mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
pping: Add systemd unit files for running pping
Add some example files for setting up ePPing with systemd. The setup creates "log" files in /var/log/pping and rotates them every minute (appending a date at the time of rotation). Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
41
pping/scripts/rotate-pping-output.sh
Executable file
41
pping/scripts/rotate-pping-output.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
MAX_WAIT_ITER=10
|
||||
pping_path=${1:-"/var/log/pping/pping.out.json"}
|
||||
|
||||
pping_folder=$(dirname "$pping_path")
|
||||
pping_file=$(basename "$pping_path")
|
||||
|
||||
if [[ ! -f "$pping_path" ]]; then
|
||||
# Nothing to rotate
|
||||
exit 0
|
||||
fi
|
||||
|
||||
dailyfolder="$pping_folder/$(date -Idate)"
|
||||
if ! mkdir -p "$dailyfolder"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
newplace="$dailyfolder/$pping_file.$(date -Iseconds)"
|
||||
if ! mv "$pping_path" "$newplace"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Tell ePPing to reopen file
|
||||
if systemctl is-active --quiet pping.service; then
|
||||
systemctl reload pping.service
|
||||
fi
|
||||
|
||||
if [[ -f "$newplace" ]]; then
|
||||
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
|
||||
if fuser -s "$newplace"; then
|
||||
sleep 1
|
||||
else
|
||||
gzip "$newplace"
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Timed out waiting for $newplace to become unused, unable to compress it" 1>&2
|
||||
exit 1
|
32
pping/systemd-files/pping.service
Normal file
32
pping/systemd-files/pping.service
Normal file
@ -0,0 +1,32 @@
|
||||
[Unit]
|
||||
Description=ePPing - Passive monitoring of network RTTs
|
||||
After=network.service
|
||||
Wants=rotate-pping.timer
|
||||
|
||||
# Uncomment below if running with LibreQoS
|
||||
# After=lqosd.service
|
||||
|
||||
[Service]
|
||||
# Ensure folder for saving output to exists
|
||||
ExecStartPre=/usr/bin/mkdir -p /var/log/pping
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
# On systemctl reload, send a SIGHUP to ePPing which causes it to reopen its output file
|
||||
ExecReload=kill -HUP $MAINPID
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=60
|
||||
|
||||
# Set to whatever maximum memory footprint you can tolerate
|
||||
# Note, hard-kills the ePPing process without allowing it to clean up. Consider
|
||||
# running /scripts/cleanup-tc-progs after.
|
||||
MemoryMax=4G
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
|
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 (pping.service)
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/pping.out.json
|
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 periodically
|
||||
PartOf=pping.service
|
||||
|
||||
[Timer]
|
||||
Unit=rotate-pping.service
|
||||
|
||||
# Rotate ePPing output every X seconds
|
||||
OnActiveSec=60
|
||||
OnUnitActiveSec=60
|
||||
AccuracySec=1us
|
Reference in New Issue
Block a user