Skip to content

Commit f423e39

Browse files
committed
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>
1 parent c6751ef commit f423e39

File tree

6 files changed

+53
-52
lines changed

6 files changed

+53
-52
lines changed

pping/scripts/rotate-pping-output.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
MAX_WAIT_ITER=10
44
pping_path=${1:-"/var/log/pping/pping.out.json"}
5+
instance=$2 # pping service instance to reload
56

67
pping_folder=$(dirname "$pping_path")
78
pping_file=$(basename "$pping_path")
@@ -21,11 +22,12 @@ if ! mv "$pping_path" "$newplace"; then
2122
exit 1
2223
fi
2324

24-
# Tell ePPing to reopen file
25-
if systemctl is-active --quiet pping.service; then
26-
systemctl reload pping.service
25+
26+
if [[ -n "$instance" ]] && systemctl is-active --quiet "pping@$instance.service"; then
27+
systemctl reload "pping@$instance.service"
2728
fi
2829

30+
# Compress the old file (once ePPing has stopped writing to it)
2931
if [[ -f "$newplace" ]]; then
3032
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
3133
if fuser -s "$newplace"; then
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
[Unit]
2-
Description=ePPing - Passive monitoring of network RTTs
3-
After=network.service
4-
Wants=rotate-pping.timer
5-
6-
# Uncomment below if running with LibreQoS
7-
# After=lqosd.service
8-
9-
[Service]
10-
# Ensure folder for saving output to exists
11-
ExecStartPre=/usr/bin/mkdir -p /var/log/pping
12-
13-
# Rotate any old output first to ensure ePPing can start writing to its intended file
14-
ExecStartPre=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/pping.out.json
15-
16-
WorkingDirectory=/opt/bpf-examples/pping
17-
ExecStart=/opt/bpf-examples/pping/pping -i <interface> -l -r 10 -a 10 -F json -w /var/log/pping/pping.out.json
18-
19-
# On systemctl reload, send a SIGHUP to ePPing which causes it to reopen its output file
20-
ExecReload=kill -HUP $MAINPID
21-
22-
Restart=on-failure
23-
RestartSec=60
24-
25-
# Set to whatever maximum memory footprint you can tolerate
26-
# Note, hard-kills the ePPing process without allowing it to clean up. Consider
27-
# running /scripts/cleanup-tc-progs after.
28-
MemoryMax=4G
29-
30-
[Install]
31-
WantedBy=default.target
32-
1+
[Unit]
2+
Description=ePPing - Passive monitoring of network RTTs on %i
3+
After=network.service
4+
Wants=rotate-pping@%i.timer
5+
6+
# Uncomment below if running with LibreQoS
7+
# After=lqosd.service
8+
9+
[Service]
10+
# Ensure folder for saving output to exists
11+
ExecStartPre=/usr/bin/mkdir -p /var/log/pping/%i
12+
13+
# Rotate any old output first to ensure ePPing can start writing to its intended file
14+
ExecStartPre=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/%i/pping.%i.json
15+
16+
WorkingDirectory=/opt/bpf-examples/pping
17+
ExecStart=/opt/bpf-examples/pping/pping -i %i -l -r 10 -a 10 -F json -w /var/log/pping/%i/pping.%i.json
18+
19+
# On systemctl reload, send a SIGHUP to ePPing which causes it to reopen its output file
20+
ExecReload=kill -HUP $MAINPID
21+
22+
Restart=on-failure
23+
RestartSec=60
24+
25+
# Set to whatever maximum memory footprint you can tolerate
26+
# Note, hard-kills the ePPing process without allowing it to clean up. Consider
27+
# running /scripts/cleanup-tc-progs after.
28+
MemoryMax=4G
29+
30+
[Install]
31+
WantedBy=default.target

pping/systemd-files/rotate-pping.service

Lines changed: 0 additions & 6 deletions
This file was deleted.

pping/systemd-files/rotate-pping.timer

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[Unit]
2+
Description=Rotates the output file from ePPing on %i (pping@%i.service)
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStart=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/%i/pping.%i.json %i
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Rotate ePPing output for %i periodically
3+
PartOf=pping@%i.service
4+
5+
[Timer]
6+
Unit=rotate-pping@%i.service
7+
8+
# Rotate ePPing output every X seconds
9+
OnActiveSec=60
10+
OnUnitActiveSec=60
11+
AccuracySec=1us

0 commit comments

Comments
 (0)