From 4b6cc21d3604514b25758eb91bd0f63df039be35 Mon Sep 17 00:00:00 2001 From: Manjurul Hoque Rumi Date: Wed, 9 Oct 2024 18:05:42 +0600 Subject: [PATCH] Some extra metrics for grafana --- Dockerfile | 2 +- docker-compose.yml | 27 + jobs/middlewares.py | 56 +- jobs/settings.py | 6 +- jobsapp/metrics.py | 14 +- .../grafana/dashboards/app-dashboard.json | 1004 +++++++++++++ .../grafana/dashboards/dashboard.yaml | 6 + .../grafana/dashboards/device-dashboard.json | 1268 +++++++++++++++++ .../grafana/datasources/datasource.yaml | 11 + provisioning/prometheus/prometheus.yml | 24 + provisioning/prometheus/rules.yml | 9 + 11 files changed, 2415 insertions(+), 12 deletions(-) create mode 100644 provisioning/grafana/dashboards/app-dashboard.json create mode 100644 provisioning/grafana/dashboards/dashboard.yaml create mode 100644 provisioning/grafana/dashboards/device-dashboard.json create mode 100644 provisioning/grafana/datasources/datasource.yaml create mode 100644 provisioning/prometheus/prometheus.yml create mode 100644 provisioning/prometheus/rules.yml diff --git a/Dockerfile b/Dockerfile index ad3e973..99a6fe6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ENV PYTHONUNBUFFERED 1 COPY requirements.txt /usr/src/app -RUN python -m pip install --upgrade pip +# RUN python -m pip install --upgrade pip RUN pip install -r requirements.txt COPY . /usr/src/app diff --git a/docker-compose.yml b/docker-compose.yml index f33e27f..47066d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,36 @@ version: '3' services: + prometheus: + image: prom/prometheus + container_name: prometheus + volumes: + - ./provisioning/prometheus:/etc/prometheus + ports: + - '9090:9090' + alertmanager: + image: prom/alertmanager + container_name: alertmanager + ports: + - '9093:9093' + grafana: + image: grafana/grafana:latest + container_name: grafana + ports: + - '3000:3000' + volumes: + - ./provisioning/grafana/datasources:/etc/grafana/provisioning/datasources + - ./provisioning/grafana/dashboards:/etc/grafana/provisioning/dashboards + node-exporter: # addidional service as a exporter example + image: prom/node-exporter + container_name: node-exporter + ports: + - '9100:9100' web: restart: always build: . + environment: + ENABLE_PROMETHEUS: 1 command: ./entrypoint.sh volumes: - .:/app diff --git a/jobs/middlewares.py b/jobs/middlewares.py index 4167937..3c14f95 100644 --- a/jobs/middlewares.py +++ b/jobs/middlewares.py @@ -1,19 +1,59 @@ +import time + from django.utils.deprecation import MiddlewareMixin from django.utils.timezone import now -from jobsapp.metrics import requests_total, last_user_activity_time +from jobsapp.metrics import error_rates_counter, requests_total, last_user_activity_time, \ + response_time_histogram class CustomMiddleware(MiddlewareMixin): def __init__(self, get_response): self.get_response = get_response + super().__init__(get_response) - def process_request(self, request): - path = request.path - user = request.user - if "metrics" not in path: - # because metrics is for prometheus url + def __call__(self, request): + # Exclude metrics endpoint from processing + if "metrics" not in request.path: + # Increment the Prometheus counter requests_total.labels( - endpoint=request.get_full_path, method=request.method, user=user + endpoint=request.get_full_path(), # call the method to get the path + method=request.method, + user=request.user.get_username() if request.user.is_authenticated else 'Anonymous' + # use get_username() for the user label ).inc() - last_user_activity_time.labels(user=user).set(now().timestamp()) + + # Update the last user activity time + if request.user.is_authenticated: + last_user_activity_time.labels(user=request.user.get_username()).set( + now().timestamp()) + + # Call the next middleware or view + response = self.get_response(request) + return response + + +class ResponseTimeMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + start_time = time.time() + response = self.get_response(request) + response_time = time.time() - start_time + + response_time_histogram.labels(method=request.method, endpoint=request.path).observe( + response_time) + + return response + + +class ErrorTrackingMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + response = self.get_response(request) + if 400 <= response.status_code < 600: + error_rates_counter.labels(status_code=response.status_code, endpoint=request.path).inc() + return response diff --git a/jobs/settings.py b/jobs/settings.py index 9b9f348..33ad4e9 100644 --- a/jobs/settings.py +++ b/jobs/settings.py @@ -311,10 +311,12 @@ "JWT_EXPIRATION_DELTA": timedelta(minutes=60), } -ENABLE_PROMETHEUS = int(os.environ.get("ENABLE_PROMETHEUS", "0")) +ENABLE_PROMETHEUS = 1 if ENABLE_PROMETHEUS: INSTALLED_APPS += ["django_prometheus"] MIDDLEWARE = ['django_prometheus.middleware.PrometheusBeforeMiddleware'] + MIDDLEWARE + \ - ['django_prometheus.middleware.PrometheusAfterMiddleware'] + ['django_prometheus.middleware.PrometheusAfterMiddleware', "jobs.middlewares.CustomMiddleware"] MIDDLEWARE.append("jobs.middlewares.CustomMiddleware") + MIDDLEWARE.append("jobs.middlewares.ResponseTimeMiddleware") + MIDDLEWARE.append("jobs.middlewares.ErrorTrackingMiddleware") diff --git a/jobsapp/metrics.py b/jobsapp/metrics.py index 11b4c76..eb098a0 100644 --- a/jobsapp/metrics.py +++ b/jobsapp/metrics.py @@ -1,4 +1,4 @@ -from prometheus_client import Counter, Enum, Gauge, Info, Summary +from prometheus_client import Counter, Enum, Gauge, Histogram, Info, Summary info = Info(name="app", documentation="Information about the application") info.info({"version": "1.0", "language": "python", "framework": "django"}) @@ -13,3 +13,15 @@ documentation="The last time when user was active.", labelnames=["user"], ) + +response_time_histogram = Histogram( + name='app_response_time_seconds', + documentation='Response time for requests', + labelnames=['method', 'endpoint'] +) + +error_rates_counter = Counter( + name='app_error_rates_total', + documentation='The total number of errors', + labelnames=['status_code', 'endpoint'] +) diff --git a/provisioning/grafana/dashboards/app-dashboard.json b/provisioning/grafana/dashboards/app-dashboard.json new file mode 100644 index 0000000..5783445 --- /dev/null +++ b/provisioning/grafana/dashboards/app-dashboard.json @@ -0,0 +1,1004 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 1, + "iteration": 1648538396345, + "links": [], + "panels": [ + { + "cacheTimeout": null, + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 4, + "w": 4, + "x": 0, + "y": 0 + }, + "id": 2, + "links": [], + "pageSize": null, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "alias": "", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "framework", + "thresholds": [], + "type": "string", + "unit": "short" + }, + { + "alias": "", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 1, + "mappingType": 1, + "pattern": "version", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "language", + "thresholds": [], + "type": "string", + "unit": "short" + }, + { + "alias": "", + "align": "right", + "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": "hidden", + "unit": "short" + } + ], + "targets": [ + { + "expr": "app_info", + "format": "table", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "App info", + "transform": "table", + "type": "table" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": null, + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 3, + "x": 4, + "y": 0 + }, + "id": 4, + "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, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "expr": "sum(app_requests_total{method=\"GET\", user=~\"$user\", endpoint=~\"$endpoint\"})", + "format": "time_series", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Total \"GET\"", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "first" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": null, + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 3, + "x": 7, + "y": 0 + }, + "id": 17, + "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, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "expr": "sum(app_requests_total{method=\"POST\", user=~\"$user\", endpoint=~\"$endpoint\"})", + "format": "time_series", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Total \"POST\"", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "first" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": null, + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 3, + "x": 10, + "y": 0 + }, + "id": 16, + "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, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "expr": "sum(app_requests_total{method=\"PATCH\", user=~\"$user\", endpoint=~\"$endpoint\"})", + "format": "time_series", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Total \"PATCH\"", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "first" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 12, + "w": 11, + "x": 13, + "y": 0 + }, + "hiddenSeries": false, + "id": 11, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "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": "rate(app_coupon_create_time_seconds_sum[1m])/rate(app_coupon_create_time_seconds_count[1m])", + "format": "time_series", + "instant": false, + "interval": "", + "legendFormat": "time", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Coupon creating time", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "s", + "label": "Time", + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 8, + "w": 13, + "x": 0, + "y": 4 + }, + "id": 14, + "pageSize": null, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "alias": "", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "/__name__|instance|job/", + "thresholds": [], + "type": "hidden", + "unit": "short" + }, + { + "alias": "Total", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "Method", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "method", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "User", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "user", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "Endpoint", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "endpoint", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "", + "align": "left", + "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": "short" + } + ], + "targets": [ + { + "expr": "app_requests_total{user=~\"$user\", method=~\"$method\", endpoint=~\"$endpoint\"}", + "format": "table", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "API calls", + "transform": "table", + "type": "table" + }, + { + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 8, + "w": 13, + "x": 0, + "y": 12 + }, + "id": 15, + "pageSize": null, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "alias": "", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "/__name__|instance|job|method/", + "thresholds": [], + "type": "hidden", + "unit": "short" + }, + { + "alias": "When", + "align": "right", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value", + "thresholds": [], + "type": "number", + "unit": "dateTimeAsIso" + }, + { + "alias": "User", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "user", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "", + "align": "left", + "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": "short" + } + ], + "targets": [ + { + "expr": "app_last_user_activity_time_seconds{user=~\"$user\"}*1000", + "format": "table", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Last activity", + "transform": "table", + "type": "table" + }, + { + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 8, + "w": 11, + "x": 13, + "y": 12 + }, + "id": 18, + "pageSize": null, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "alias": "", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "/__name__|instance|job/", + "thresholds": [], + "type": "hidden", + "unit": "short" + }, + { + "alias": "Status", + "align": "center", + "colorMode": "cell", + "colors": [ + "rgba(245, 54, 54, 0)", + "rgba(50, 172, 45, 0.97)", + "rgba(245, 54, 54, 0.9)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value", + "thresholds": [ + "0", + "1" + ], + "type": "string", + "unit": "short", + "valueMaps": [ + { + "text": "Success", + "value": "0" + }, + { + "text": "Error", + "value": "1" + } + ] + }, + { + "alias": "Method", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "method", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "User", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "user", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "Endpoint", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "endpoint", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "alias": "", + "align": "left", + "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": "short" + } + ], + "targets": [ + { + "expr": "sum(app_coupon_create_last_status{app_coupon_create_last_status=\"error\", user=~\"$user\"}) by (user)", + "format": "table", + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Coupon create last status", + "transform": "table", + "type": "table" + } + ], + "refresh": "30s", + "schemaVersion": 22, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "allValue": null, + "current": { + "text": "batman", + "value": [ + "batman" + ] + }, + "datasource": "Prometheus", + "definition": "label_values(user)", + "hide": 0, + "includeAll": true, + "index": -1, + "label": "User", + "multi": true, + "name": "user", + "options": [], + "query": "label_values(user)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": null, + "current": { + "text": "All", + "value": [ + "$__all" + ] + }, + "datasource": "Prometheus", + "definition": "label_values(method)", + "hide": 0, + "includeAll": true, + "index": -1, + "label": "Method", + "multi": true, + "name": "method", + "options": [], + "query": "label_values(method)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": null, + "current": { + "text": "All", + "value": [ + "$__all" + ] + }, + "datasource": "Prometheus", + "definition": "label_values(endpoint)", + "hide": 0, + "includeAll": true, + "index": -1, + "label": "Endpoint", + "multi": true, + "name": "endpoint", + "options": [], + "query": "label_values(endpoint)", + "refresh": 1, + "regex": "/^(?!catalog)/", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + } + ] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "", + "title": "Web App", + "uid": "8Q_jQC_Mk", + "variables": { + "list": [] + }, + "version": 1 +} \ No newline at end of file diff --git a/provisioning/grafana/dashboards/dashboard.yaml b/provisioning/grafana/dashboards/dashboard.yaml new file mode 100644 index 0000000..f49adfe --- /dev/null +++ b/provisioning/grafana/dashboards/dashboard.yaml @@ -0,0 +1,6 @@ +apiVersion: 1 + +providers: + - type: file + options: + path: /etc/grafana/provisioning/dashboards \ No newline at end of file diff --git a/provisioning/grafana/dashboards/device-dashboard.json b/provisioning/grafana/dashboards/device-dashboard.json new file mode 100644 index 0000000..586bee7 --- /dev/null +++ b/provisioning/grafana/dashboards/device-dashboard.json @@ -0,0 +1,1268 @@ +{ + "annotations": { + "list": [ + { + "$$hashKey": "object:20", + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "description": "", + "editable": true, + "gnetId": 1860, + "graphTooltip": 0, + "iteration": 1619352497626, + "links": [ + { + "icon": "external link", + "includeVars": false, + "tags": [ + "exporter-shared", + "exporter-vps" + ], + "targetBlank": false, + "type": "dashboards" + } + ], + "panels": [ + { + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 3, + "w": 5, + "x": 0, + "y": 0 + }, + "id": 312, + "pageSize": null, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden", + "unit": "dateTimeAsIso" + }, + { + "alias": "RAM", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value #A", + "thresholds": [], + "type": "number", + "unit": "bytes" + }, + { + "alias": "SWAP", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value #B", + "thresholds": [], + "type": "number", + "unit": "bytes" + }, + { + "alias": "CPU", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value #C", + "thresholds": [], + "type": "number", + "unit": "none" + }, + { + "alias": "Uptime", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value #D", + "thresholds": [], + "type": "number", + "unit": "s" + }, + { + "alias": "Root FS", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value #E", + "thresholds": [], + "type": "number", + "unit": "bytes" + }, + { + "alias": "Disk", + "align": "center", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 0, + "mappingType": 1, + "pattern": "Value #F", + "thresholds": [], + "type": "number", + "unit": "bytes" + } + ], + "targets": [ + { + "expr": "count(count(node_cpu_seconds_total{instance=~\"$instance\",job=~\"$job\"}) by (cpu))", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "C" + }, + { + "expr": "sum(node_filesystem_size_bytes{instance=~\"$instance\",job=~\"$job\", fstype=~\"ext4\"})", + "format": "table", + "hide": true, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "F" + }, + { + "expr": "sum(node_memory_MemTotal_bytes{instance=~\"$instance\",job=~\"$job\"})", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + }, + { + "expr": "sum(node_memory_SwapTotal_bytes{instance=~\"$instance\",job=~\"$job\"})", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "B" + }, + { + "expr": "sum(node_time_seconds{instance=~\"$instance\",job=~\"$job\"} - node_boot_time_seconds{instance=~\"$instance\",job=~\"$job\"})", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "D" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Machine Info", + "transform": "table", + "type": "table" + }, + { + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 3, + "w": 3, + "x": 5, + "y": 0 + }, + "id": 313, + "pageSize": null, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "alias": "1m", + "align": "center", + "colorMode": "value", + "colors": [ + "rgb(255, 255, 255)", + "rgba(237, 129, 40, 0.89)", + "rgba(245, 54, 54, 0.9)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "Value #A", + "thresholds": [ + "8", + "10" + ], + "type": "number", + "unit": "short" + }, + { + "alias": "5m", + "align": "center", + "colorMode": "value", + "colors": [ + "rgb(255, 255, 255)", + "rgba(237, 129, 40, 0.89)", + "rgba(245, 54, 54, 0.9)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "Value #B", + "thresholds": [ + "8", + "10" + ], + "type": "number", + "unit": "short" + }, + { + "alias": "15m", + "align": "center", + "colorMode": "value", + "colors": [ + "rgb(255, 255, 255)", + "rgba(237, 129, 40, 0.89)", + "rgba(245, 54, 54, 0.9)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "Value #C", + "thresholds": [ + "8", + "10" + ], + "type": "number", + "unit": "short" + } + ], + "targets": [ + { + "expr": "sum(node_load1{instance=~\"$instance\",job=~\"$job\"})", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + }, + { + "expr": "sum(node_load5{instance=~\"$instance\",job=~\"$job\"})", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "B" + }, + { + "expr": "sum(node_load15{instance=~\"$instance\",job=~\"$job\"})", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "C" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Sys Load", + "transform": "table", + "type": "table" + }, + { + "columns": [], + "datasource": null, + "fontSize": "100%", + "gridPos": { + "h": 3, + "w": 4, + "x": 8, + "y": 0 + }, + "id": 310, + "pageSize": null, + "showHeader": true, + "sort": { + "col": 1, + "desc": false + }, + "styles": [ + { + "$$hashKey": "object:76", + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "$$hashKey": "object:77", + "alias": "Device", + "align": "auto", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "device", + "thresholds": [], + "type": "string", + "unit": "short" + }, + { + "$$hashKey": "object:82", + "alias": "Usage", + "align": "center", + "colorMode": "cell", + "colors": [ + "rgba(163, 173, 163, 0)", + "rgba(237, 129, 40, 0.89)", + "rgba(245, 54, 54, 0.9)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 1, + "mappingType": 1, + "pattern": "Value", + "thresholds": [ + "80", + "90" + ], + "type": "number", + "unit": "percent" + } + ], + "targets": [ + { + "expr": "100 - (( sum(node_filesystem_avail_bytes{instance=~\"$instance\",job=~\"$job\", fstype=~\"ext4|ext3\"}) by (device) * 100) / sum(node_filesystem_size_bytes{instance=~\"$instance\",job=~\"$job\", fstype=~\"ext4|ext3\"}) by (device))", + "format": "table", + "hide": false, + "instant": true, + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Disk Usage", + "transform": "table", + "type": "table" + }, + { + "cacheTimeout": null, + "datasource": "Prometheus", + "description": "Busy state of all CPU cores together", + "gridPos": { + "h": 3, + "w": 3, + "x": 12, + "y": 0 + }, + "id": 20, + "links": [], + "options": { + "fieldOptions": { + "calcs": [ + "lastNotNull" + ], + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "max": 100, + "min": 0, + "nullValueMode": "null", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(50, 172, 45, 0.97)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 85 + }, + { + "color": "rgba(245, 54, 54, 0.9)", + "value": 95 + } + ] + }, + "unit": "percent" + }, + "overrides": [], + "values": false + }, + "orientation": "horizontal", + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "6.7.4", + "targets": [ + { + "expr": "(((count(count(node_cpu_seconds_total{instance=~\"$instance\",job=~\"$job\"}) by (cpu))) - avg(sum by (mode)(irate(node_cpu_seconds_total{mode='idle',instance=~\"$instance\",job=~\"$job\"}[5m])))) * 100) / count(count(node_cpu_seconds_total{instance=~\"$instance\",job=~\"$job\"}) by (cpu))", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "", + "refId": "A", + "step": 900 + } + ], + "title": "CPU Busy", + "type": "gauge" + }, + { + "cacheTimeout": null, + "datasource": "Prometheus", + "description": "Busy state of all CPU cores together (5 min average)", + "gridPos": { + "h": 3, + "w": 3, + "x": 15, + "y": 0 + }, + "id": 155, + "links": [], + "options": { + "fieldOptions": { + "calcs": [ + "lastNotNull" + ], + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "max": 100, + "min": 0, + "nullValueMode": "null", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(50, 172, 45, 0.97)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 85 + }, + { + "color": "rgba(245, 54, 54, 0.9)", + "value": 95 + } + ] + }, + "unit": "percent" + }, + "overrides": [], + "values": false + }, + "orientation": "horizontal", + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "6.7.4", + "targets": [ + { + "expr": "avg(node_load5{instance=~\"$instance\",job=~\"$job\"}) / count(count(node_cpu_seconds_total{instance=~\"$instance\",job=~\"$job\"}) by (cpu)) * 100", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "", + "refId": "A", + "step": 900 + } + ], + "title": "Sys Load (5m avg)", + "type": "gauge" + }, + { + "cacheTimeout": null, + "datasource": "Prometheus", + "description": "Non available RAM memory", + "gridPos": { + "h": 3, + "w": 3, + "x": 18, + "y": 0 + }, + "hideTimeOverride": false, + "id": 16, + "links": [], + "options": { + "fieldOptions": { + "calcs": [ + "lastNotNull" + ], + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 0, + "mappings": [], + "max": 100, + "min": 0, + "nullValueMode": "null", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(50, 172, 45, 0.97)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 80 + }, + { + "color": "rgba(245, 54, 54, 0.9)", + "value": 90 + } + ] + }, + "unit": "percent" + }, + "overrides": [], + "values": false + }, + "orientation": "horizontal", + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "6.7.4", + "targets": [ + { + "expr": "((node_memory_MemTotal_bytes{instance=~\"$instance\",job=~\"$job\"} - node_memory_MemFree_bytes{instance=~\"$instance\",job=~\"$job\"}) / (node_memory_MemTotal_bytes{instance=~\"$instance\",job=~\"$job\"} )) * 100", + "format": "time_series", + "hide": true, + "interval": "", + "intervalFactor": 1, + "legendFormat": "", + "refId": "A", + "step": 900 + }, + { + "expr": "100 - ((node_memory_MemAvailable_bytes{instance=~\"$instance\",job=~\"$job\"} * 100) / node_memory_MemTotal_bytes{instance=~\"$instance\",job=~\"$job\"})", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "", + "refId": "B", + "step": 900 + } + ], + "title": "RAM Used", + "type": "gauge" + }, + { + "cacheTimeout": null, + "datasource": "Prometheus", + "description": "Used Swap", + "gridPos": { + "h": 3, + "w": 3, + "x": 21, + "y": 0 + }, + "id": 21, + "links": [], + "options": { + "fieldOptions": { + "calcs": [ + "lastNotNull" + ], + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "max": 100, + "min": 0, + "nullValueMode": "null", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(50, 172, 45, 0.97)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 10 + }, + { + "color": "rgba(245, 54, 54, 0.9)", + "value": 25 + } + ] + }, + "unit": "percent" + }, + "overrides": [], + "values": false + }, + "orientation": "horizontal", + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "6.7.4", + "targets": [ + { + "expr": "((node_memory_SwapTotal_bytes{instance=~\"$instance\",job=~\"$job\"} - node_memory_SwapFree_bytes{instance=~\"$instance\",job=~\"$job\"}) / (node_memory_SwapTotal_bytes{instance=~\"$instance\",job=~\"$job\"} )) * 100", + "interval": "", + "intervalFactor": 1, + "legendFormat": "", + "refId": "A", + "step": 900 + } + ], + "title": "SWAP Used", + "type": "gauge" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "Prometheus", + "fill": 2, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 8, + "x": 0, + "y": 3 + }, + "hiddenSeries": false, + "id": 7, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "maxPerRow": 6, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "repeat": null, + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "node_load1{instance=~\"$instance\",job=~\"$job\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 4, + "legendFormat": "Load 1m", + "refId": "A", + "step": 480 + }, + { + "expr": "node_load5{instance=~\"$instance\",job=~\"$job\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 4, + "legendFormat": "Load 5m", + "refId": "B", + "step": 480 + }, + { + "expr": "node_load15{instance=~\"$instance\",job=~\"$job\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 4, + "legendFormat": "Load 15m", + "refId": "C", + "step": 480 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "System Load", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": "", + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": { + "n113.domenomania.pl": "dark-green", + "n113.domenomania.pl:9100": "dark-green", + "n116.domenomania.pl": "semi-dark-orange", + "n118.domenomania.pl": "dark-blue", + "n118.domenomania.pl:9100": "dark-blue", + "n123.domenomania.pl": "semi-dark-purple", + "n123.domenomania.pl:9100": "dark-purple", + "n124.domenomania.pl": "dark-red", + "n124.domenomania.pl:9100": "dark-red" + }, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "Prometheus", + "fill": 2, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 8, + "x": 8, + "y": 3 + }, + "hiddenSeries": false, + "id": 315, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "maxPerRow": 6, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "(((count(count(node_cpu_seconds_total{instance=~\"$instance\",job=~\"$job\"}) by (instance, cpu)) by (instance)) - sum(sum(irate(node_cpu_seconds_total{mode='idle',instance=~\"$instance\",job=~\"$job\"}[5m])) by (mode, instance)) by (instance) ) * 100) / count(count(node_cpu_seconds_total{instance=~\"$instance\",job=~\"$job\"}) by (instance, cpu)) by (instance)", + "format": "time_series", + "interval": "", + "intervalFactor": 4, + "legendFormat": "Usage", + "refId": "A", + "step": 480 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "CPU", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "percent", + "label": "", + "logBase": 1, + "max": "100", + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": { + "n113.domenomania.pl": "dark-green", + "n113.domenomania.pl:9100": "dark-green", + "n116.domenomania.pl": "semi-dark-orange", + "n118.domenomania.pl": "dark-blue", + "n118.domenomania.pl:9100": "dark-blue", + "n123.domenomania.pl": "semi-dark-purple", + "n123.domenomania.pl:9100": "dark-purple", + "n124.domenomania.pl": "dark-red", + "n124.domenomania.pl:9100": "dark-red" + }, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "Prometheus", + "fill": 2, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 8, + "x": 16, + "y": 3 + }, + "hiddenSeries": false, + "id": 317, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "maxPerRow": 6, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*Limit*./", + "fill": 0 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "node_memory_MemTotal_bytes{instance=~\"$instance\",job=~\"$job\"} - node_memory_MemAvailable_bytes{instance=~\"$instance\",job=~\"$job\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 4, + "legendFormat": "Usage", + "refId": "A", + "step": 480 + }, + { + "expr": "node_memory_MemTotal_bytes{instance=~\"$instance\",job=~\"$job\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 4, + "legendFormat": "Limit", + "refId": "B", + "step": 480 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Memory", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "bytes", + "label": "", + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": { + "receive_packets_eth0": "#7EB26D", + "receive_packets_lo": "#E24D42", + "transmit_packets_eth0": "#7EB26D", + "transmit_packets_lo": "#E24D42" + }, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "Prometheus", + "fill": 4, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 8, + "x": 0, + "y": 12 + }, + "hiddenSeries": false, + "id": 84, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*Trans.*/", + "transform": "negative-Y" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "irate(node_network_receive_bytes_total{instance=~\"$instance\",job=~\"$job\"}[5m])*8", + "format": "time_series", + "interval": "", + "intervalFactor": 2, + "legendFormat": "{{device}} - Receive", + "refId": "A", + "step": 240 + }, + { + "expr": "irate(node_network_transmit_bytes_total{instance=~\"$instance\",job=~\"$job\"}[5m])*8", + "format": "time_series", + "interval": "", + "intervalFactor": 2, + "legendFormat": "{{device}} - Transmit", + "refId": "B", + "step": 240 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Network Traffic", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "bps", + "label": "bits out (-) / in (+)", + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + } + ], + "refresh": "30s", + "schemaVersion": 22, + "style": "dark", + "tags": [ + "linux" + ], + "templating": { + "list": [ + { + "allValue": null, + "current": { + "text": "node-exporter", + "value": "node-exporter" + }, + "datasource": "Prometheus", + "definition": "label_values(node_uname_info, job)", + "hide": 0, + "includeAll": false, + "index": -1, + "label": "Job", + "multi": false, + "name": "job", + "options": [], + "query": "label_values(node_uname_info, job)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": null, + "current": { + "text": "node-exporter:9100", + "value": "node-exporter:9100" + }, + "datasource": "Prometheus", + "definition": "label_values({job=~\"$job\"}, instance)", + "hide": 0, + "includeAll": false, + "index": -1, + "label": "Instance", + "multi": false, + "name": "instance", + "options": [], + "query": "label_values({job=~\"$job\"}, instance)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + } + ] + }, + "time": { + "from": "now-5m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ] + }, + "timezone": "browser", + "title": "Device", + "uid": "rYddafadlPWk", + "variables": { + "list": [] + }, + "version": 1 +} \ No newline at end of file diff --git a/provisioning/grafana/datasources/datasource.yaml b/provisioning/grafana/datasources/datasource.yaml new file mode 100644 index 0000000..425772f --- /dev/null +++ b/provisioning/grafana/datasources/datasource.yaml @@ -0,0 +1,11 @@ +apiVersion: 1 + +datasources: + - name: Prometheus + type: prometheus + access: proxy + orgId: 1 + url: http://prometheus:9090/ + isDefault: true + version: 1 + editable: false diff --git a/provisioning/prometheus/prometheus.yml b/provisioning/prometheus/prometheus.yml new file mode 100644 index 0000000..aa76134 --- /dev/null +++ b/provisioning/prometheus/prometheus.yml @@ -0,0 +1,24 @@ +global: + scrape_interval: 10s + +alerting: + alertmanagers: + - static_configs: + - targets: + - alertmanager:9093 + +rule_files: +- /etc/prometheus/rules.yml + +scrape_configs: +- job_name: web-apps + scrape_interval: 10s + static_configs: + - targets: + - web:8000 + +- job_name: node-exporter + static_configs: + - targets: + - node-exporter:9100 + diff --git a/provisioning/prometheus/rules.yml b/provisioning/prometheus/rules.yml new file mode 100644 index 0000000..099adb5 --- /dev/null +++ b/provisioning/prometheus/rules.yml @@ -0,0 +1,9 @@ +groups: +- name: nodes + rules: + - alert: App server is down + expr: up{instance="app:8000"} == 0 + for: 1m + annotations: + description: App server is not running + summary: App server is down and not running \ No newline at end of file