diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9de9975 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.14.5 AS build-env + +LABEL maintainer="Max Schmitt " +LABEL maintainer="Andreas Schmid " +LABEL description="FRITZ!Box Prometheus exporter" + +RUN go get -v github.com/aaschmid/fritzbox_exporter && \ + cd /go/src/github.com/aaschmid/fritzbox_exporter && \ + CGO_ENABLED=0 go build -v -o /exporter + + +FROM alpine + +RUN apk update && apk add ca-certificates + +COPY --from=build-env /go/src/github.com/aaschmid/fritzbox_exporter/metrics.json /metrics.json +COPY --from=build-env /exporter / + +EXPOSE 9133 + +ENTRYPOINT ["/exporter"] +CMD ["-listen-address", ":9133", "-metrics-file", "/metrics.json"] diff --git a/grafana/Dashboard.json b/grafana/Dashboard.json index a2072cb..020f23c 100644 --- a/grafana/Dashboard.json +++ b/grafana/Dashboard.json @@ -20,7 +20,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "6.7.4" + "version": "7.1.0" }, { "type": "panel", @@ -42,15 +42,20 @@ }, { "type": "panel", - "id": "table", - "name": "Table", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "table-old", + "name": "Table (old)", "version": "" } ], "annotations": { "list": [ { - "$$hashKey": "object:41", "builtIn": 1, "datasource": "-- Grafana --", "enable": true, @@ -61,66 +66,83 @@ } ] }, - "description": "Monitor FRITZ!Box routers.", + "description": "Monitor FRITZ!Box routers using prometheus and fritzbox_exporter", "editable": true, - "gnetId": 713, + "gnetId": 12579, "graphTooltip": 2, "id": null, "links": [], "panels": [ { "cacheTimeout": null, - "colorBackground": true, - "colorValue": false, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "#1f78c1" - ], "datasource": "${DS_PROMETHEUS}", - "format": "none", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + }, + { + "id": 1, + "op": "=", + "text": "Disconnected", + "type": 1, + "value": "0" + }, + { + "id": 2, + "op": "=", + "text": "Connected", + "type": 1, + "value": "1" + } + ], + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(245, 54, 54, 0.9)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 1 + }, + { + "color": "#1f78c1", + "value": 1 + } + ] + }, + "unit": "none" + }, + "overrides": [] }, "id": 10, "interval": null, "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": false + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" }, - "tableColumn": "", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", @@ -164,46 +186,59 @@ "target": "" } ], - "thresholds": "1,1", "title": "WAN Connection Status", - "type": "singlestat", - "valueFontSize": "80%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - }, - { - "op": "=", - "text": "Disconnected", - "value": "0" - }, - { - "op": "=", - "text": "Connected", - "value": "1" - } - ], - "valueName": "current" + "type": "stat" }, { "cacheTimeout": null, - "colorBackground": true, - "colorValue": false, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "#1f78c1" - ], "datasource": "${DS_PROMETHEUS}", - "format": "none", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + }, + { + "id": 1, + "op": "=", + "text": "Disconnected", + "type": 1, + "value": "0" + }, + { + "id": 2, + "op": "=", + "text": "Connected", + "type": 1, + "value": "1" + } + ], + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(245, 54, 54, 0.9)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 1 + }, + { + "color": "#1f78c1", + "value": 1 + } + ] + }, + "unit": "none" + }, + "overrides": [] }, "gridPos": { "h": 3, @@ -214,38 +249,22 @@ "id": 9, "interval": null, "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": false + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" }, - "tableColumn": "", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", @@ -289,34 +308,54 @@ "target": "" } ], - "thresholds": "1,1", "title": "DSL Link Status", - "type": "singlestat", - "valueFontSize": "80%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - }, - { - "op": "=", - "text": "Disconnected", - "value": "0" - }, - { - "op": "=", - "text": "Connected", - "value": "1" - } - ], - "valueName": "current" + "type": "stat" }, { "cacheTimeout": null, "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": {}, + "decimals": 0, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "max": 7000000, + "min": 0, + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 2500000 + }, + { + "color": "red", + "value": 5000000 + } + ] + }, + "unit": "Bps" + }, + "overrides": [] + }, "gridPos": { - "h": 6, + "h": 5, "w": 6, "x": 12, "y": 0 @@ -324,58 +363,23 @@ "id": 11, "links": [], "options": { - "fieldOptions": { + "orientation": "horizontal", + "reduceOptions": { "calcs": [ - "lastNotNull" + "last" ], - "defaults": { - "color": { - "mode": "thresholds" - }, - "decimals": 1, - "mappings": [ - { - "id": 0, - "op": "=", - "text": "N/A", - "type": 1, - "value": "null" - } - ], - "max": 116000000, - "min": 0, - "nullValueMode": "connected", - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "rgba(237, 129, 40, 0.89)", - "value": 50000000 - }, - { - "color": "red", - "value": 100000000 - } - ] - }, - "unit": "bps" - }, - "overrides": [], + "fields": "", "values": false }, - "orientation": "horizontal", "showThresholdLabels": false, "showThresholdMarkers": true }, - "pluginVersion": "6.7.4", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", "expr": "gateway_wan_bytes_receive_rate", + "format": "table", "groupBy": [ { "params": [ @@ -384,6 +388,7 @@ "type": "time" } ], + "instant": false, "interval": "", "legendFormat": "", "measurement": "fritzbox_value", @@ -421,8 +426,52 @@ { "cacheTimeout": null, "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": {}, + "decimals": 1, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "max": 1100000, + "min": 0, + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + }, + { + "color": "green", + "value": 250000 + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 500000 + }, + { + "color": "#e24d42", + "value": 1000000 + } + ] + }, + "unit": "Bps" + }, + "overrides": [] + }, "gridPos": { - "h": 6, + "h": 5, "w": 6, "x": 18, "y": 0 @@ -430,62 +479,23 @@ "id": 12, "links": [], "options": { - "fieldOptions": { + "orientation": "horizontal", + "reduceOptions": { "calcs": [ - "lastNotNull" + "last" ], - "defaults": { - "color": { - "mode": "thresholds" - }, - "decimals": 1, - "mappings": [ - { - "id": 0, - "op": "=", - "text": "N/A", - "type": 1, - "value": "null" - } - ], - "max": 40000000, - "min": 0, - "nullValueMode": "connected", - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "blue", - "value": null - }, - { - "color": "green", - "value": 5000000 - }, - { - "color": "rgba(237, 129, 40, 0.89)", - "value": 10000000 - }, - { - "color": "#e24d42", - "value": 30000000 - } - ] - }, - "unit": "bps" - }, - "overrides": [], + "fields": "", "values": false }, - "orientation": "horizontal", "showThresholdLabels": false, "showThresholdMarkers": true }, - "pluginVersion": "6.7.4", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", "expr": "gateway_wan_bytes_send_rate", + "format": "table", "groupBy": [ { "params": [ @@ -530,22 +540,51 @@ }, { "cacheTimeout": null, - "colorBackground": false, - "colorValue": false, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "rgba(50, 172, 45, 0.97)" - ], "datasource": "${DS_PROMETHEUS}", - "decimals": 1, - "format": "dtdurations", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true + "fieldConfig": { + "defaults": { + "custom": {}, + "decimals": 1, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + }, + { + "id": 1, + "op": "=", + "text": "Disconnected", + "type": 1, + "value": "0" + }, + { + "id": 2, + "op": "=", + "text": "Connected", + "type": 1, + "value": "1" + } + ], + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(245, 54, 54, 0.9)", + "value": null + }, + { + "color": "rgba(50, 172, 45, 0.97)", + "value": 1 + } + ] + }, + "unit": "dtdurations" + }, + "overrides": [] }, "gridPos": { "h": 3, @@ -556,39 +595,23 @@ "id": 21, "interval": null, "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 + "maxDataPoints": 100, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false }, - { - "name": "range to text", - "value": 2 - } - ], - "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": false - }, - "tableColumn": "", - "targets": [ + "textMode": "auto" + }, + "pluginVersion": "7.1.0", + "targets": [ { "dsType": "prometheus", "expr": "gateway_uptime_seconds", @@ -631,47 +654,46 @@ "target": "" } ], - "thresholds": "1,1", "title": "Fritzbox Uptime", - "type": "singlestat", - "valueFontSize": "80%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - }, - { - "op": "=", - "text": "Disconnected", - "value": "0" - }, - { - "op": "=", - "text": "Connected", - "value": "1" - } - ], - "valueName": "current" + "type": "stat" }, { "cacheTimeout": null, - "colorBackground": false, - "colorValue": false, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "rgba(50, 172, 45, 0.97)" - ], "datasource": "${DS_PROMETHEUS}", - "decimals": 1, - "format": "dtdurations", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true + "fieldConfig": { + "defaults": { + "custom": {}, + "decimals": 1, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(245, 54, 54, 0.9)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 1 + }, + { + "color": "rgba(50, 172, 45, 0.97)", + "value": 1 + } + ] + }, + "unit": "dtdurations" + }, + "overrides": [] }, "gridPos": { "h": 3, @@ -682,38 +704,22 @@ "id": 13, "interval": null, "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": false + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" }, - "tableColumn": "", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", @@ -757,18 +763,8 @@ "target": "" } ], - "thresholds": "1,1", "title": "Connection Uptime", - "type": "singlestat", - "valueFontSize": "80%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - } - ], - "valueName": "current" + "type": "stat" }, { "cacheTimeout": null, @@ -781,6 +777,12 @@ ], "datasource": "${DS_PROMETHEUS}", "decimals": 1, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "format": "decbytes", "gauge": { "maxValue": 100, @@ -792,11 +794,12 @@ "gridPos": { "h": 4, "w": 6, - "x": 0, - "y": 6 + "x": 12, + "y": 5 }, - "id": 3, - "interval": null, + "hideTimeOverride": false, + "id": 22, + "interval": "", "links": [], "mappingType": 1, "mappingTypes": [ @@ -829,7 +832,7 @@ "lineColor": "rgb(31, 120, 193)", "show": true }, - "tableColumn": "", + "tableColumn": "gateway_wan_bytes_received{gateway=\"fritz.box\", instance=\"fritzbox-exporter-svc.fritzbox:9133\", job=\"fritzbox\"}", "targets": [ { "dsType": "prometheus", @@ -840,7 +843,7 @@ "measurement": "fritzbox_value", "orderByTime": "ASC", "policy": "default", - "query": "SELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter GROUP BY time($__interval)", + "query": "SELECT cumulative_sum(max(\"value\")) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter GROUP BY time($__interval) tz('Europe/Berlin')", "rawQuery": false, "refId": "A", "resultFormat": "time_series", @@ -853,10 +856,8 @@ "type": "field" }, { - "params": [ - "10s" - ], - "type": "non_negative_derivative" + "params": [], + "type": "non_negative_difference" } ] ], @@ -871,7 +872,9 @@ } ], "thresholds": "", - "title": "Total Download", + "timeFrom": "1d", + "timeShift": null, + "title": "Last 24h Download", "type": "singlestat", "valueFontSize": "100%", "valueMaps": [ @@ -881,12 +884,11 @@ "value": "null" } ], - "valueName": "total" + "valueName": "range" }, { "cacheTimeout": null, "colorBackground": false, - "colorPrefix": true, "colorValue": false, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -895,6 +897,12 @@ ], "datasource": "${DS_PROMETHEUS}", "decimals": 1, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "format": "decbytes", "gauge": { "maxValue": 100, @@ -906,10 +914,10 @@ "gridPos": { "h": 4, "w": 6, - "x": 6, - "y": 6 + "x": 18, + "y": 5 }, - "id": 8, + "id": 16, "interval": null, "links": [], "mappingType": 1, @@ -943,7 +951,7 @@ "lineColor": "#e24d42", "show": true }, - "tableColumn": "", + "tableColumn": "gateway_wan_bytes_sent{gateway=\"fritz.box\", instance=\"fritzbox-exporter-svc.fritzbox:9133\", job=\"fritzbox\"}", "targets": [ { "dsType": "prometheus", @@ -954,7 +962,7 @@ "measurement": "fritzbox_value", "orderByTime": "ASC", "policy": "default", - "query": "SELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter GROUP BY time($__interval)", + "query": "SELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter GROUP BY time($__interval) tz('Europe/Berlin')", "rawQuery": false, "refId": "A", "resultFormat": "time_series", @@ -983,7 +991,8 @@ } ], "thresholds": "", - "title": "Total Upload", + "timeFrom": "1d", + "title": "Last 24h Upload", "type": "singlestat", "valueFontSize": "100%", "valueMaps": [ @@ -993,69 +1002,67 @@ "value": "null" } ], - "valueName": "total" + "valueName": "range" }, { "cacheTimeout": null, - "colorBackground": false, - "colorValue": false, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "rgba(50, 172, 45, 0.97)" - ], "datasource": "${DS_PROMETHEUS}", - "decimals": 1, - "format": "decbytes", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true + "fieldConfig": { + "defaults": { + "custom": {}, + "decimals": 1, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] }, "gridPos": { "h": 4, "w": 6, - "x": 12, + "x": 0, "y": 6 }, - "hideTimeOverride": false, - "id": 22, - "interval": "", + "id": 3, + "interval": null, "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": true + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "sum" + ], + "fields": "", + "values": false + }, + "textMode": "auto" }, - "tableColumn": "", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", @@ -1066,7 +1073,7 @@ "measurement": "fritzbox_value", "orderByTime": "ASC", "policy": "default", - "query": "SELECT cumulative_sum(max(\"value\")) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter GROUP BY time($__interval) tz('Europe/Berlin')", + "query": "SELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter GROUP BY time($__interval)", "rawQuery": false, "refId": "A", "resultFormat": "time_series", @@ -1079,8 +1086,10 @@ "type": "field" }, { - "params": [], - "type": "non_negative_difference" + "params": [ + "10s" + ], + "type": "non_negative_derivative" } ] ], @@ -1094,81 +1103,68 @@ "target": "" } ], - "thresholds": "", - "timeFrom": "1d", - "timeShift": null, - "title": "Last 24h Download", - "type": "singlestat", - "valueFontSize": "100%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - } - ], - "valueName": "range" + "title": "Total Download", + "type": "stat" }, { "cacheTimeout": null, - "colorBackground": false, - "colorValue": false, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "rgba(50, 172, 45, 0.97)" - ], "datasource": "${DS_PROMETHEUS}", - "decimals": 1, - "format": "decbytes", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true + "fieldConfig": { + "defaults": { + "custom": {}, + "decimals": 1, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "nullValueMode": "connected", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] }, "gridPos": { "h": 4, "w": 6, - "x": 18, + "x": 6, "y": 6 }, - "id": 16, + "id": 8, "interval": null, "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "sparkline": { - "fillColor": "rgba(137, 15, 2, 0.18)", - "full": false, - "lineColor": "#e24d42", - "show": true + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "sum" + ], + "fields": "", + "values": false + }, + "textMode": "auto" }, - "tableColumn": "", + "pluginVersion": "7.1.0", "targets": [ { "dsType": "prometheus", @@ -1179,7 +1175,7 @@ "measurement": "fritzbox_value", "orderByTime": "ASC", "policy": "default", - "query": "SELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter GROUP BY time($__interval) tz('Europe/Berlin')", + "query": "SELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter GROUP BY time($__interval)", "rawQuery": false, "refId": "A", "resultFormat": "time_series", @@ -1207,119 +1203,8 @@ "target": "" } ], - "thresholds": "", - "timeFrom": "1d", - "title": "Last 24h Upload", - "type": "singlestat", - "valueFontSize": "100%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - } - ], - "valueName": "range" - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "${DS_PROMETHEUS}", - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 10 - }, - "hiddenSeries": false, - "id": 24, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "expr": "gateway_wlan_current_connections", - "interval": "", - "legendFormat": "2.4 GHz", - "refId": "A" - }, - { - "expr": "gateway_wlan2_current_connections", - "interval": "", - "legendFormat": "5 GHz", - "refId": "B" - }, - { - "expr": "gateway_wlan_current_connections+gateway_wlan2_current_connections", - "interval": "", - "legendFormat": "Total", - "refId": "C" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "WLAN Connections", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "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 - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } + "title": "Total Upload", + "type": "stat" }, { "aliasColors": { @@ -1336,14 +1221,21 @@ "dashes": false, "datasource": "${DS_PROMETHEUS}", "editable": true, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "grid": {}, "gridPos": { - "h": 7, + "h": 6, "w": 6, "x": 12, - "y": 10 + "y": 9 }, "hiddenSeries": false, "id": 18, @@ -1362,10 +1254,8 @@ "linewidth": 1, "links": [], "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, "percentage": false, + "pluginVersion": "7.1.0", "pointradius": 5, "points": false, "renderer": "flot", @@ -1657,15 +1547,23 @@ "dashLength": 10, "dashes": false, "datasource": "${DS_PROMETHEUS}", + "description": "", "editable": true, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 0, "fillGradient": 0, "grid": {}, "gridPos": { - "h": 7, + "h": 6, "w": 6, "x": 18, - "y": 10 + "y": 9 }, "hiddenSeries": false, "id": 17, @@ -1683,10 +1581,8 @@ "linewidth": 1, "links": [], "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, "percentage": false, + "pluginVersion": "7.1.0", "pointradius": 5, "points": false, "renderer": "flot", @@ -1701,34 +1597,336 @@ { "alias": "download", "dsType": "prometheus", - "expr": "delta(gateway_wan_bytes_received[1m])/60", + "expr": "delta(gateway_wan_bytes_received[120s])/120", + "fields": [ + { + "func": "mean", + "name": "value" + } + ], + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "groupByTags": [], + "interval": "", + "legendFormat": "Download", + "measurement": "fritzbox_value", + "orderByTime": "ASC", + "policy": "default", + "query": "SELECT mean(\"value\") FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter GROUP BY time($interval) fill(null)", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "type_instance", + "operator": "=", + "value": "totalbytesreceived" + } + ], + "target": "alias(summarize(nonNegativeDerivative(collectd.squirrel.fritzbox.bytes-totalbytesreceived, 0), '1h', 'sum'), 'download')" + }, + { + "alias": "upload", + "dsType": "prometheus", + "expr": "delta(gateway_wan_bytes_sent[120s])/120", "fields": [ { "func": "mean", "name": "value" } ], + "fill": "null", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "groupByTags": [], + "hide": false, + "interval": "", + "legendFormat": "Upload", + "measurement": "fritzbox_value", + "orderByTime": "ASC", + "policy": "default", + "query": "SELECT non_negative_difference(last(cumulative_sum)) FROM (\nSELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter GROUP BY time($__interval)\n) WHERE $timeFilter GROUP BY time($__interval) tz('Europe/Berlin')", + "rawQuery": true, + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "type_instance", + "operator": "=", + "value": "totalbytessent" + } + ], + "target": "alias(summarize(nonNegativeDerivative(collectd.squirrel.fritzbox.bytes-totalbytessent,0),'1h','sum'),'upload')" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Current Traffic", + "tooltip": { + "msResolution": false, + "query_as_alias": true, + "shared": true, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "Bps", + "logBase": 1, + "max": null, + "min": 0, + "show": true + }, + { + "format": "Bps", + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + }, + "zerofill": true + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 10 + }, + "hiddenSeries": false, + "id": 24, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "percentage": false, + "pluginVersion": "7.1.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "gateway_wlan_current_connections", + "interval": "", + "legendFormat": "2.4 GHz", + "refId": "A" + }, + { + "expr": "gateway_wlan2_current_connections", + "interval": "", + "legendFormat": "5 GHz", + "refId": "B" + }, + { + "expr": "gateway_wlan_current_connections+gateway_wlan2_current_connections", + "interval": "", + "legendFormat": "Total", + "refId": "C" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "WLAN Connections", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 0, + "format": "short", + "label": "", + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "columns": [], + "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "fontSize": "100%", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 15 + }, + "id": 14, + "links": [], + "pageSize": null, + "scroll": true, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "MMMM D, YYYY LT", + "pattern": "Time", + "type": "date" + }, + { + "alias": "", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "decimals": 2, + "pattern": "/.*/", + "thresholds": [], + "type": "number", + "unit": "decbytes" + } + ], + "targets": [ + { + "alias": "Download", + "dsType": "prometheus", + "expr": "gateway_wan_bytes_received", "groupBy": [ { "params": [ - "$interval" + "1d" ], "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" } ], - "groupByTags": [], "interval": "", "legendFormat": "Download", "measurement": "fritzbox_value", "orderByTime": "ASC", "policy": "default", - "query": "SELECT mean(\"value\") FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter GROUP BY time($interval) fill(null)", + "query": "SELECT non_negative_difference(last(cumulative_sum)) FROM (\nSELECT cumulative_sum(non_negative_difference(\"value\")) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter \n) WHERE $timeFilter GROUP BY time(1d) tz('Europe/Berlin')", "rawQuery": true, "refId": "A", "resultFormat": "time_series", @@ -1742,7 +1940,13 @@ }, { "params": [], - "type": "mean" + "type": "max" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" } ] ], @@ -1753,41 +1957,26 @@ "value": "totalbytesreceived" } ], - "target": "alias(summarize(nonNegativeDerivative(collectd.squirrel.fritzbox.bytes-totalbytesreceived, 0), '1h', 'sum'), 'download')" + "target": "" }, { - "alias": "upload", + "alias": "Upload", "dsType": "prometheus", - "expr": "delta(gateway_wan_bytes_sent[1m])/60", - "fields": [ - { - "func": "mean", - "name": "value" - } - ], - "fill": "null", + "expr": "gateway_wan_bytes_sent", "groupBy": [ { "params": [ - "$interval" + "1d" ], "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" } ], - "groupByTags": [], - "hide": false, "interval": "", "legendFormat": "Upload", "measurement": "fritzbox_value", "orderByTime": "ASC", "policy": "default", - "query": "SELECT non_negative_difference(last(cumulative_sum)) FROM (\nSELECT cumulative_sum(non_negative_difference(last(\"value\"))) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter GROUP BY time($__interval)\n) WHERE $timeFilter GROUP BY time($__interval) tz('Europe/Berlin')", + "query": "SELECT non_negative_difference(last(cumulative_sum)) FROM (\nSELECT cumulative_sum(non_negative_difference(\"value\")) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter\n) WHERE $timeFilter GROUP BY time(1d) tz('Europe/Berlin')", "rawQuery": true, "refId": "B", "resultFormat": "time_series", @@ -1801,7 +1990,13 @@ }, { "params": [], - "type": "mean" + "type": "max" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" } ] ], @@ -1809,53 +2004,15 @@ { "key": "type_instance", "operator": "=", - "value": "totalbytessent" + "value": "totalbytesreceived" } ], - "target": "alias(summarize(nonNegativeDerivative(collectd.squirrel.fritzbox.bytes-totalbytessent,0),'1h','sum'),'upload')" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Current Traffic", - "tooltip": { - "msResolution": false, - "query_as_alias": true, - "shared": true, - "sort": 0, - "value_type": "cumulative" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "Bps", - "logBase": 1, - "max": null, - "min": 0, - "show": true - }, - { - "format": "Bps", - "logBase": 1, - "max": null, - "min": null, - "show": true + "target": "" } ], - "yaxis": { - "align": false, - "alignLevel": null - }, - "zerofill": true + "title": "Daily Traffic", + "transform": "timeseries_to_columns", + "type": "table-old" }, { "aliasColors": { @@ -1868,13 +2025,20 @@ "dashLength": 10, "dashes": false, "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { - "h": 7, + "h": 6, "w": 12, "x": 0, - "y": 18 + "y": 16 }, "hiddenSeries": false, "id": 2, @@ -1896,10 +2060,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": { - "dataLinks": [] - }, "percentage": false, + "pluginVersion": "7.1.0", "pointradius": 5, "points": false, "renderer": "flot", @@ -2054,166 +2216,17 @@ "align": false, "alignLevel": null } - }, - { - "columns": [], - "datasource": "${DS_PROMETHEUS}", - "fontSize": "100%", - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 25 - }, - "id": 14, - "links": [], - "pageSize": null, - "scroll": true, - "showHeader": true, - "sort": { - "col": 0, - "desc": true - }, - "styles": [ - { - "alias": "Time", - "align": "auto", - "dateFormat": "MMMM D, YYYY LT", - "pattern": "Time", - "type": "date" - }, - { - "alias": "", - "align": "auto", - "colorMode": null, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "rgba(50, 172, 45, 0.97)" - ], - "decimals": 2, - "pattern": "/.*/", - "thresholds": [], - "type": "number", - "unit": "decbytes" - } - ], - "targets": [ - { - "alias": "Download", - "dsType": "prometheus", - "expr": "gateway_wan_bytes_received", - "groupBy": [ - { - "params": [ - "1d" - ], - "type": "time" - } - ], - "interval": "", - "legendFormat": "Download", - "measurement": "fritzbox_value", - "orderByTime": "ASC", - "policy": "default", - "query": "SELECT non_negative_difference(last(cumulative_sum)) FROM (\nSELECT cumulative_sum(non_negative_difference(\"value\")) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytesreceived') AND $timeFilter \n) WHERE $timeFilter GROUP BY time(1d) tz('Europe/Berlin')", - "rawQuery": true, - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "value" - ], - "type": "field" - }, - { - "params": [], - "type": "max" - }, - { - "params": [ - "10s" - ], - "type": "non_negative_derivative" - } - ] - ], - "tags": [ - { - "key": "type_instance", - "operator": "=", - "value": "totalbytesreceived" - } - ], - "target": "" - }, - { - "alias": "Upload", - "dsType": "prometheus", - "expr": "gateway_wan_bytes_sent", - "groupBy": [ - { - "params": [ - "1d" - ], - "type": "time" - } - ], - "interval": "", - "legendFormat": "Upload", - "measurement": "fritzbox_value", - "orderByTime": "ASC", - "policy": "default", - "query": "SELECT non_negative_difference(last(cumulative_sum)) FROM (\nSELECT cumulative_sum(non_negative_difference(\"value\")) FROM \"fritzbox_value\" WHERE (\"type_instance\" = 'totalbytessent') AND $timeFilter\n) WHERE $timeFilter GROUP BY time(1d) tz('Europe/Berlin')", - "rawQuery": true, - "refId": "B", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "value" - ], - "type": "field" - }, - { - "params": [], - "type": "max" - }, - { - "params": [ - "10s" - ], - "type": "non_negative_derivative" - } - ] - ], - "tags": [ - { - "key": "type_instance", - "operator": "=", - "value": "totalbytesreceived" - } - ], - "target": "" - } - ], - "title": "Daily Traffic", - "transform": "timeseries_to_columns", - "type": "table" } ], "refresh": false, - "schemaVersion": 22, + "schemaVersion": 26, "style": "dark", "tags": [], "templating": { "list": [] }, "time": { - "from": "now-7d", + "from": "now-24h", "to": "now" }, "timepicker": { @@ -2244,8 +2257,5 @@ "timezone": "", "title": "FRITZ!Box Status", "uid": "000000013", - "variables": { - "list": [] - }, - "version": 18 -} \ No newline at end of file + "version": 5 +} diff --git a/grafana/README.md b/grafana/README.md index 82fa5af..a59129d 100644 --- a/grafana/README.md +++ b/grafana/README.md @@ -1,8 +1,6 @@ # Grafana dashboard working with this exporter This dashboard is based on the following dashboard: -https://grafana.com/grafana/dashboards/713 +https://grafana.com/grafana/dashboards/12579 -Instead of influx it uses prometheus and has been modified and enhanced. - -The dashboard is now also published to [Grafana](https://grafana.com/grafana/dashboards/12579) +Adjusted to my personal max down- and upstream and upgraded to the newest grafana version. diff --git a/main.go b/main.go index a0ba1fa..0e4b5d3 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ import ( "github.com/namsral/flag" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" upnp "github.com/sberk42/fritzbox_exporter/fritzbox_upnp" ) @@ -320,7 +321,7 @@ func main() { prometheus.MustRegister(collector) prometheus.MustRegister(collect_errors) - http.Handle("/metrics", prometheus.Handler()) + http.Handle("/metrics", promhttp.Handler()) fmt.Printf("metrics available at http://%s/metrics\n", *flag_addr) log.Fatal(http.ListenAndServe(*flag_addr, nil)) }