Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DB interval adjustable #172

Merged
merged 5 commits into from
Dec 13, 2017
Merged

Make DB interval adjustable #172

merged 5 commits into from
Dec 13, 2017

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Dec 12, 2017

By submitting this pull request, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your PR:

Please submit all pull requests against the development branch. Failure to do so will delay or deny your request

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?:

10


Make interval in which FTL stores queries in the long term database easily adjustable via the config file.

It defaults to 1.0 (once per minute).
It cannot be lower than 0.1 (every six seconds).
It cannot be larger than 1440.0 (once a day).

Related to pi-hole/pi-hole#1839

This template was created based on the work of udemy-dl.

…asily adjustable via the config file.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>

Conflicts:
	README.md
	config.c
@AzureMarker
Copy link
Contributor

Wouldn't writing to the database in intervals longer than a day miss some queries?

Signed-off-by: DL6ER <dl6er@dl6er.de>
config.c Outdated
// How often do we store queries in FTL's database [minutes]?
// this value can be a floating point number, e.g. "DBINTERVAL=0.5"
// defaults to: 1 (once per minute)
config.DBinterval = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should be 60 (once every 60 seconds) based on how it is used below.

Signed-off-by: DL6ER <dl6er@dl6er.de>
AzureMarker
AzureMarker previously approved these changes Dec 13, 2017
… is done (but before). This ensures that the queries will be written to the database even if the user specifies DBINTERVAL=n*60 (where n=1,2,3,...) which is a special that was not explicitly considered so far.

Signed-off-by: DL6ER <dl6er@dl6er.de>
@graysky2
Copy link

graysky2 commented Dec 13, 2017

@DL6ER - I'm thinking that you probably also want to force a write-out before /usr/bin/pihole-FTL exits?

This could be handled by the init system (systemd for example) if there is a command one can pass to pihole-FTL that causes the db to be written.

@DL6ER
Copy link
Member Author

DL6ER commented Dec 13, 2017

force a write-out when /usr/bin/pihole-FTL exits

No, I don't really want that. It is unforeseeable how long the write will take and I consider it as bad practice to react only delayed to requests to terminate. I think a sane write out interval (i.e. several times an hour) should be sufficient to achieve that everything is properly saved.

There is only one scenario where you could loose some queries and that is having a very long interval, shutting down your Pi-hole and then powering it back on at least 48 hours later. I'm not sure if that is a very likely scenario as you wouldn't have DNS functionality in your network as long as Pi-hole is shut down.

@graysky2
Copy link

@DL6ER - Sounds good, just wanted to check.

@DL6ER DL6ER merged commit 8ab56e5 into development Dec 13, 2017
@DL6ER DL6ER deleted the new/DBinterval branch December 13, 2017 21:06
@graysky2
Copy link

@DL6ER - The Arch package for pi-hole-ftl has this PR#172 and PR#167 applied to the standard v2.12. I have /etc/pihole/pihole-FTL.conf setup to sync every 121 minutes, but I haven't seen a sync occur (4 hours of uptime).

Local time is 5:25 PM:

% ls -lrt /etc/pihole
...
-rw-r--r-- 1 pihole pihole  147456 Dec 13 12:30 pihole-FTL.db
% cat /etc/pihole/pihole-FTL.conf 
SOCKET_LISTENING=localonly
TIMEFRAME=rolling24h
QUERY_DISPLAY=yes
AAAA_QUERY_ANALYSIS=yes
MAXDBDAYS=365
RESOLVE_IPV6=no
RESOLVE_IPV4=yes
DBINTERVAL=121.0
DBFILE=/etc/pihole/pihole-FTL.db

@DL6ER
Copy link
Member Author

DL6ER commented Dec 13, 2017

Strange... I will set the timer to 121.0 for me as well and report tomorrow what happened over night.

edit: So far, so good:

[2017-12-13 23:30:00.570]    DBINTERVAL: saving to DB file every 7260 seconds

@graysky2
Copy link

graysky2 commented Dec 13, 2017

I got the same...

% grep -i dbint /run/log/pihole-ftl/pihole-FTL.log 
[2017-12-13 13:26:21.132]    DBINTERVAL: saving to DB file every 7260 seconds

Yet still no writes (local time is 18:49)...

% stat /etc/pihole/pihole-FTL.db 
  File: /etc/pihole/pihole-FTL.db
  Size: 147456    	Blocks: 288        IO Block: 4096   regular file
Device: 30h/48d	Inode: 260690      Links: 1
Access: (0644/-rw-r--r--)  Uid: (  996/  pihole)   Gid: (  996/  pihole)
Access: 2017-12-13 14:49:00.053508686 -0500
Modify: 2017-12-13 12:30:00.196199782 -0500
Change: 2017-12-13 13:26:21.298180015 -0500
 Birth: -

@DL6ER
Copy link
Member Author

DL6ER commented Dec 14, 2017

@graysky2 It seems to work fine for me, writes are done every 02:01 (HH:MM):

[2017-12-14 00:51:00.185] Notice: Queries stored in DB: 826
[2017-12-14 00:51:00.186] Notice: Database size is 138.87 MB, deleted 0 rows
[...]
[2017-12-14 02:52:00.192] Notice: Queries stored in DB: 382
[2017-12-14 02:52:00.194] Notice: Database size is 138.90 MB, deleted 0 rows
[...]
[2017-12-14 04:53:00.184] Notice: Queries stored in DB: 412
[2017-12-14 04:53:00.185] Notice: Database size is 138.92 MB, deleted 0 rows
[...]
[2017-12-14 06:54:00.143] Notice: Queries stored in DB: 391
[2017-12-14 06:54:00.145] Notice: Database size is 138.95 MB, deleted 0 rows

and

$ stat /etc/pihole/pihole-FTL.db 
  File: ‘/etc/pihole/pihole-FTL.db’
  Size: 138950656       Blocks: 271400     IO Block: 4096   regular file
Device: b302h/45826d    Inode: 149592      Links: 1
Access: (0644/-rw-r--r--)  Uid: (  999/  pihole)   Gid: (  996/  pihole)
Access: 2017-08-02 17:20:12.882001730 +0200
Modify: 2017-12-14 06:54:00.115726043 +0100
Change: 2017-12-14 06:54:00.115726043 +0100
 Birth: -

@graysky2
Copy link

graysky2 commented Dec 14, 2017 via email

@DL6ER
Copy link
Member Author

DL6ER commented Dec 14, 2017

It continued as expected for me so far (08:55, 10:56, 12:57, 14:58).

I'm on the branch of this PR. I quickly reviewed what that means:

v2.12 + #166 + #168 + #171 + all comits in this PR

However, nothing outside of this PR should be changing anything here. How about other values? I think you said already that 60 is working, how about 61?

@graysky2
Copy link

Very odd... a value of 2 works just fine. I am testing 61 now and will report back.

@graysky2
Copy link

graysky2 commented Dec 14, 2017

Nope... a value of 61 has failed to write.

% grep -i dbint /etc/pihole/pihole-FTL.conf       
DBINTERVAL=61

% grep -i dbint /run/log/pihole-ftl/pihole-FTL.log
[2017-12-14 14:51:19.538]    DBINTERVAL: saving to DB file every 3660 seconds

Local time is 16:55:

% stat /etc/pihole/pihole-FTL.db
  File: /etc/pihole/pihole-FTL.db
  Size: 208896    	Blocks: 408        IO Block: 4096   regular file
Device: 30h/48d	Inode: 260690      Links: 1
Access: (0644/-rw-r--r--)  Uid: (  996/  pihole)   Gid: (  996/  pihole)
Access: 2017-12-14 14:51:19.558958997 -0500
Modify: 2017-12-14 14:50:00.107371181 -0500
Change: 2017-12-14 14:50:00.107371181 -0500
 Birth: -

@DL6ER
Copy link
Member Author

DL6ER commented Dec 14, 2017

@graysky2 I'm confused. Are you sure that your Arch version hast the whole PR merged into it? Including 5951e5b ?

@graysky2
Copy link

@graysky2
Copy link

graysky2 commented Dec 14, 2017

The X and checkmarks in the git log are confusing to me...
...So our package should include 2.12 + which commits?

https://github.com/pi-hole/FTL/compare/95bdd62777347f2117070ce8060b2ca1cc3072c0...8ab56e58f29fc3e5263ab51b80534154832ffbd6.patch

???

@AzureMarker
Copy link
Contributor

Are you trying to make the current branch a package? Why do you need to distinguish between commits?

@graysky2
Copy link

graysky2 commented Dec 15, 2017

@Mcat12 - No, the intent is to incorporate the adjustable db into 2.12. The patch I referenced above is working with a DBINTERVAL=121.0 by the way.

@DL6ER
Copy link
Member Author

DL6ER commented Dec 15, 2017

Okay, so there is no issue with this PR or our code base but only in the way you applied which modifications to the last tagged release. Good to know, thanks for doing extensive testing BTW.

@graysky2
Copy link

@DL6ER - You're welcome and thank you for the quick implementation of this request. Is the patch I referenced above the correct set of commits to apply to 2.12 for the Arch package?

@DL6ER
Copy link
Member Author

DL6ER commented Dec 16, 2017

@graysky2

Is the patch I referenced above the correct set of commits to apply to 2.12 for the Arch package?

Not sure what/which link you are referring to... If you are asking what the diff is that leads to this branch, then it is https://github.com/pi-hole/FTL/compare/master...5951e5b.diff
However, if it is working now for you, then I'd assume you already have all required commits added to your build system. We targeted the next release rather sooner than later (ideally before Christmas), so all changes will become live pretty soon.

@graysky2
Copy link

Thanks again. Will wait for 2.12.1 or whatever you bump to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants