Merge pull request #36 from FreeWillyB/gateway_status

There's absolutely potential to include way too much data in the database.  If I had the time, I would look into retention policies and data rollup, but I do this for fun and don't have the time to spare to read up on influx.   I'll add the defaultgw and gwdesc back in when I get the time since it's specific to the gateway.   The ifdesc belongs on the main interface table and would be redundant here.  Sometimes I get too caught up in what I can collect and monitor.

Thanks
This commit is contained in:
VictorRobellini 2021-04-26 20:58:51 -04:00 committed by GitHub
commit 0ffb2e1148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21018 additions and 117 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -54,6 +54,8 @@ from_beginning = true
I'm sure you can even rename the measurements, columns and update the tags, but that's beyond my influx capabilities.
### Templates of what I currently run in my Kubernetes homelab
Kubernetes deployed locally with [these instructions](https://www.reddit.com/r/homelab/comments/ipsc4r/howto_k8s_metallb_and_external_dns_access_for/)
@ -229,6 +231,7 @@ What I updated:
- Created dashboard wide variables to make the dashboard more portable and easily configurable. You shouldn't need to update any of the queries.
- Took some inspiration and panels [from this dashboard](https://grafana.com/grafana/dashboards/9806 "from this dashboard")
- Included gateway RTT from dpinger thanks to [this integration](https://forum.netgate.com/topic/142093/can-telegraf-package-gather-latency-packet-loss-information/3 "this integration")
- Pulled information from the "return_gateways_status_text" function in "/etc/inc/gwlb.inc" to return the actual status of the gateway, as well as the current loss/rtt and IP values.
- Used[ telegraf configs](https://www.reddit.com/r/pfBlockerNG/comments/bu0ms0/pfblockerngtelegrafinfluxdb_ip_block_list/ " telegraf configs") from this post by [/u/PeskyWarrior](https://www.reddit.com/u/PeskyWarrior "/u/PeskyWarrior")
- Tag, templating - No need to specify all cpus or interfaces in the graph queries. These values are pulled in with queries.
- Added chart to show all adapters, IP, MAC and Status[ from here](https://github.com/influxdata/telegraf/issues/3756#issuecomment-485606025 " from here")

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,12 @@
# Installing the Plugins
Perhaps the easiest method of installing these plugins is by utlizing the "Filer" plugin in pfSense. Simply type the entire file name (i.e. "/usr/local/bin/plugin_name") and paste the code into the window. Make sure to set the permissions to be "0755", as they default to "0644" which is NOT executable!
# telegraf_pfinterface.php
IP Address and subnet for IPv4 and IPv6 are collected. I don't have an ipv6 on the dashbaord because I don't use it.
# telegraf_gateways
Depending on how recent your pfSense install is, you may need to use the python 3.7 version of the plugin. If you are running 2.4.5, you probably want telegraf_gateways-3.7.py. They both output he same data in the same format.
# telegraf_gateways.php
This has been modified from the original python version to a native PHP script. The new script calls the builtin "return_gateways_status_text" function from "/etc/inc/gwlb.inc". In addition to the loss, rtt, and rttsd included in the original plugin, the new version will also return the gateway IP, monitored IP, status, and substatus of the gateway. This eliminates the guess work of whether or not pfSense has marked this gateway as down.
All I did was copy telegraf_gateways-3.7.py to /usr/local/bin and rename it to telegraf_gateways.py
## Python 2.7
Does /usr/local/bin/python2.7 exist on your pfSense system? If so, use this telegraf_gateways-2.7.py

View File

@ -0,0 +1,30 @@
#!/usr/local/bin/php-cgi -f
<?php
require_once("gwlb.inc");
$source = "pfconfig";
$gwstat = return_gateways_status($true);
foreach ($gwstat as $gw_ip => $gwaddress) {
$gateway = $gw_ip;
$monitor = $gwstat[$gw_ip]["monitorip"];
$source = $gwstat[$gw_ip]["srcip"];
$delay = $gwstat[$gw_ip]["delay"];
$stddev = $gwstat[$gw_ip]["stddev"];
$loss = $gwstat[$gw_ip]["loss"];
$status = $gwstat[$gw_ip]["status"];
$substatus = $gwstat[$gw_ip]["substatus"];
printf("gateways,gateway_name=%s monitor_ip=\"%s\",gateway_ip=\"%s\",rtt=%s,rttsd=%s,loss=%si,status=\"%s\",substatus=\"%s\"\n",
$gateway,
$monitor,
$source,
floatval($delay),
floatval($stddev),
floatval($loss),
$status,
$substatus
);
}
?>

View File

@ -0,0 +1,45 @@
#!/usr/local/bin/python3.7
import subprocess
import sys
php_str = """php -r "require_once('/etc/inc/gwlb.inc'); print(return_gateways_status_text());" """
try:
proc = subprocess.Popen(php_str, shell=True, stdout=subprocess.PIPE)
output = proc.stdout.read().decode('utf-8')
fields_output, gw_output = output.split("\n",1)
gateways_text = gw_output.split("\n")
fields = fields_output.split()
for gw in gateways_text:
if len(gw) > 0:
gw_str="gateways,gateway_name="
values = gw.split()
for i,val in enumerate(values):
field = fields[i].lower()
if field in ['monitor','source','status','substatus']:
if field == 'monitor':
field = 'monitor_ip'
elif field == 'source':
field = 'gateway_ip'
val = f'"{val}"'
elif field == 'delay':
field = 'rtt'
val = val.replace('ms','')
elif field == 'stddev':
field = 'rttsd'
val = val.replace('ms','')
elif field == 'loss':
val = str(int(float(val.replace('%','')))) + "i"
if i == 0:
gw_str+=str(val) + " "
else:
gw_str+=str(field)+"="+str(val)+","
gw_str=gw_str[:-1]
print(gw_str)
except Exception as e:
print(e, file=sys.stderr)