From 28d296bb65df3b3c1e077327b93b0f6b96ba28dc Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Tue, 4 Jun 2024 10:04:47 +0200 Subject: [PATCH] Grafana --- .env.example | 4 + .gitignore | 3 +- README.md | 6 + docker-compose.yml | 13 +- .../dashboards-prov/dashboard.yml | 11 ++ grafana-provisioning/dashboards/allnet.json | 134 ++++++++++++++++++ .../datasources/datasource.yml | 14 ++ 7 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 .env.example create mode 100644 grafana-provisioning/dashboards-prov/dashboard.yml create mode 100644 grafana-provisioning/dashboards/allnet.json create mode 100644 grafana-provisioning/datasources/datasource.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d4ca1e3 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +INFUXDB_USERNAME=admin +INFLUXDB_PASSWORD=password +INFLUXDB_TOKEN= +GRAFANA_PASSWORD="password123#" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 03dbed0..fdc9fc6 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,5 @@ dist .yarn/install-state.gz .pnp.* -influxdb \ No newline at end of file +influxdb +grafana \ No newline at end of file diff --git a/README.md b/README.md index fd4bfff..b416520 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ # influxdb-allnet-connector + +## Usage + +- Projekt clonen +- `.env` erstellen und mit den Daten aus `.env.example` befüllen +- Ausführen: `docker-compose up -d` diff --git a/docker-compose.yml b/docker-compose.yml index 883d760..dfc419c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,4 +44,15 @@ services: ports: - 3000:3000 environment: - - TZ=Europe/Berlin \ No newline at end of file + - TZ=Europe/Berlin + - GF_AUTH_ANONYMOUS_ENABLED=true + - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer + - GF_SECURITY_ALLOW_EMBEDDING=true + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD} + - INFLUXDB_TOKEN=${INFLUXDB_TOKEN} + volumes: + - ./grafana/storage:/var/lib/grafana + - ./grafana-provisioning/datasources:/etc/grafana/provisioning/datasources + - ./grafana-provisioning/dashboards-prov:/etc/grafana/provisioning/dashboards + - ./grafana-provisioning/dashboards:/var/lib/grafana/dashboards \ No newline at end of file diff --git a/grafana-provisioning/dashboards-prov/dashboard.yml b/grafana-provisioning/dashboards-prov/dashboard.yml new file mode 100644 index 0000000..2d2266d --- /dev/null +++ b/grafana-provisioning/dashboards-prov/dashboard.yml @@ -0,0 +1,11 @@ +apiVersion: 1 + +providers: + - name: "default" + orgId: 1 + folder: "" + type: file + disableDeletion: false + updateIntervalSeconds: 10 + options: + path: /var/lib/grafana/dashboards \ No newline at end of file diff --git a/grafana-provisioning/dashboards/allnet.json b/grafana-provisioning/dashboards/allnet.json new file mode 100644 index 0000000..0a4f670 --- /dev/null +++ b/grafana-provisioning/dashboards/allnet.json @@ -0,0 +1,134 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 4, + "links": [], + "panels": [ + { + "datasource": { + "type": "influxdb", + "uid": "f607742f-31b6-4340-8557-c7b2d0770e0a" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": 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", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "celsius" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "maxHeight": 600, + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "influxdb", + "uid": "f607742f-31b6-4340-8557-c7b2d0770e0a" + }, + "query": "from(bucket: \"allnet\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"sId_107\")\r\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\r\n |> yield(name: \"mean\")", + "refId": "A" + } + ], + "title": "Temperatur", + "type": "timeseries" + } + ], + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timeRangeUpdatedDuringEditOrView": false, + "timepicker": {}, + "timezone": "browser", + "title": "Allnet", + "uid": "bdnqkz6ow70u8a", + "version": 1, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana-provisioning/datasources/datasource.yml b/grafana-provisioning/datasources/datasource.yml new file mode 100644 index 0000000..687dcda --- /dev/null +++ b/grafana-provisioning/datasources/datasource.yml @@ -0,0 +1,14 @@ +apiVersion: 1 + +datasources: + - name: InfluxDB + type: influxdb + access: proxy + url: http://influxdb:8086 + jsonData: + version: Flux + organization: org + defaultBucket: allnet + tlsSkipVerify: true + secureJsonData: + token: ${INFLUXDB_TOKEN} \ No newline at end of file