-
-
Save ackstorm23/b44f6ec44197df5d4c6dbb3de4062dca to your computer and use it in GitHub Desktop.
Scrape pf QOS metrics for forwarding to InfluxDB
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
#!/bin/sh | |
# | |
# Shell script: get_pfqueue_data.sh | |
# Date: 21-Dec-2016 | |
# | |
# Script to scrape queue metrics from pfctl | |
# and output in influxdb line protocol with interface name & | |
# q name as tags and q bytes & q drops as data. | |
# | |
# Copy this script to a directory on your pfsense machine and ensure | |
# it is executable. It requires the privileges of a user with permission | |
# to read /dev/pf. | |
# | |
# This script should be invoked with the target influxdb measurement name | |
# as the single argument (e.g. 'get_pfqueue_data.sh pf_metrics' where | |
# pf_metrics is the measurement name)and is meant to be used in | |
# combination with telegraf inputs.exec plugin to forward stats to | |
# the influx server. The influxdb database name and retention policy | |
# are configured within telegraf. | |
# | |
# Suggest using telegraf output filtering to only forward data for queues | |
# for which metrics are wanted. | |
if test X"$1" = 'X' | |
then | |
echo "Error! No measurement name provided" | |
exit | |
fi | |
pfctl_output=$(pfctl -s queue -v) | |
dt=$(date +%s) | |
dt=$(($dt*1000000000)) | |
qdrops() { | |
drops=$(echo $pfctl_output | grep -o -E 'dropped pkts: *[0-9]*' | sed -n -e 's/^.*pkts:[ \t]* //p' | sed -n "$4"p) | |
bytes=$(echo $pfctl_output | grep -o -E '\[ pkts: *[0-9]* *bytes: *[0-9]*' | sed -n -e 's/^.*bytes:[ \t]* //p' | sed -n "$4"p) | |
qdepth=$(echo $pfctl_output | grep -o -E '\[ qlength: *[0-9]*' | sed -n -e 's/^.*qlength:[ \t]* //p' | sed -n "$4"p) | |
echo $1',interface='$2',queue='$3' drops='$drops'i,bytes='$bytes'i,qdepth='$qdepth'i '$dt | |
} | |
index=1 | |
for q in $(echo $pfctl_output | grep -o -E '[A-Za-z0-9_]* on' | cut -d ' ' -f1) | |
do | |
r=$(echo $q | grep -o -E 'root') | |
if test X"$r" = 'Xroot' | |
then | |
iface=$(echo $q | cut -d"_" -f2) | |
index=$(($index+1)) | |
else | |
qdrops $1 $iface $q $index | |
index=$(($index+1)) | |
fi | |
done | |
Grafana Dashboard .json
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 5,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "influxdb",
"decimals": 0,
"fill": 3,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 0
},
"id": 5,
"legend": {
"alignAsTable": true,
"avg": false,
"current": true,
"hideZero": true,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"sort": "current",
"sortDesc": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 0,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"$$hashKey": "object:2797",
"alias": "[[tag_queue]]",
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"queue"
],
"type": "tag"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "pfsense",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"bytes"
],
"type": "field"
},
{
"params": [],
"type": "mean"
},
{
"params": [
"10s"
],
"type": "derivative"
}
]
],
"tags": [],
"target": ""
}
],
"thresholds": [
{
"colorMode": "warning",
"fill": true,
"line": true,
"op": "gt",
"value": 5242880
}
],
"timeFrom": null,
"timeShift": null,
"title": "Queue Traffic",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"transparent": true,
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "Bps",
"label": "bytes/s",
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": "Drops/s",
"logBase": 1,
"max": "500",
"min": "0",
"show": false
}
]
},
{
"aliasColors": {},
"bars": true,
"dashLength": 10,
"dashes": false,
"datasource": "influxdb",
"decimals": 0,
"fill": 1,
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 7
},
"id": 6,
"legend": {
"alignAsTable": true,
"avg": false,
"current": true,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"sideWidth": null,
"sort": "current",
"sortDesc": true,
"total": false,
"values": true
},
"lines": false,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 1,
"points": false,
"renderer": "flot",
"seriesOverrides": [
{
"$$hashKey": "object:3509",
"alias": "/.*/",
"transform": "negative-Y"
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"$$hashKey": "object:3245",
"alias": "[[tag_queue]]",
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"queue"
],
"type": "tag"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "pfsense",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"drops"
],
"type": "field"
},
{
"params": [],
"type": "mean"
},
{
"params": [
"10s"
],
"type": "derivative"
}
]
],
"tags": [],
"target": ""
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Drops",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"transparent": true,
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "influxdb",
"decimals": 0,
"fill": 1,
"gridPos": {
"h": 7,
"w": 12,
"x": 12,
"y": 7
},
"id": 12,
"legend": {
"alignAsTable": true,
"avg": false,
"current": true,
"hideZero": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"sort": "current",
"sortDesc": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [
{
"alias": "/ack/",
"color": "#5195ce",
"fill": 0
},
{
"alias": "q_up_tcp_psh",
"color": "#0a50a1",
"fill": 2
},
{
"alias": "q_up_control",
"color": "#ffffff",
"dashes": true
},
{
"alias": "q_up_udp_high",
"color": "#cc0000",
"fill": 4
},
{
"alias": "q_up_udp_low",
"color": "#aa0000",
"fill": 6
},
{
"alias": "q_up_udp_vpn",
"color": "#aa0000",
"fill": 8
},
{
"alias": "q_default",
"bars": false,
"legend": false,
"lines": false,
"points": false
}
],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"$$hashKey": "object:3171",
"alias": "[[tag_queue]]",
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"queue"
],
"type": "tag"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "pfsense",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"qdepth"
],
"type": "field"
},
{
"params": [],
"type": "mean"
}
]
],
"tags": [],
"target": ""
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Q-Depth",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"transparent": true,
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": "queued",
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": "Drops/s",
"logBase": 1,
"max": "500",
"min": "0",
"show": false
}
]
}
],
"refresh": "5s",
"schemaVersion": 16,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-5m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "PFSense Queues",
"uid": "xrkdMxMik",
"version": 4
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
telegraf.conf exec section example