Last active
December 4, 2022 13:14
-
-
Save fastjack/a0feb792a9655da7aa3e2a7a1d9f812f to your computer and use it in GitHub Desktop.
Quick and dirty gateway metrics for telegraf on pfSense
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
[[inputs.exec]] | |
commands = ["/usr/local/libexec/telegraf/gateways.py"] | |
timeout = "5s" | |
data_format = "influx" |
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
#!/usr/local/bin/python2.7 | |
import glob, os, socket | |
DPINGER_SOCK_PATH = "/var/run/" | |
os.chdir(DPINGER_SOCK_PATH) | |
for sock_name in glob.glob("dpinger*.sock"): | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
sock_path = DPINGER_SOCK_PATH+sock_name | |
s = sock.connect(sock_path) | |
line = sock.recv(1024).split('\n', 1)[0] | |
values = line.split() | |
print "gateways,gateway_name=" + values[0] + " rtt=" + str(int(values[1])/100.0) + \ | |
",rttsd=" + str(int(values[2])/100.0) + ",loss=" + str(int(values[3])) + "i" | |
sock.close() |
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
#!/usr/local/bin/python3.7 | |
import glob, os, socket | |
DPINGER_SOCK_PATH = "/var/run/" | |
os.chdir(DPINGER_SOCK_PATH) | |
for sock_name in glob.glob("dpinger*.sock"): | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
sock_path = DPINGER_SOCK_PATH+sock_name | |
s = sock.connect(sock_path) | |
line = sock.recv(1024).decode().split('\n', 1)[0] | |
values = line.split() | |
print("gateways,gateway_name="+values[0]+" rtt="+str(int(values[1])/100.0)+ \ | |
",rttsd="+str(int(values[2])/100.0)+",loss="+str(int(values[3]))+"i") | |
sock.close() |
Why the /100
- the default output is microseconds and that seems fine?
I believe I had my Grafana already set up for seconds instead of microseconds so I added it here.
Ah okay, that would be /1000
but either way thanks for saving me some time with this. Works well on opnsense too
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@corgan2222 You probably could cobble together something with ping. I used dpinger because it already comes configured through pfSense's admin interface.
But if you're having problems pinging your already configured gateway you can choose a custom ping target (the user interfaces calls it a "Monitor IP"). Just go to System -> Routing -> Gateways and then edit your gateway from there.