vmstan / gravity-sync

💫 The easy way to synchronize the DNS configuration of two Pi-hole 5.x instances.
https://vmstan.com/gravity-sync/
GNU General Public License v3.0
2.29k stars 129 forks source link

Logging Level option #319

Closed greggitter closed 2 years ago

greggitter commented 2 years ago

This might be more of a question than an enhancement request as there may be a way to achieve these already. My piholes are mostly static and rarely ever change. I noticed in /var/log/syslog there is quite a bit of writing indicating updates are occurring in 4.0.0 per your note, at an interval of < 5 minutes. In my situation this is overkill, even for when I make a change, I can for the most part make a white list change in two places if it's critical or run a manual sync. So I guess there are two questions, 1) can a logging level be set or can a separate log file be used for gravity-sync to minimize overloading the syslog? And 2) is there a way to reduce the frequency of updates to say once every x number of minutes rather than the default.

Thanks for providing a great product, really nice to have! :)

vmstan commented 2 years ago

I don't have a log level option, but you can manually decrease the frequency of replication by modifying the gravity-sync.timer file in /etc/systemd/ and reloading the systemd daemon. There should be randomly generated values for the timer and the offset in there now.

My environment is probably equally as static. I thought about including an option to be less aggressive in the timers and may still do it in the future. It seemed like everyone was always wanting replication to go faster with the old system so that's what I did.

One of the things I was attempting with the rewrite was eliminating as many options as I could get away with, and then only putting back what was needed. 😊

greggitter commented 2 years ago

Thanks for the very quick reply, got it tested and timer mod is working (changed to one hour). I also made a change to the service file to drop the log data into its own file which for me is better as I tend to scan syslog periodically looking for anomalies. To do this, in the service section I added two lines to route the output as such, but noticed the time stamp is omitted at the beginning of each line....that might be a feature of syslog.

[Service] Type=simple User=pi StandardOutput=file:/var/log/gravity-sync.log StandardError=file:/var/log/gravity-sync.log ExecStart=/usr/local/bin/gravity-sync

Also, I did notice some odd escape characters showing in my log output as such prior to making changes:

Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;95m∞#033[0m #033[1mInitializing Gravity Sync (4.0.0)#033[0m Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Loading gravity-sync.conf#015#033[0;92m✓#033[0m Loading gravity-sync.conf Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Detecting local Pi-hole installation#015#033[0;92m✓#033[0m Detecting local Pi-hole installation Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Detecting remote Pi-hole installation#015#033[0;92m✓#033[0m Detecting remote Pi-hole installation Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Checking on peer#015#033[0;92m✓#033[0m Gravity Sync remote peer is configured Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Evaluating arguments#015#033[0;92m✓#033[0m Evaluating arguments: SMART Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;93m»#033[0m #033[0;93mRemote Pi-hole: pi@192.168.1.214#033[0m Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Validating pathways to Pi-hole#015#033[0;92m✓#033[0m Validating pathways to Pi-hole Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Validating pathways to DNSMASQ#015#033[0;92m✓#033[0m Validating pathways to DNSMASQ Apr 12 10:10:57 Rpi-1 gravity-sync[861824]: #033[0;93m»#033[0m #033[0;93mStarting SMART Analysis#033[0m Apr 12 10:10:58 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Hashing the remote Gravity Database#015#033[0;92m✓#033[0m Hashing the remote Gravity Database Apr 12 10:10:58 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Comparing to the local Gravity Database#015#033[0;92m✓#033[0m Comparing to the local Gravity Database Apr 12 10:10:58 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Hashing the remote DNS Records#015#033[0;92m✓#033[0m Hashing the remote DNS Records Apr 12 10:10:58 Rpi-1 gravity-sync[861824]: #033[0;96m∞#033[0m Comparing to the local DNS Records#015#033[0;92m✓#033[0m Comparing to the local DNS Records Apr 12 10:10:59 Rpi-1 gravity-sync[861824]: #033[0;95m!#033[0m #033[0;95mDNS CNAMEs not detected on the local Pi-hole#033[0m Apr 12 10:10:59 Rpi-1 gravity-sync[861824]: #033[0;95m!#033[0m #033[0;95mNo replication is required at this time#033[0m Apr 12 10:10:59 Rpi-1 gravity-sync[861824]: #033[0;95m∞#033[0m #033[1mGravity Sync SMART exited after 2 seconds#033[0m

Again, thanks for all your time spent on cool utility.

vmstan commented 2 years ago

I have baked this into 4.0.2 which you can try as a beta.

Update your existing install. gravity-sync update Then run gravity-sync beta and type origin/4.0.2 into the prompt, from the list of options.

This should get you the beta for 4.0.2 that is running on a different branch right now.

In this version you can do gravity-sync auto slow which will set the replication timers to roughly an hour, give or take. You can also try gravity-sync auto half which will do a half an hour, give or take.

Also, you can add GS_SYSLOG_REDIRECT=/full/path/to/file.log to your gravity-sync.conf file before you run the auto command, and it will add that redirect option into your service file.

greggitter commented 2 years ago

That looks pretty good for sure. I'll test this more tomorrow...any ideas on where the escape characters are coming from. I don't see these anywhere else in syslog. Tested with two ssh clients, windows terminal and mobaXterm...same results I pasted above. Thanks!

EDIT: The escape codes are from the "Script Colors" and "Message Codes" appended to the start of each message; these are not working on my side.