From 0bdda3c5450dab47216bfb47fc4c008337d4e2dc Mon Sep 17 00:00:00 2001 From: Sammy Delanghe Date: Wed, 26 Apr 2023 22:36:39 +0200 Subject: [PATCH] add snmp monitor --- config_prod.env | 2 + docker-compose.yml | 7 + .../provisioning/dashboards/snmp-network.json | 237 ++++++++++++++++++ prometheus/prometheus.template.yml | 15 +- snmp/Dockerfile | 5 + 5 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 grafana/provisioning/dashboards/snmp-network.json create mode 100644 snmp/Dockerfile diff --git a/config_prod.env b/config_prod.env index 2d3ac8d..c29c8bf 100644 --- a/config_prod.env +++ b/config_prod.env @@ -31,3 +31,5 @@ MANUALCOUNT_PORT=3000 CLIENT1_IP=172.12.50.21 CLIENT2_IP=172.12.50.22 + +ROUTER_IP=172.12.50.1 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 368bdc1..583bcd5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,9 +22,16 @@ services: - "--web.console.templates=/usr/share/prometheus/consoles" network_mode: host depends_on: + depends_on: - blackbox + - snmp # ports: # - "9090:9090" + snmp: + build: + context: snmp/ + dockerfile: Dockerfile + network_mode: host blackbox: build: context: blackbox/ diff --git a/grafana/provisioning/dashboards/snmp-network.json b/grafana/provisioning/dashboards/snmp-network.json new file mode 100644 index 0000000..9297fc1 --- /dev/null +++ b/grafana/provisioning/dashboards/snmp-network.json @@ -0,0 +1,237 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 15, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "description": "Traffic on the mikrotik router per bridge network", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "binBps" + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "editorMode": "code", + "expr": "rate(ifHCInOctets{ifName!~\"ether.*\"}[$__rate_interval])", + "legendFormat": "{{ifName}}", + "range": true, + "refId": "A" + } + ], + "title": "Router traffic IN", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "description": "Traffic on the mikrotik router per bridge network", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "binBps" + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 24, + "x": 0, + "y": 9 + }, + "id": 3, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "editorMode": "code", + "expr": "rate(ifHCOutOctets{ifName!~\"ether.*\"}[$__rate_interval])", + "legendFormat": "{{ifName}}", + "range": true, + "refId": "A" + } + ], + "title": "Router traffic OUT", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-1h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Network Traffic", + "uid": "N80PqzyVk", + "version": 4, + "weekStart": "" + } \ No newline at end of file diff --git a/prometheus/prometheus.template.yml b/prometheus/prometheus.template.yml index d08f44e..be65c8e 100644 --- a/prometheus/prometheus.template.yml +++ b/prometheus/prometheus.template.yml @@ -17,7 +17,20 @@ scrape_configs: metrics_path: /metrics static_configs: - targets: [ "$TELRAAM_IP:9187" ] - + - job_name: snmp + static_configs: + - targets: + - $ROUTER_IP # SNMP device + metrics_path: /snmp + params: + module: [if_mib] + relabel_configs: + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - target_label: __address__ + replacement: 127.0.0.1:9116 # The SNMP exporter's real hostname:port. - job_name: blackbox metrics_path: /probe params: diff --git a/snmp/Dockerfile b/snmp/Dockerfile new file mode 100644 index 0000000..d29c5a6 --- /dev/null +++ b/snmp/Dockerfile @@ -0,0 +1,5 @@ +FROM prom/snmp-exporter + +EXPOSE 9116 +ENTRYPOINT [ "/bin/snmp_exporter" ] +CMD [ "--config.file=/etc/snmp_exporter/snmp.yml" ] \ No newline at end of file