Skip to content

Commit bc9df64

Browse files
authored
Merge pull request #91 from simosund/pping-systemd
Add systemd unit files for ePPing setup
2 parents 4b677fd + f423e39 commit bc9df64

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

pping/scripts/cleanup-tc-progs.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
interface=$1
4+
5+
if [[ -z "$interface" ]]; then
6+
echo "Usage: $0 <interface>"
7+
exit 0
8+
fi
9+
10+
if [[ ! -e "/sys/class/net/$interface" ]]; then
11+
echo "$interface is not a valid interface" 1>&2
12+
exit 1
13+
fi
14+
15+
for trafdir in "ingress" "egress"; do
16+
prios=$(tc filter show dev "$interface" "$trafdir" | grep pping_tc | cut -f 5 -d ' ')
17+
18+
while IFS= read -r p || [[ -n "$p" ]]; do
19+
if [[ "$p" =~ ^[0-9]+ ]]; then
20+
tc filter del dev "$interface" "$trafdir" prio "$p"
21+
fi
22+
done <<< "$prios"
23+
24+
done
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
MAX_WAIT_ITER=10
4+
pping_path=${1:-"/var/log/pping/pping.out.json"}
5+
instance=$2 # pping service instance to reload
6+
7+
pping_folder=$(dirname "$pping_path")
8+
pping_file=$(basename "$pping_path")
9+
10+
if [[ ! -f "$pping_path" ]]; then
11+
# Nothing to rotate
12+
exit 0
13+
fi
14+
15+
dailyfolder="$pping_folder/$(date -Idate)"
16+
if ! mkdir -p "$dailyfolder"; then
17+
exit 1
18+
fi
19+
20+
newplace="$dailyfolder/$pping_file.$(date -Iseconds)"
21+
if ! mv "$pping_path" "$newplace"; then
22+
exit 1
23+
fi
24+
25+
26+
if [[ -n "$instance" ]] && systemctl is-active --quiet "pping@$instance.service"; then
27+
systemctl reload "pping@$instance.service"
28+
fi
29+
30+
# Compress the old file (once ePPing has stopped writing to it)
31+
if [[ -f "$newplace" ]]; then
32+
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
33+
if fuser -s "$newplace"; then
34+
sleep 1
35+
else
36+
gzip "$newplace"
37+
exit $?
38+
fi
39+
done
40+
fi
41+
42+
echo "Timed out waiting for $newplace to become unused, unable to compress it" 1>&2
43+
exit 1

pping/systemd-files/pping@.service

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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
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)