From 09d6d43b89a8c87ee86afcaae9d9433ca0d55435 Mon Sep 17 00:00:00 2001 From: Kaviraj Date: Fri, 16 Oct 2020 13:58:00 +0200 Subject: [PATCH 1/6] feat(mixin): Add grafana mixins support for postgres exporter --- postgres_mixin/.gitignore | 3 + postgres_mixin/Makefile | 23 + postgres_mixin/README.md | 26 + postgres_mixin/alerts/alerts.yaml | 57 + .../dashboards/postgres-overview.json | 1321 +++++++++++++++++ postgres_mixin/go.mod | 3 + postgres_mixin/mixin.libsonnet | 13 + 7 files changed, 1446 insertions(+) create mode 100644 postgres_mixin/.gitignore create mode 100644 postgres_mixin/Makefile create mode 100644 postgres_mixin/README.md create mode 100644 postgres_mixin/alerts/alerts.yaml create mode 100644 postgres_mixin/dashboards/postgres-overview.json create mode 100644 postgres_mixin/go.mod create mode 100644 postgres_mixin/mixin.libsonnet diff --git a/postgres_mixin/.gitignore b/postgres_mixin/.gitignore new file mode 100644 index 000000000..97bf5f5c8 --- /dev/null +++ b/postgres_mixin/.gitignore @@ -0,0 +1,3 @@ +/alerts.yaml +/rules.yaml +dashboards_out diff --git a/postgres_mixin/Makefile b/postgres_mixin/Makefile new file mode 100644 index 000000000..f2643c2b7 --- /dev/null +++ b/postgres_mixin/Makefile @@ -0,0 +1,23 @@ +JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s + +default: build + +all: fmt lint build clean + +fmt: + find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ + xargs -n 1 -- $(JSONNET_FMT) -i + +lint: + find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ + while read f; do \ + $(JSONNET_FMT) "$$f" | diff -u "$$f" -; \ + done + + mixtool lint mixin.libsonnet + +build: + mixtool generate all mixin.libsonnet + +clean: + rm -rf dashboards_out alerts.yaml rules.yaml diff --git a/postgres_mixin/README.md b/postgres_mixin/README.md new file mode 100644 index 000000000..e5f12edf6 --- /dev/null +++ b/postgres_mixin/README.md @@ -0,0 +1,26 @@ +# Postgres Mixin + +_This is a work in progress. We aim for it to become a good role model for alerts +and dashboards eventually, but it is not quite there yet._ + +The Postgres Mixin is a set of configurable, reusable, and extensible alerts and +dashboards based on the metrics exported by the Postgres Exporter. The mixin creates +recording and alerting rules for Prometheus and suitable dashboard descriptions +for Grafana. + +To use them, you need to have `mixtool` and `jsonnetfmt` installed. If you +have a working Go development environment, it's easiest to run the following: +```bash +$ go get github.com/monitoring-mixins/mixtool/cmd/mixtool +$ go get github.com/google/go-jsonnet/cmd/jsonnetfmt +``` + +You can then build the Prometheus rules files `alerts.yaml` and +`rules.yaml` and a directory `dashboard_out` with the JSON dashboard files +for Grafana: +```bash +$ make build +``` + +For more advanced uses of mixins, see +https://github.com/monitoring-mixins/docs. diff --git a/postgres_mixin/alerts/alerts.yaml b/postgres_mixin/alerts/alerts.yaml new file mode 100644 index 000000000..ff3d75a7f --- /dev/null +++ b/postgres_mixin/alerts/alerts.yaml @@ -0,0 +1,57 @@ +--- +groups: + - name: PostgreSQL + rules: + - alert: PostgreSQLMaxConnectionsReached + expr: sum(pg_stat_activity_count) by (instance) >= sum(pg_settings_max_connections) by (instance) - sum(pg_settings_superuser_reserved_connections) by (instance) + for: 1m + labels: + severity: email + annotations: + summary: "{{ $labels.instance }} has maxed out Postgres connections." + description: "{{ $labels.instance }} is exceeding the currently configured maximum Postgres connection limit (current value: {{ $value }}s). Services may be degraded - please take immediate action (you probably need to increase max_connections in the Docker image and re-deploy." + + - alert: PostgreSQLHighConnections + expr: sum(pg_stat_activity_count) by (instance) > (sum(pg_settings_max_connections) by (instance) - sum(pg_settings_superuser_reserved_connections) by (instance)) * 0.8 + for: 10m + labels: + severity: email + annotations: + summary: "{{ $labels.instance }} is over 80% of max Postgres connections." + description: "{{ $labels.instance }} is exceeding 80% of the currently configured maximum Postgres connection limit (current value: {{ $value }}s). Please check utilization graphs and confirm if this is normal service growth, abuse or an otherwise temporary condition or if new resources need to be provisioned (or the limits increased, which is mostly likely)." + + - alert: PostgreSQLDown + expr: pg_up != 1 + for: 1m + labels: + severity: email + annotations: + summary: "PostgreSQL is not processing queries: {{ $labels.instance }}" + description: "{{ $labels.instance }} is rejecting query requests from the exporter, and thus probably not allowing DNS requests to work either. User services should not be effected provided at least 1 node is still alive." + + - alert: PostgreSQLSlowQueries + expr: avg(rate(pg_stat_activity_max_tx_duration{datname!~"template.*"}[2m])) by (datname) > 2 * 60 + for: 2m + labels: + severity: email + annotations: + summary: "PostgreSQL high number of slow on {{ $labels.cluster }} for database {{ $labels.datname }} " + description: "PostgreSQL high number of slow queries {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }} " + + - alert: PostgreSQLQPS + expr: avg(irate(pg_stat_database_xact_commit{datname!~"template.*"}[5m]) + irate(pg_stat_database_xact_rollback{datname!~"template.*"}[5m])) by (datname) > 10000 + for: 5m + labels: + severity: email + annotations: + summary: "PostgreSQL high number of queries per second {{ $labels.cluster }} for database {{ $labels.datname }}" + description: "PostgreSQL high number of queries per second on {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }}" + + - alert: PostgreSQLCacheHitRatio + expr: avg(rate(pg_stat_database_blks_hit{datname!~"template.*"}[5m]) / (rate(pg_stat_database_blks_hit{datname!~"template.*"}[5m]) + rate(pg_stat_database_blks_read{datname!~"template.*"}[5m]))) by (datname) < 0.98 + for: 5m + labels: + severity: email + annotations: + summary: "PostgreSQL low cache hit rate on {{ $labels.cluster }} for database {{ $labels.datname }}" + description: "PostgreSQL low on cache hit rate on {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }}" diff --git a/postgres_mixin/dashboards/postgres-overview.json b/postgres_mixin/dashboards/postgres-overview.json new file mode 100644 index 000000000..376f8dd2c --- /dev/null +++ b/postgres_mixin/dashboards/postgres-overview.json @@ -0,0 +1,1321 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "5.2.0-pre1" + }, + { + "type": "panel", + "id": "graph", + "name": "Graph", + "version": "5.0.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "5.0.0" + }, + { + "type": "panel", + "id": "singlestat", + "name": "Singlestat", + "version": "5.0.0" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "description": "Performance metrics for Postgres", + "editable": true, + "gnetId": 455, + "graphTooltip": 0, + "id": null, + "iteration": 1534108418743, + "links": [], + "panels": [ + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_PROMETHEUS}", + "editable": true, + "error": false, + "fill": 1, + "grid": {}, + "gridPos": { + "h": 7, + "w": 20, + "x": 0, + "y": 0 + }, + "id": 1, + "isNew": true, + "legend": { + "alignAsTable": true, + "avg": true, + "current": false, + "max": true, + "min": true, + "rightSide": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "connected", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "fetched", + "dsType": "prometheus", + "expr": "sum(irate(pg_stat_database_tup_fetched{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "fetched", + "measurement": "postgresql", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "tup_fetched" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + } + ] + ], + "step": 120, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "fetched", + "dsType": "prometheus", + "expr": "sum(irate(pg_stat_database_tup_returned{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "returned", + "measurement": "postgresql", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "tup_fetched" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + } + ] + ], + "step": 120, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "fetched", + "dsType": "prometheus", + "expr": "sum(irate(pg_stat_database_tup_inserted{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "inserted", + "measurement": "postgresql", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "tup_fetched" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + } + ] + ], + "step": 120, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "fetched", + "dsType": "prometheus", + "expr": "sum(irate(pg_stat_database_tup_updated{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "updated", + "measurement": "postgresql", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "tup_fetched" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + } + ] + ], + "step": 120, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "fetched", + "dsType": "prometheus", + "expr": "sum(irate(pg_stat_database_tup_deleted{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "deleted", + "measurement": "postgresql", + "policy": "default", + "refId": "E", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "tup_fetched" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + } + ] + ], + "step": 120, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Rows", + "tooltip": { + "msResolution": true, + "shared": true, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ] + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "datasource": "${DS_PROMETHEUS}", + "decimals": 0, + "editable": true, + "error": false, + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 3, + "w": 4, + "x": 20, + "y": 0 + }, + "height": "55px", + "id": 11, + "interval": null, + "isNew": true, + "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": true, + "lineColor": "rgb(31, 120, 193)", + "show": true + }, + "tableColumn": "", + "targets": [ + { + "dsType": "prometheus", + "expr": "sum(irate(pg_stat_database_xact_commit{datname=~\"$db\",instance=~\"$host\"}[5m])) + sum(irate(pg_stat_database_xact_rollback{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "measurement": "postgresql", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "xact_commit" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + } + ] + ], + "step": 1800, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + } + ], + "thresholds": "", + "title": "QPS", + "transparent": true, + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "avg" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_PROMETHEUS}", + "decimals": 1, + "editable": true, + "error": false, + "fill": 1, + "grid": {}, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 7 + }, + "id": 2, + "isNew": true, + "legend": { + "alignAsTable": true, + "avg": true, + "current": false, + "hideZero": true, + "max": true, + "min": true, + "rightSide": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "connected", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "Buffers Allocated", + "dsType": "prometheus", + "expr": "irate(pg_stat_bgwriter_buffers_alloc{instance='$host'}[5m])", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "buffers_alloc", + "measurement": "postgresql", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "buffers_alloc" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "Buffers Allocated", + "dsType": "prometheus", + "expr": "irate(pg_stat_bgwriter_buffers_backend_fsync{instance='$host'}[5m])", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "buffers_backend_fsync", + "measurement": "postgresql", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "buffers_alloc" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "Buffers Allocated", + "dsType": "prometheus", + "expr": "irate(pg_stat_bgwriter_buffers_backend{instance='$host'}[5m])", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "buffers_backend", + "measurement": "postgresql", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "buffers_alloc" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "Buffers Allocated", + "dsType": "prometheus", + "expr": "irate(pg_stat_bgwriter_buffers_clean{instance='$host'}[5m])", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "buffers_clean", + "measurement": "postgresql", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "buffers_alloc" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "Buffers Allocated", + "dsType": "prometheus", + "expr": "irate(pg_stat_bgwriter_buffers_checkpoint{instance='$host'}[5m])", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "buffers_checkpoint", + "measurement": "postgresql", + "policy": "default", + "refId": "E", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "buffers_alloc" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Buffers", + "tooltip": { + "msResolution": false, + "shared": true, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": 0, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ] + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_PROMETHEUS}", + "editable": true, + "error": false, + "fill": 1, + "grid": {}, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 7 + }, + "id": 3, + "isNew": true, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "links": [], + "nullPointMode": "connected", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "conflicts", + "dsType": "prometheus", + "expr": "sum(rate(pg_stat_database_deadlocks{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "deadlocks", + "measurement": "postgresql", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "conflicts" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + }, + { + "alias": "deadlocks", + "dsType": "prometheus", + "expr": "sum(rate(pg_stat_database_conflicts{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "format": "time_series", + "groupBy": [ + { + "params": [ + "$interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "intervalFactor": 2, + "legendFormat": "conflicts", + "measurement": "postgresql", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "deadlocks" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [], + "type": "difference" + } + ] + ], + "step": 240, + "tags": [ + { + "key": "host", + "operator": "=~", + "value": "/^$host$/" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Conflicts/Deadlocks", + "tooltip": { + "msResolution": false, + "shared": true, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": 0, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ] + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_PROMETHEUS}", + "editable": true, + "error": false, + "fill": 1, + "grid": {}, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 14 + }, + "id": 12, + "isNew": true, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "links": [], + "nullPointMode": "connected", + "percentage": true, + "pointradius": 1, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "sum(pg_stat_database_blks_hit{datname=~\"$db\",instance=~\"$host\"}) / (sum(pg_stat_database_blks_hit{datname=~\"$db\",instance=~\"$host\"}) + sum(pg_stat_database_blks_read{datname=~\"$db\",instance=~\"$host\"}))", + "format": "time_series", + "intervalFactor": 2, + "legendFormat": "cache hit rate", + "refId": "A", + "step": 240 + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Cache hit ratio", + "tooltip": { + "msResolution": false, + "shared": true, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "percentunit", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ] + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_PROMETHEUS}", + "editable": true, + "error": false, + "fill": 1, + "grid": {}, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 14 + }, + "id": 13, + "isNew": true, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "links": [], + "nullPointMode": "connected", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "pg_stat_database_numbackends{datname=~\"$db\",instance=~\"$host\"}", + "format": "time_series", + "intervalFactor": 2, + "legendFormat": "{{__name__}}", + "refId": "A", + "step": 240 + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Number of active connections", + "tooltip": { + "msResolution": false, + "shared": true, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ] + } + ], + "refresh": false, + "schemaVersion": 16, + "style": "dark", + "tags": [ + "postgres" + ], + "templating": { + "list": [ + { + "allValue": ".*", + "current": {}, + "datasource": "${DS_PROMETHEUS}", + "hide": 0, + "includeAll": true, + "label": null, + "multi": false, + "name": "host", + "options": [], + "query": "label_values(up{job=~\"postgres.*\"},instance)", + "refresh": 1, + "regex": "", + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": ".*", + "current": {}, + "datasource": "${DS_PROMETHEUS}", + "hide": 0, + "includeAll": true, + "label": "db", + "multi": false, + "name": "db", + "options": [], + "query": "label_values(pg_stat_database_tup_fetched{instance=~\"$host\",datname!~\"template.*|postgres\"},datname)", + "refresh": 1, + "regex": "", + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + } + ] + }, + "time": { + "from": "now-1h", + "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": "Postgres Overview", + "uid": "wGgaPlciz", + "version": 4 +} \ No newline at end of file diff --git a/postgres_mixin/go.mod b/postgres_mixin/go.mod new file mode 100644 index 000000000..fa5e20579 --- /dev/null +++ b/postgres_mixin/go.mod @@ -0,0 +1,3 @@ +module github.com/wrouesnel/postgres_exporter/postgres_mixin + +go 1.15 diff --git a/postgres_mixin/mixin.libsonnet b/postgres_mixin/mixin.libsonnet new file mode 100644 index 000000000..98c7ea7d1 --- /dev/null +++ b/postgres_mixin/mixin.libsonnet @@ -0,0 +1,13 @@ +{ + grafanaDashboards: { + 'postgres-overview.json': (import 'dashboards/postgres-overview.json'), + }, + + // Helper function to ensure that we don't override other rules, by forcing + // the patching of the groups list, and not the overall rules object. + local importRules(rules) = { + groups+: std.native('parseYaml')(rules)[0].groups, + }, + + prometheusAlerts+: importRules(importstr 'alerts/alerts.yaml'), +} From fad1eda5d170e4e2912105b5d3bf17ac70485a70 Mon Sep 17 00:00:00 2001 From: Kaviraj Date: Tue, 20 Oct 2020 13:10:20 +0200 Subject: [PATCH 2/6] Add templating for job, instance and datasource --- .../dashboards/postgres-overview.json | 315 ++++++++++++------ 1 file changed, 216 insertions(+), 99 deletions(-) diff --git a/postgres_mixin/dashboards/postgres-overview.json b/postgres_mixin/dashboards/postgres-overview.json index 376f8dd2c..24b7bc92d 100644 --- a/postgres_mixin/dashboards/postgres-overview.json +++ b/postgres_mixin/dashboards/postgres-overview.json @@ -1,40 +1,4 @@ { - "__inputs": [ - { - "name": "DS_PROMETHEUS", - "label": "Prometheus", - "description": "", - "type": "datasource", - "pluginId": "prometheus", - "pluginName": "Prometheus" - } - ], - "__requires": [ - { - "type": "grafana", - "id": "grafana", - "name": "Grafana", - "version": "5.2.0-pre1" - }, - { - "type": "panel", - "id": "graph", - "name": "Graph", - "version": "5.0.0" - }, - { - "type": "datasource", - "id": "prometheus", - "name": "Prometheus", - "version": "5.0.0" - }, - { - "type": "panel", - "id": "singlestat", - "name": "Singlestat", - "version": "5.0.0" - } - ], "annotations": { "list": [ { @@ -52,8 +16,8 @@ "editable": true, "gnetId": 455, "graphTooltip": 0, - "id": null, - "iteration": 1534108418743, + "id": 1, + "iteration": 1603191461722, "links": [], "panels": [ { @@ -61,10 +25,17 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": "Postgres Overview", "editable": true, "error": false, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "grid": {}, "gridPos": { "h": 7, @@ -72,6 +43,7 @@ "x": 0, "y": 0 }, + "hiddenSeries": false, "id": 1, "isNew": true, "legend": { @@ -89,7 +61,11 @@ "linewidth": 1, "links": [], "nullPointMode": "connected", + "options": { + "alertThreshold": true + }, "percentage": false, + "pluginVersion": "7.2.1", "pointradius": 5, "points": false, "renderer": "flot", @@ -101,7 +77,7 @@ { "alias": "fetched", "dsType": "prometheus", - "expr": "sum(irate(pg_stat_database_tup_fetched{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(irate(pg_stat_database_tup_fetched{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -146,16 +122,16 @@ "step": 120, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "fetched", "dsType": "prometheus", - "expr": "sum(irate(pg_stat_database_tup_returned{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(irate(pg_stat_database_tup_returned{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -200,16 +176,16 @@ "step": 120, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "fetched", "dsType": "prometheus", - "expr": "sum(irate(pg_stat_database_tup_inserted{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(irate(pg_stat_database_tup_inserted{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -254,16 +230,16 @@ "step": 120, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "fetched", "dsType": "prometheus", - "expr": "sum(irate(pg_stat_database_tup_updated{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(irate(pg_stat_database_tup_updated{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -308,16 +284,16 @@ "step": 120, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "fetched", "dsType": "prometheus", - "expr": "sum(irate(pg_stat_database_tup_deleted{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(irate(pg_stat_database_tup_deleted{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -362,15 +338,16 @@ "step": 120, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] } ], "thresholds": [], "timeFrom": null, + "timeRegions": [], "timeShift": null, "title": "Rows", "tooltip": { @@ -404,7 +381,11 @@ "min": null, "show": true } - ] + ], + "yaxis": { + "align": false, + "alignLevel": null + } }, { "cacheTimeout": null, @@ -415,10 +396,16 @@ "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)" ], - "datasource": "${DS_PROMETHEUS}", + "datasource": "Postgres Overview", "decimals": 0, "editable": true, "error": false, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "format": "none", "gauge": { "maxValue": 100, @@ -473,7 +460,7 @@ "targets": [ { "dsType": "prometheus", - "expr": "sum(irate(pg_stat_database_xact_commit{datname=~\"$db\",instance=~\"$host\"}[5m])) + sum(irate(pg_stat_database_xact_rollback{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(irate(pg_stat_database_xact_commit{datname=~\"$db\",instance=~\"$instance\"}[5m])) + sum(irate(pg_stat_database_xact_rollback{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -517,9 +504,9 @@ "step": 1800, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] } @@ -543,11 +530,18 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": "Postgres Overview", "decimals": 1, "editable": true, "error": false, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "grid": {}, "gridPos": { "h": 7, @@ -555,6 +549,7 @@ "x": 0, "y": 7 }, + "hiddenSeries": false, "id": 2, "isNew": true, "legend": { @@ -573,7 +568,11 @@ "linewidth": 1, "links": [], "nullPointMode": "connected", + "options": { + "alertThreshold": true + }, "percentage": false, + "pluginVersion": "7.2.1", "pointradius": 5, "points": false, "renderer": "flot", @@ -585,7 +584,7 @@ { "alias": "Buffers Allocated", "dsType": "prometheus", - "expr": "irate(pg_stat_bgwriter_buffers_alloc{instance='$host'}[5m])", + "expr": "irate(pg_stat_bgwriter_buffers_alloc{instance='$instance'}[5m])", "format": "time_series", "groupBy": [ { @@ -628,16 +627,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "Buffers Allocated", "dsType": "prometheus", - "expr": "irate(pg_stat_bgwriter_buffers_backend_fsync{instance='$host'}[5m])", + "expr": "irate(pg_stat_bgwriter_buffers_backend_fsync{instance='$instance'}[5m])", "format": "time_series", "groupBy": [ { @@ -680,16 +679,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "Buffers Allocated", "dsType": "prometheus", - "expr": "irate(pg_stat_bgwriter_buffers_backend{instance='$host'}[5m])", + "expr": "irate(pg_stat_bgwriter_buffers_backend{instance='$instance'}[5m])", "format": "time_series", "groupBy": [ { @@ -732,16 +731,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "Buffers Allocated", "dsType": "prometheus", - "expr": "irate(pg_stat_bgwriter_buffers_clean{instance='$host'}[5m])", + "expr": "irate(pg_stat_bgwriter_buffers_clean{instance='$instance'}[5m])", "format": "time_series", "groupBy": [ { @@ -784,16 +783,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "Buffers Allocated", "dsType": "prometheus", - "expr": "irate(pg_stat_bgwriter_buffers_checkpoint{instance='$host'}[5m])", + "expr": "irate(pg_stat_bgwriter_buffers_checkpoint{instance='$instance'}[5m])", "format": "time_series", "groupBy": [ { @@ -836,15 +835,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] } ], "thresholds": [], "timeFrom": null, + "timeRegions": [], "timeShift": null, "title": "Buffers", "tooltip": { @@ -878,17 +878,28 @@ "min": null, "show": true } - ] + ], + "yaxis": { + "align": false, + "alignLevel": null + } }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": "Postgres Overview", "editable": true, "error": false, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "grid": {}, "gridPos": { "h": 7, @@ -896,6 +907,7 @@ "x": 12, "y": 7 }, + "hiddenSeries": false, "id": 3, "isNew": true, "legend": { @@ -911,7 +923,11 @@ "linewidth": 2, "links": [], "nullPointMode": "connected", + "options": { + "alertThreshold": true + }, "percentage": false, + "pluginVersion": "7.2.1", "pointradius": 5, "points": false, "renderer": "flot", @@ -923,7 +939,7 @@ { "alias": "conflicts", "dsType": "prometheus", - "expr": "sum(rate(pg_stat_database_deadlocks{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(rate(pg_stat_database_deadlocks{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -966,16 +982,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] }, { "alias": "deadlocks", "dsType": "prometheus", - "expr": "sum(rate(pg_stat_database_conflicts{datname=~\"$db\",instance=~\"$host\"}[5m]))", + "expr": "sum(rate(pg_stat_database_conflicts{datname=~\"$db\",instance=~\"$instance\"}[5m]))", "format": "time_series", "groupBy": [ { @@ -1018,15 +1034,16 @@ "step": 240, "tags": [ { - "key": "host", + "key": "instance", "operator": "=~", - "value": "/^$host$/" + "value": "/^$instance$/" } ] } ], "thresholds": [], "timeFrom": null, + "timeRegions": [], "timeShift": null, "title": "Conflicts/Deadlocks", "tooltip": { @@ -1060,17 +1077,28 @@ "min": null, "show": true } - ] + ], + "yaxis": { + "align": false, + "alignLevel": null + } }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": "Postgres Overview", "editable": true, "error": false, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "grid": {}, "gridPos": { "h": 7, @@ -1078,6 +1106,7 @@ "x": 0, "y": 14 }, + "hiddenSeries": false, "id": 12, "isNew": true, "legend": { @@ -1093,7 +1122,11 @@ "linewidth": 2, "links": [], "nullPointMode": "connected", + "options": { + "alertThreshold": true + }, "percentage": true, + "pluginVersion": "7.2.1", "pointradius": 1, "points": false, "renderer": "flot", @@ -1103,7 +1136,7 @@ "steppedLine": false, "targets": [ { - "expr": "sum(pg_stat_database_blks_hit{datname=~\"$db\",instance=~\"$host\"}) / (sum(pg_stat_database_blks_hit{datname=~\"$db\",instance=~\"$host\"}) + sum(pg_stat_database_blks_read{datname=~\"$db\",instance=~\"$host\"}))", + "expr": "sum(pg_stat_database_blks_hit{datname=~\"$db\",instance=~\"$instance\"}) / (sum(pg_stat_database_blks_hit{datname=~\"$db\",instance=~\"$instance\"}) + sum(pg_stat_database_blks_read{datname=~\"$db\",instance=~\"$instance\"}))", "format": "time_series", "intervalFactor": 2, "legendFormat": "cache hit rate", @@ -1113,6 +1146,7 @@ ], "thresholds": [], "timeFrom": null, + "timeRegions": [], "timeShift": null, "title": "Cache hit ratio", "tooltip": { @@ -1146,17 +1180,28 @@ "min": null, "show": true } - ] + ], + "yaxis": { + "align": false, + "alignLevel": null + } }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": "Postgres Overview", "editable": true, "error": false, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "grid": {}, "gridPos": { "h": 7, @@ -1164,6 +1209,7 @@ "x": 12, "y": 14 }, + "hiddenSeries": false, "id": 13, "isNew": true, "legend": { @@ -1179,7 +1225,11 @@ "linewidth": 2, "links": [], "nullPointMode": "connected", + "options": { + "alertThreshold": true + }, "percentage": false, + "pluginVersion": "7.2.1", "pointradius": 5, "points": false, "renderer": "flot", @@ -1189,7 +1239,7 @@ "steppedLine": false, "targets": [ { - "expr": "pg_stat_database_numbackends{datname=~\"$db\",instance=~\"$host\"}", + "expr": "pg_stat_database_numbackends{datname=~\"$db\",instance=~\"$instance\"}", "format": "time_series", "intervalFactor": 2, "legendFormat": "{{__name__}}", @@ -1199,6 +1249,7 @@ ], "thresholds": [], "timeFrom": null, + "timeRegions": [], "timeShift": null, "title": "Number of active connections", "tooltip": { @@ -1232,11 +1283,15 @@ "min": null, "show": true } - ] + ], + "yaxis": { + "align": false, + "alignLevel": null + } } ], "refresh": false, - "schemaVersion": 16, + "schemaVersion": 26, "style": "dark", "tags": [ "postgres" @@ -1245,17 +1300,23 @@ "list": [ { "allValue": ".*", - "current": {}, - "datasource": "${DS_PROMETHEUS}", + "current": { + "selected": false, + "text": "All", + "value": "$__all" + }, + "datasource": "Postgres Overview", + "definition": "", "hide": 0, "includeAll": true, "label": null, "multi": false, - "name": "host", + "name": "instance", "options": [], "query": "label_values(up{job=~\"postgres.*\"},instance)", "refresh": 1, "regex": "", + "skipUrlSync": false, "sort": 0, "tagValuesQuery": "", "tags": [], @@ -1265,17 +1326,73 @@ }, { "allValue": ".*", - "current": {}, - "datasource": "${DS_PROMETHEUS}", + "current": { + "selected": false, + "text": "All", + "value": "$__all" + }, + "datasource": "Postgres Overview", + "definition": "label_values(pg_stat_database_tup_fetched{instance=~\"$instance\",datname!~\"template.*|postgres\"},datname)", "hide": 0, "includeAll": true, "label": "db", "multi": false, "name": "db", "options": [], - "query": "label_values(pg_stat_database_tup_fetched{instance=~\"$host\",datname!~\"template.*|postgres\"},datname)", + "query": "label_values(pg_stat_database_tup_fetched{instance=~\"$instance\",datname!~\"template.*|postgres\"},datname)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "current": { + "selected": false, + "text": "Postgres Overview", + "value": "Postgres Overview" + }, + "hide": 0, + "includeAll": false, + "label": "datasource", + "multi": false, + "name": "datasource", + "options": [], + "query": "prometheus", "refresh": 1, "regex": "", + "skipUrlSync": false, + "type": "datasource" + }, + { + "allValue": null, + "current": { + "selected": true, + "text": "postgres", + "value": "postgres" + }, + "datasource": "$datasource", + "definition": "label_values(pg_up, job)", + "hide": 0, + "includeAll": false, + "label": "job", + "multi": false, + "name": "job", + "options": [ + { + "selected": true, + "text": "postgres", + "value": "postgres" + } + ], + "query": "label_values(pg_up, job)", + "refresh": 0, + "regex": "", + "skipUrlSync": false, "sort": 0, "tagValuesQuery": "", "tags": [], @@ -1317,5 +1434,5 @@ "timezone": "browser", "title": "Postgres Overview", "uid": "wGgaPlciz", - "version": 4 -} \ No newline at end of file + "version": 5 +} From 6795cb28c82247eab6682a4d6426ad49c9436e11 Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Wed, 9 Dec 2020 17:12:25 +0100 Subject: [PATCH 3/6] Align Postgres mixin name. --- {postgres_mixin => postgres-mixin}/.gitignore | 0 {postgres_mixin => postgres-mixin}/Makefile | 0 {postgres_mixin => postgres-mixin}/README.md | 0 {postgres_mixin => postgres-mixin}/alerts/alerts.yaml | 0 .../dashboards/postgres-overview.json | 0 {postgres_mixin => postgres-mixin}/go.mod | 0 {postgres_mixin => postgres-mixin}/mixin.libsonnet | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename {postgres_mixin => postgres-mixin}/.gitignore (100%) rename {postgres_mixin => postgres-mixin}/Makefile (100%) rename {postgres_mixin => postgres-mixin}/README.md (100%) rename {postgres_mixin => postgres-mixin}/alerts/alerts.yaml (100%) rename {postgres_mixin => postgres-mixin}/dashboards/postgres-overview.json (100%) rename {postgres_mixin => postgres-mixin}/go.mod (100%) rename {postgres_mixin => postgres-mixin}/mixin.libsonnet (100%) diff --git a/postgres_mixin/.gitignore b/postgres-mixin/.gitignore similarity index 100% rename from postgres_mixin/.gitignore rename to postgres-mixin/.gitignore diff --git a/postgres_mixin/Makefile b/postgres-mixin/Makefile similarity index 100% rename from postgres_mixin/Makefile rename to postgres-mixin/Makefile diff --git a/postgres_mixin/README.md b/postgres-mixin/README.md similarity index 100% rename from postgres_mixin/README.md rename to postgres-mixin/README.md diff --git a/postgres_mixin/alerts/alerts.yaml b/postgres-mixin/alerts/alerts.yaml similarity index 100% rename from postgres_mixin/alerts/alerts.yaml rename to postgres-mixin/alerts/alerts.yaml diff --git a/postgres_mixin/dashboards/postgres-overview.json b/postgres-mixin/dashboards/postgres-overview.json similarity index 100% rename from postgres_mixin/dashboards/postgres-overview.json rename to postgres-mixin/dashboards/postgres-overview.json diff --git a/postgres_mixin/go.mod b/postgres-mixin/go.mod similarity index 100% rename from postgres_mixin/go.mod rename to postgres-mixin/go.mod diff --git a/postgres_mixin/mixin.libsonnet b/postgres-mixin/mixin.libsonnet similarity index 100% rename from postgres_mixin/mixin.libsonnet rename to postgres-mixin/mixin.libsonnet From 8dcb7dc64ffe06f732877ceaa70bd34b8ec06eac Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Wed, 9 Dec 2020 17:12:51 +0100 Subject: [PATCH 4/6] Remove unused files. --- postgres-mixin/Makefile | 23 ----------------------- postgres-mixin/go.mod | 3 --- 2 files changed, 26 deletions(-) delete mode 100644 postgres-mixin/Makefile delete mode 100644 postgres-mixin/go.mod diff --git a/postgres-mixin/Makefile b/postgres-mixin/Makefile deleted file mode 100644 index f2643c2b7..000000000 --- a/postgres-mixin/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s - -default: build - -all: fmt lint build clean - -fmt: - find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ - xargs -n 1 -- $(JSONNET_FMT) -i - -lint: - find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ - while read f; do \ - $(JSONNET_FMT) "$$f" | diff -u "$$f" -; \ - done - - mixtool lint mixin.libsonnet - -build: - mixtool generate all mixin.libsonnet - -clean: - rm -rf dashboards_out alerts.yaml rules.yaml diff --git a/postgres-mixin/go.mod b/postgres-mixin/go.mod deleted file mode 100644 index fa5e20579..000000000 --- a/postgres-mixin/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/wrouesnel/postgres_exporter/postgres_mixin - -go 1.15 From 88c9f414a11b35df4ccfe633b85f77aa749d27f2 Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Wed, 9 Dec 2020 17:43:17 +0100 Subject: [PATCH 5/6] Correct datasource variable name. --- postgres-mixin/dashboards/postgres-overview.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/postgres-mixin/dashboards/postgres-overview.json b/postgres-mixin/dashboards/postgres-overview.json index 24b7bc92d..791ca95b0 100644 --- a/postgres-mixin/dashboards/postgres-overview.json +++ b/postgres-mixin/dashboards/postgres-overview.json @@ -25,7 +25,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "Postgres Overview", + "datasource": "$datasource", "editable": true, "error": false, "fieldConfig": { @@ -396,7 +396,7 @@ "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)" ], - "datasource": "Postgres Overview", + "datasource": "$datasource", "decimals": 0, "editable": true, "error": false, @@ -530,7 +530,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "Postgres Overview", + "datasource": "$datasource", "decimals": 1, "editable": true, "error": false, @@ -889,7 +889,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "Postgres Overview", + "datasource": "$datasource", "editable": true, "error": false, "fieldConfig": { @@ -1088,7 +1088,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "Postgres Overview", + "datasource": "$datasource", "editable": true, "error": false, "fieldConfig": { @@ -1191,7 +1191,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "Postgres Overview", + "datasource": "$datasource", "editable": true, "error": false, "fieldConfig": { @@ -1305,7 +1305,7 @@ "text": "All", "value": "$__all" }, - "datasource": "Postgres Overview", + "datasource": "$datasource", "definition": "", "hide": 0, "includeAll": true, @@ -1331,7 +1331,7 @@ "text": "All", "value": "$__all" }, - "datasource": "Postgres Overview", + "datasource": "$datasource", "definition": "label_values(pg_stat_database_tup_fetched{instance=~\"$instance\",datname!~\"template.*|postgres\"},datname)", "hide": 0, "includeAll": true, From 636986077d79eda39d7ebbabed5f07a59f424125 Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Wed, 9 Dec 2020 18:40:52 +0100 Subject: [PATCH 6/6] Remove reference to Makefile in README. --- postgres-mixin/README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/postgres-mixin/README.md b/postgres-mixin/README.md index e5f12edf6..7a0002b69 100644 --- a/postgres-mixin/README.md +++ b/postgres-mixin/README.md @@ -15,12 +15,5 @@ $ go get github.com/monitoring-mixins/mixtool/cmd/mixtool $ go get github.com/google/go-jsonnet/cmd/jsonnetfmt ``` -You can then build the Prometheus rules files `alerts.yaml` and -`rules.yaml` and a directory `dashboard_out` with the JSON dashboard files -for Grafana: -```bash -$ make build -``` - For more advanced uses of mixins, see https://github.com/monitoring-mixins/docs.