mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
pping: Change single pping-service into generic template
Replace the systemd unit files that needed to be modified for a specific interface with template files. The template files allows one to instansiate a service for any interface (by running systemctl start pping@<interface>.service), and multiple interfaces can be monitored at once. Each instance maintains a separtate "log" of data at /sys/var/log/pping/<interface>/pping.<interface>.json which is rotated one per minute (see the rotate-pping@.timer file) and placed in daily subfolders. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
MAX_WAIT_ITER=10
|
MAX_WAIT_ITER=10
|
||||||
pping_path=${1:-"/var/log/pping/pping.out.json"}
|
pping_path=${1:-"/var/log/pping/pping.out.json"}
|
||||||
|
instance=$2 # pping service instance to reload
|
||||||
|
|
||||||
pping_folder=$(dirname "$pping_path")
|
pping_folder=$(dirname "$pping_path")
|
||||||
pping_file=$(basename "$pping_path")
|
pping_file=$(basename "$pping_path")
|
||||||
@@ -21,11 +22,12 @@ if ! mv "$pping_path" "$newplace"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Tell ePPing to reopen file
|
|
||||||
if systemctl is-active --quiet pping.service; then
|
if [[ -n "$instance" ]] && systemctl is-active --quiet "pping@$instance.service"; then
|
||||||
systemctl reload pping.service
|
systemctl reload "pping@$instance.service"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Compress the old file (once ePPing has stopped writing to it)
|
||||||
if [[ -f "$newplace" ]]; then
|
if [[ -f "$newplace" ]]; then
|
||||||
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
|
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
|
||||||
if fuser -s "$newplace"; then
|
if fuser -s "$newplace"; then
|
||||||
|
@@ -1,32 +1,31 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=ePPing - Passive monitoring of network RTTs
|
Description=ePPing - Passive monitoring of network RTTs on %i
|
||||||
After=network.service
|
After=network.service
|
||||||
Wants=rotate-pping.timer
|
Wants=rotate-pping@%i.timer
|
||||||
|
|
||||||
# Uncomment below if running with LibreQoS
|
# Uncomment below if running with LibreQoS
|
||||||
# After=lqosd.service
|
# After=lqosd.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
# Ensure folder for saving output to exists
|
# Ensure folder for saving output to exists
|
||||||
ExecStartPre=/usr/bin/mkdir -p /var/log/pping
|
ExecStartPre=/usr/bin/mkdir -p /var/log/pping/%i
|
||||||
|
|
||||||
# Rotate any old output first to ensure ePPing can start writing to its intended file
|
# Rotate any old output first to ensure ePPing can start writing to its intended file
|
||||||
ExecStartPre=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/pping.out.json
|
ExecStartPre=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/%i/pping.%i.json
|
||||||
|
|
||||||
WorkingDirectory=/opt/bpf-examples/pping
|
WorkingDirectory=/opt/bpf-examples/pping
|
||||||
ExecStart=/opt/bpf-examples/pping/pping -i <interface> -l -r 10 -a 10 -F json -w /var/log/pping/pping.out.json
|
ExecStart=/opt/bpf-examples/pping/pping -i %i -l -r 10 -a 10 -F json -w /var/log/pping/%i/pping.%i.json
|
||||||
|
|
||||||
# On systemctl reload, send a SIGHUP to ePPing which causes it to reopen its output file
|
# On systemctl reload, send a SIGHUP to ePPing which causes it to reopen its output file
|
||||||
ExecReload=kill -HUP $MAINPID
|
ExecReload=kill -HUP $MAINPID
|
||||||
|
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=60
|
RestartSec=60
|
||||||
|
|
||||||
# Set to whatever maximum memory footprint you can tolerate
|
# Set to whatever maximum memory footprint you can tolerate
|
||||||
# Note, hard-kills the ePPing process without allowing it to clean up. Consider
|
# Note, hard-kills the ePPing process without allowing it to clean up. Consider
|
||||||
# running /scripts/cleanup-tc-progs after.
|
# running /scripts/cleanup-tc-progs after.
|
||||||
MemoryMax=4G
|
MemoryMax=4G
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|
@@ -1,6 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Rotates the output file from ePPing (pping.service)
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/pping.out.json
|
|
@@ -1,11 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Rotate ePPing output periodically
|
|
||||||
PartOf=pping.service
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
Unit=rotate-pping.service
|
|
||||||
|
|
||||||
# Rotate ePPing output every X seconds
|
|
||||||
OnActiveSec=60
|
|
||||||
OnUnitActiveSec=60
|
|
||||||
AccuracySec=1us
|
|
6
pping/systemd-files/rotate-pping@.service
Normal file
6
pping/systemd-files/rotate-pping@.service
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Rotates the output file from ePPing on %i (pping@%i.service)
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/%i/pping.%i.json %i
|
11
pping/systemd-files/rotate-pping@.timer
Normal file
11
pping/systemd-files/rotate-pping@.timer
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Rotate ePPing output for %i periodically
|
||||||
|
PartOf=pping@%i.service
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
Unit=rotate-pping@%i.service
|
||||||
|
|
||||||
|
# Rotate ePPing output every X seconds
|
||||||
|
OnActiveSec=60
|
||||||
|
OnUnitActiveSec=60
|
||||||
|
AccuracySec=1us
|
Reference in New Issue
Block a user