Last active
April 17, 2022 15:57
-
-
Save mill1000/d143bb8dfec08f287a71c325034d1bc4 to your computer and use it in GitHub Desktop.
Scripts to generate NTP Visualizations and pruning old stats files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Generate ntpviz webpage and plots | |
Documentation=man:ntpviz(1) | |
ConditionACPower=true | |
[Service] | |
User=ntp | |
Group=ntp | |
Type=oneshot | |
ExecStart=/usr/local/bin/ntpviz --name %H -d /var/log.hdd/ntpstats/ -o /var/www/ntpviz | |
ExecStartPost=/usr/local/bin/ntpviz_prune | |
# Hardening taken from logrotate.service | |
PrivateDevices=true | |
PrivateTmp=true | |
ProtectControlGroups=true | |
ProtectKernelModules=true | |
ProtectSystem=full | |
RestrictRealtime=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Daily ntpviz generation | |
Documentation=man:ntpviz(1) | |
[Timer] | |
OnCalendar=daily | |
AccuracySec=12h | |
Persistent=true | |
[Install] | |
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
echo "Pruning old and compressed ntpstats files." | |
# Prune logs in ramdisk over a day old | |
find /var/log/ntpstats/ -type f -mtime +1 | sort | while read FILENAME | |
do | |
echo "Pruning '$FILENAME' due to age." | |
rm $FILENAME | |
done | |
# Prune logs on disk over a week old | |
find /var/log.hdd/ntpstats/ -type f -mtime +7 | sort | while read FILENAME | |
do | |
echo "Pruning '$FILENAME' due to age." | |
rm $FILENAME | |
done | |
# Prune uncompressed logs that have a compressed copy | |
find /var/log.hdd/ntpstats/ -type f -name "*.gz" | sort | while read FILENAME | |
do | |
BASE=${FILENAME%.gz} | |
if [[ -f $BASE ]]; then | |
echo "Pruning '$BASE' since '$FILENAME' exists." | |
rm $BASE | |
fi | |
done | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment