From b2d0542fed90418e041dabf9fd08f3e2617b9292 Mon Sep 17 00:00:00 2001 From: Hasan Eroglu Date: Thu, 5 Sep 2024 17:39:21 +0200 Subject: [PATCH 1/2] add provision config for grafana Signed-off-by: Hasan Eroglu --- conf/grafana/dashboards/dashboard.json | 142 ++++++++++++++++++ .../provisioning/dashboards/dashboard.yml | 11 ++ .../provisioning/datasources/datasource.yml | 10 ++ docker-compose-infra.yml | 8 +- 4 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 conf/grafana/dashboards/dashboard.json create mode 100644 conf/grafana/provisioning/dashboards/dashboard.yml create mode 100644 conf/grafana/provisioning/datasources/datasource.yml diff --git a/conf/grafana/dashboards/dashboard.json b/conf/grafana/dashboards/dashboard.json new file mode 100644 index 0000000..1f0e23f --- /dev/null +++ b/conf/grafana/dashboards/dashboard.json @@ -0,0 +1,142 @@ +{ + "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": 1, + "links": [], + "panels": [ + { + "datasource": { + "default": true, + "type": "prometheus", + "uid": "adwznwwq8yupse" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": true, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.5, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "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 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "adwznwwq8yupse" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "changes(traefik_service_requests_total{protocol=\"http\", service=\"http-express-calculator-simple-test-things@docker\"}[1m])", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Status Code:{{code}}", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "HTTP Express Calculator GET Requests", + "type": "timeseries" + } + ], + "refresh": "", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-1h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "HTTP Services", + "uid": "bdwzocnv714hsd", + "version": 1, + "weekStart": "" +} \ No newline at end of file diff --git a/conf/grafana/provisioning/dashboards/dashboard.yml b/conf/grafana/provisioning/dashboards/dashboard.yml new file mode 100644 index 0000000..2d2266d --- /dev/null +++ b/conf/grafana/provisioning/dashboards/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/conf/grafana/provisioning/datasources/datasource.yml b/conf/grafana/provisioning/datasources/datasource.yml new file mode 100644 index 0000000..f6e070d --- /dev/null +++ b/conf/grafana/provisioning/datasources/datasource.yml @@ -0,0 +1,10 @@ +apiVersion: 1 + +datasources: + - name: prometheus-datasource + uid: adwznwwq8yupse #THIS IS IMPORTANT ON THE DASHBOARD MUST BE THE SAME + orgId: 1 + type: prometheus + access: proxy + url: http://prometheus:${PROMETHEUS_PORT} + isDefault: true \ No newline at end of file diff --git a/docker-compose-infra.yml b/docker-compose-infra.yml index 00e4e6e..b093bbb 100644 --- a/docker-compose-infra.yml +++ b/docker-compose-infra.yml @@ -59,10 +59,12 @@ services: - cadvisor grafana: image: grafana/grafana + environment: + - PROMETHEUS_PORT=${PROMETHEUS_PORT} volumes: + - ./conf/grafana/provisioning:/etc/grafana/provisioning + - ./conf/grafana/dashboards:/var/lib/grafana/dashboards - grafana_data:/var/lib/grafana - environment: - GF_INSTALL_PLUGINS: grafana-piechart-panel labels: - "traefik.http.routers.grafana.rule=Host(`grafana.${HOSTNAME}`)" - "traefik.http.routers.grafana.service=grafana" @@ -124,6 +126,6 @@ services: cpus: '0.05' memory: 50M volumes: - grafana_data: prometheus_data: + grafana_data: portainer_data: From 494e53d8309a2ca8a7caedf422f3ef537bc1ff3c Mon Sep 17 00:00:00 2001 From: Hasan Eroglu Date: Fri, 6 Sep 2024 16:24:55 +0200 Subject: [PATCH 2/2] update README.md Signed-off-by: Hasan Eroglu --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index a228723..6617498 100644 --- a/README.md +++ b/README.md @@ -117,3 +117,13 @@ A username and password should be generated for running the services. To do so: For running the things separately, using their `Dockerfile`'s, `docker build -t -f ./Dockerfile ../../` command must be used to give the context to be able to copy `tm.json` into the container. For Node.js-based devices, we use npm workspaces and running `npm install` at the root directory installs all the packages needed for every device. After packages are installed, running `node main.js` would run the thing. For port configuration, running either `node main.js -p 1000` or `node main.js --port 1000` would start the thing on port 1000. + +### Saving Grafana Dashboards + +Grafana dashboard json files are stored in [./conf/grafana/dashboards](./conf//grafana//dashboards/). +To save your newly created dashboard locally and push it into the remote repository: + - Export the dashboard as JSON file using Share > Export. + - Save the exported JSON file to [./conf/grafana/dashboards](./conf//grafana//dashboards/). + +If your dashboard uses another datasource than our default `prometheus-datasource`, new datasource also must be provisioned in [./conf/grafana/datasources](./conf/grafana/provisioning/datasources/). +For more information check Grafana's provisioning [documentation](https://grafana.com/docs/grafana/latest/administration/provisioning/). \ No newline at end of file