diff --git a/check_datasource.sh b/check_datasource.sh new file mode 100755 index 0000000..ab56979 --- /dev/null +++ b/check_datasource.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Check if Grafana container is running +if ! docker-compose ps | grep -q grafana; then + echo "Grafana container is not running. Starting it now..." + docker-compose up -d grafana + sleep 10 +fi + +# Check if InfluxDB container is running +if ! docker-compose ps | grep -q influxdb; then + echo "InfluxDB container is not running. Starting it now..." + docker-compose up -d influxdb + sleep 10 +fi + +# Check if Telegraf container is running +if ! docker-compose ps | grep -q telegraf; then + echo "Telegraf container is not running. Starting it now..." + docker-compose up -d telegraf + sleep 5 +fi + +# Check if data is being written to InfluxDB +echo "Checking if data is being written to InfluxDB..." +docker-compose exec influxdb influx query 'from(bucket: "telegraf-bucket") |> range(start: -5m) |> filter(fn: (r) => r._measurement == "cpu") |> limit(n: 1)' + +# Check Grafana data source configuration +echo -e "\nChecking Grafana data source configuration..." +docker-compose exec grafana grafana-cli admin data-sources list + +# Check if the dashboard is loaded +echo -e "\nChecking if the dashboard is loaded..." +docker-compose exec grafana ls -la /etc/grafana/provisioning/dashboards/telegraf/ + +# Check Grafana logs for errors +echo -e "\nChecking Grafana logs for errors..." +docker-compose logs --tail=50 grafana | grep -i error || echo "No errors found in the last 50 lines of logs." diff --git a/grafana/provisioning/dashboards/telegraf/system-dashboard.json b/grafana/provisioning/dashboards/telegraf/system-dashboard.json new file mode 100644 index 0000000..ced5003 --- /dev/null +++ b/grafana/provisioning/dashboards/telegraf/system-dashboard.json @@ -0,0 +1,221 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 1, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": "InfluxDB", + "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", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max", + "min" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "influxdb", + "uid": "${DS_INFLUXDB}" + }, + "query": "from(bucket: \"telegraf-bucket\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r._measurement == \"cpu\" and r._field == \"usage_user\" and r.cpu == \"cpu-total\")\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")", + "refId": "A" + } + ], + "title": "CPU Usage", + "type": "timeseries" + }, + { + "datasource": "InfluxDB", + "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", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 4, + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max", + "min" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "influxdb", + "uid": "${DS_INFLUXDB}" + }, + "query": "from(bucket: \"telegraf-bucket\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r._measurement == \"mem\" and r._field == \"used_percent\")\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")", + "refId": "A" + } + ], + "title": "Memory Usage", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 36, + "style": "dark", + "tags": ["telegraf", "system"], + "templating": { + "list": [] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Telegraf System Metrics", + "version": 1 +} diff --git a/grafana/provisioning/dashboards/system-metrics.json b/grafana/provisioning/dashboards/telegraf/system-metrics.json similarity index 99% rename from grafana/provisioning/dashboards/system-metrics.json rename to grafana/provisioning/dashboards/telegraf/system-metrics.json index ad94268..21c7f20 100644 --- a/grafana/provisioning/dashboards/system-metrics.json +++ b/grafana/provisioning/dashboards/telegraf/system-metrics.json @@ -57,6 +57,10 @@ "links": [], "panels": [ { + "datasource": { + "type": "influxdb", + "uid": "${DS_INFLUXDB}" + }, "collapsed": false, "gridPos": { "h": 1,