From 5e431602c868c29c2269519275c0db540aafd092 Mon Sep 17 00:00:00 2001 From: Yogesh Sharma Date: Tue, 23 Feb 2021 15:25:16 -0800 Subject: [PATCH 1/3] Convert newline to space Special IFS is not reuired --- hugo/themes/crunchy-hugo-theme | 2 +- postgres_exporter/linux/pgbackrest-info.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hugo/themes/crunchy-hugo-theme b/hugo/themes/crunchy-hugo-theme index 69edd300..84a0ea49 160000 --- a/hugo/themes/crunchy-hugo-theme +++ b/hugo/themes/crunchy-hugo-theme @@ -1 +1 @@ -Subproject commit 69edd30074df74a5046b594c9d88ad57cb813ed6 +Subproject commit 84a0ea49a40ec561313ffa5a678afb9404cc524a diff --git a/postgres_exporter/linux/pgbackrest-info.sh b/postgres_exporter/linux/pgbackrest-info.sh index ae685bdb..a05fe450 100755 --- a/postgres_exporter/linux/pgbackrest-info.sh +++ b/postgres_exporter/linux/pgbackrest-info.sh @@ -8,7 +8,7 @@ [ -f /etc/pgmonitor.conf ] && . /etc/pgmonitor.conf if [ ${BACKREST_AUTOCONFIG_STANZAS:-0} -gt 0 ]; then - BACKREST_STANZAS=$(grep '^\[' /etc/pgbackrest.conf /etc/pgbackrest/ -rh |sort -u |grep -v ':\|global' |sed 's/\[\|\]//g') + BACKREST_STANZAS=$(grep '^\[' /etc/pgbackrest.conf /etc/pgbackrest/ -rh |sort -u |grep -v ':\|global' |sed 's/\[\|\]//g' | tr '\n' ' ' ) BACKREST_CONFIGS="" fi @@ -17,13 +17,13 @@ conf="default" if [ -z "$BACKREST_CONFIGS" ] && [ -z "$BACKREST_STANZAS" ]; then echo $(echo -n "$conf|" | tr '/' '_'; pgbackrest --output=json info | tr -d '\n') elif [ ! -z "$BACKREST_CONFIGS" ] && [ -z "$BACKREST_STANZAS" ]; then - IFS=':' read -r -a config_array <<< "$BACKREST_CONFIGS" + read -r -a config_array <<< "$BACKREST_CONFIGS" for conf in "${config_array[@]}" do echo $(echo -n "$conf|" | tr '/' '_'; pgbackrest --config=$conf --output=json info | tr -d '\n') done elif [ -z "$BACKREST_CONFIGS" ] && [ ! -z "$BACKREST_STANZAS" ]; then - IFS=':' read -r -a stanza_array <<< "$BACKREST_STANZAS" + read -r -a stanza_array <<< "$BACKREST_STANZAS" for stanza in "${stanza_array[@]}" do export PGBACKREST_STANZA=$stanza From 735504cffd4eed5af69981f32f7dca057a5ef779 Mon Sep 17 00:00:00 2001 From: Yogesh Sharma Date: Thu, 25 Feb 2021 16:19:21 -0800 Subject: [PATCH 2/3] Fix issue #628 Fix pgbackrest dashboard Fix setup.sql --- grafana/common/PGBackrest.json | 127 ++++++--- grafana/common/PG_Details.json | 314 +++++++++++---------- postgres_exporter/common/pg10/setup.sql | 9 +- postgres_exporter/common/pg11/setup.sql | 9 +- postgres_exporter/common/pg12/setup.sql | 5 +- postgres_exporter/common/pg13/setup.sql | 11 +- postgres_exporter/common/pg96/setup.sql | 6 +- postgres_exporter/linux/pgbackrest-info.sh | 12 +- 8 files changed, 278 insertions(+), 215 deletions(-) diff --git a/grafana/common/PGBackrest.json b/grafana/common/PGBackrest.json index 28db28ee..f836f3c8 100644 --- a/grafana/common/PGBackrest.json +++ b/grafana/common/PGBackrest.json @@ -15,8 +15,8 @@ "editable": false, "gnetId": null, "graphTooltip": 0, - "id": 6, - "iteration": 1582574864807, + "id": 4, + "iteration": 1614244309467, "links": [], "panels": [ { @@ -25,6 +25,13 @@ "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -49,9 +56,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -61,8 +69,9 @@ "steppedLine": false, "targets": [ { - "expr": "ccp_backrest_last_incr_backup_time_since_completion_seconds{job=~\"[[pgnodes]]\",stanza=\"[[backrest_stanza]]\"}", + "expr": "ccp_backrest_last_incr_backup_time_since_completion_seconds{stanza=\"[[backrest_stanza]]\"} + on(job,instance) group_left() (ccp_is_in_recovery_status == 2)", "format": "time_series", + "interval": "", "intervalFactor": 1, "legendFormat": "{{stanza}}", "refId": "A" @@ -115,6 +124,13 @@ "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -139,9 +155,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -151,8 +168,9 @@ "steppedLine": false, "targets": [ { - "expr": "ccp_backrest_last_info_backup_runtime_seconds{job=~\"[[pgnodes]]\",stanza=\"[[backrest_stanza]]\"}", + "expr": "ccp_backrest_last_info_backup_runtime_seconds{stanza=\"[[backrest_stanza]]\"} + on(job,instance) group_left() (ccp_is_in_recovery_status == 2)", "format": "time_series", + "interval": "", "intervalFactor": 1, "legendFormat": "{{backup_type}}", "refId": "A" @@ -205,6 +223,13 @@ "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -229,9 +254,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 2, "points": false, "renderer": "flot", @@ -241,8 +267,9 @@ "steppedLine": false, "targets": [ { - "expr": "ccp_backrest_last_info_repo_total_size_bytes{job=~\"[[pgnodes]]\",stanza=\"[[backrest_stanza]]\"}", + "expr": "ccp_backrest_last_info_repo_total_size_bytes{stanza=\"[[backrest_stanza]]\"} + on(job,instance) group_left() (ccp_is_in_recovery_status == 2)", "format": "time_series", + "interval": "", "intervalFactor": 1, "legendFormat": "{{backup_type}}", "refId": "A" @@ -295,6 +322,13 @@ "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -319,9 +353,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 2, "points": false, "renderer": "flot", @@ -331,8 +366,9 @@ "steppedLine": false, "targets": [ { - "expr": "ccp_backrest_last_info_repo_backup_size_bytes{job=~\"[[pgnodes]]\",stanza=\"[[backrest_stanza]]\"}", + "expr": "ccp_backrest_last_info_repo_backup_size_bytes{stanza=\"[[backrest_stanza]]\"} + on(job,instance) group_left() (ccp_is_in_recovery_status == 2)", "format": "time_series", + "interval": "", "intervalFactor": 1, "legendFormat": "{{backup_type}}", "refId": "A" @@ -385,6 +421,13 @@ "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -409,9 +452,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -421,8 +465,9 @@ "steppedLine": false, "targets": [ { - "expr": "ccp_backrest_last_full_backup_time_since_completion_seconds{job=~\"[[pgnodes]]\",stanza=\"[[backrest_stanza]]\"}", + "expr": "ccp_backrest_last_full_backup_time_since_completion_seconds{stanza=\"[[backrest_stanza]]\"} + on(job,instance) group_left() (ccp_is_in_recovery_status == 2)", "format": "time_series", + "interval": "", "intervalFactor": 1, "legendFormat": "{{stanza}}", "refId": "A" @@ -475,6 +520,13 @@ "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -499,9 +551,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -511,8 +564,9 @@ "steppedLine": false, "targets": [ { - "expr": "ccp_backrest_last_diff_backup_time_since_completion_seconds{job=~\"[[pgnodes]]\",stanza=\"[[backrest_stanza]]\"}", + "expr": "ccp_backrest_last_diff_backup_time_since_completion_seconds{stanza=\"[[backrest_stanza]]\"} + on(job,instance) group_left() (ccp_is_in_recovery_status == 2)", "format": "time_series", + "interval": "", "intervalFactor": 1, "legendFormat": "{{stanza}}", "refId": "A" @@ -561,7 +615,7 @@ } ], "refresh": "15m", - "schemaVersion": 21, + "schemaVersion": 27, "style": "dark", "tags": [], "templating": { @@ -569,45 +623,24 @@ { "allValue": null, "current": { - "text": "pg1", - "value": "pg1" - }, - "datasource": "PROMETHEUS", - "definition": "", - "hide": 0, - "includeAll": false, - "label": "PGCluster", - "multi": false, - "name": "pgnodes", - "options": [], - "query": "label_values(up{exp_type='pg'}, job)", - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 1, - "tagValuesQuery": "", - "tags": [], - "tagsQuery": "", - "type": "query", - "useTags": false - }, - { - "allValue": null, - "current": { - "isNone": true, "selected": false, - "text": "None", - "value": "" + "text": "alpha", + "value": "alpha" }, "datasource": "PROMETHEUS", - "definition": "", + "definition": "label_values(ccp_backrest_last_info_backup_runtime_seconds{}, stanza)", + "description": null, + "error": null, "hide": 0, "includeAll": false, "label": "Stanza", "multi": false, "name": "backrest_stanza", "options": [], - "query": "label_values(ccp_backrest_last_info_backup_runtime_seconds{job=~\"[[pgnodes]]\"}, stanza)", + "query": { + "query": "label_values(ccp_backrest_last_info_backup_runtime_seconds{}, stanza)", + "refId": "StandardVariableQuery" + }, "refresh": 1, "regex": "", "skipUrlSync": false, @@ -621,7 +654,7 @@ ] }, "time": { - "from": "now-2w", + "from": "now-1h", "to": "now" }, "timepicker": { @@ -647,5 +680,5 @@ "timezone": "", "title": "pgBackRest", "uid": "QtHwNCrik", - "version": 2 + "version": 1 } \ No newline at end of file diff --git a/grafana/common/PG_Details.json b/grafana/common/PG_Details.json index 54442767..ce2b42da 100644 --- a/grafana/common/PG_Details.json +++ b/grafana/common/PG_Details.json @@ -15,114 +15,30 @@ "editable": false, "gnetId": null, "graphTooltip": 0, - "id": 13, - "iteration": 1582574919045, + "id": 8, + "iteration": 1614123620619, "links": [], "panels": [ - { - "cacheTimeout": null, - "colorBackground": false, - "colorPrefix": false, - "colorValue": false, - "colors": [ - "#d44a3a", - "rgb(7, 6, 79)", - "rgba(50, 172, 45, 0.9)" - ], - "datasource": null, - "format": "dtdurations", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true - }, - "gridPos": { - "h": 2, - "w": 12, - "x": 0, - "y": 0 - }, - "id": 52, - "interval": null, - "links": [ - { - "targetBlank": true, - "title": "PGBackrest", - "url": "/d/QtHwNCrik/pgbackrest?$__all_variables" - } - ], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], - "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "options": {}, - "postfix": "", - "postfixFontSize": "50%", - "prefix": "Time Since Last Backup:", - "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 - }, - "tableColumn": "", - "targets": [ - { - "expr": "ccp_backrest_last_incr_backup_time_since_completion_seconds{job=~\"[[pgnodes]]\", stanza=\"[[backrest_stanza]]\"}", - "format": "time_series", - "intervalFactor": 1, - "legendFormat": "", - "refId": "A" - } - ], - "thresholds": "", - "timeFrom": null, - "timeShift": null, - "title": "[[pgnodes]] - [[backrest_stanza]] Backup Details", - "type": "singlestat", - "valueFontSize": "50%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - } - ], - "valueName": "current" - }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 6, "w": 24, "x": 0, - "y": 2 + "y": 0 }, "hiddenSeries": false, "id": 18, @@ -142,9 +58,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -237,13 +154,20 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 9, "w": 12, "x": 0, - "y": 8 + "y": 6 }, "hiddenSeries": false, "id": 39, @@ -266,9 +190,10 @@ ], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -339,13 +264,20 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 9, "w": 12, "x": 12, - "y": 8 + "y": 6 }, "hiddenSeries": false, "id": 41, @@ -363,9 +295,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -430,13 +363,20 @@ "dashes": false, "datasource": "PROMETHEUS", "description": "Note that replica_port can change if replicas ever detach and re-attach", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 6, "w": 12, "x": 0, - "y": 17 + "y": 15 }, "hiddenSeries": false, "id": 35, @@ -454,9 +394,10 @@ "links": [], "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -521,13 +462,20 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 6, "w": 12, "x": 12, - "y": 17 + "y": 15 }, "hiddenSeries": false, "id": 37, @@ -545,9 +493,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -611,13 +560,20 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 6, "w": 12, "x": 0, - "y": 23 + "y": 21 }, "hiddenSeries": false, "id": 12, @@ -635,9 +591,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -703,13 +660,20 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {}, + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 6, "w": 12, "x": 12, - "y": 23 + "y": 21 }, "hiddenSeries": false, "id": 13, @@ -727,9 +691,10 @@ "links": [], "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -803,13 +768,21 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "gridPos": { "h": 10, "w": 12, "x": 0, - "y": 29 + "y": 27 }, + "hiddenSeries": false, "id": 11, "legend": { "alignAsTable": true, @@ -832,8 +805,11 @@ } ], "nullPointMode": "null", - "options": {}, + "options": { + "alertThreshold": true + }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -935,13 +911,21 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, + "fillGradient": 0, "gridPos": { "h": 10, "w": 12, "x": 12, - "y": 29 + "y": 27 }, + "hiddenSeries": false, "id": 17, "legend": { "alignAsTable": true, @@ -958,8 +942,11 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, + "options": { + "alertThreshold": true + }, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1080,12 +1067,18 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 0, - "y": 39 + "y": 37 }, "id": 15, "legend": { @@ -1103,8 +1096,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1179,12 +1172,18 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 12, - "y": 39 + "y": 37 }, "id": 14, "legend": { @@ -1203,8 +1202,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1306,12 +1305,18 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 0, - "y": 46 + "y": 44 }, "id": 47, "legend": { @@ -1327,8 +1332,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1391,12 +1396,18 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 12, - "y": 46 + "y": 44 }, "id": 45, "legend": { @@ -1412,8 +1423,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1476,12 +1487,18 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 0, - "y": 53 + "y": 51 }, "id": 49, "legend": { @@ -1497,8 +1514,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1561,12 +1578,18 @@ "dashLength": 10, "dashes": false, "datasource": "PROMETHEUS", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 12, - "y": 53 + "y": 51 }, "id": 16, "legend": { @@ -1584,8 +1607,8 @@ "linewidth": 1, "links": [], "nullPointMode": "null", - "options": {}, "percentage": false, + "pluginVersion": "7.4.2", "pointradius": 5, "points": false, "renderer": "flot", @@ -1671,7 +1694,7 @@ } ], "refresh": "15m", - "schemaVersion": 21, + "schemaVersion": 27, "style": "dark", "tags": [], "templating": { @@ -1679,45 +1702,24 @@ { "allValue": null, "current": { - "text": "pg1", - "value": "pg1" + "selected": false, + "text": "pg1_alpha", + "value": "pg1_alpha" }, "datasource": "PROMETHEUS", "definition": "", + "description": null, + "error": null, "hide": 0, "includeAll": false, "label": "PGCluster", "multi": false, "name": "pgnodes", "options": [], - "query": "label_values(up{exp_type='pg'}, job)", - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 1, - "tagValuesQuery": "", - "tags": [], - "tagsQuery": "", - "type": "query", - "useTags": false - }, - { - "allValue": null, - "current": { - "isNone": true, - "selected": false, - "text": "None", - "value": "" + "query": { + "query": "label_values(up{exp_type='pg'}, job)", + "refId": "PROMETHEUS-pgnodes-Variable-Query" }, - "datasource": "PROMETHEUS", - "definition": "", - "hide": 0, - "includeAll": false, - "label": "BackRest Stanza", - "multi": false, - "name": "backrest_stanza", - "options": [], - "query": "label_values(ccp_backrest_last_info_backup_runtime_seconds{job=~\"[[pgnodes]]\"}, stanza)", "refresh": 1, "regex": "", "skipUrlSync": false, @@ -1731,7 +1733,7 @@ ] }, "time": { - "from": "now-2d", + "from": "now-15m", "to": "now" }, "timepicker": { @@ -1757,5 +1759,5 @@ "timezone": "browser", "title": "PostgreSQL Details", "uid": "6jtN_vfiz", - "version": 2 -} \ No newline at end of file + "version": 1 +} diff --git a/postgres_exporter/common/pg10/setup.sql b/postgres_exporter/common/pg10/setup.sql index cd584045..1b1d2df7 100644 --- a/postgres_exporter/common/pg10/setup.sql +++ b/postgres_exporter/common/pg10/setup.sql @@ -37,6 +37,7 @@ DECLARE v_gather_timestamp timestamptz; v_throttle interval; +v_system_identifier bigint; BEGIN -- Get pgBackRest info in JSON format @@ -51,8 +52,10 @@ IF pg_catalog.pg_is_in_recovery() = 'f' THEN -- Ensure table is empty DELETE FROM monitor.pgbackrest_info; + SELECT system_identifier into v_system_identifier FROM pg_control_system(); + -- Copy data into the table directory from the pgBackRest into command - COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh' WITH (format text,DELIMITER '|'); + EXECUTE format( $cmd$ COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh %s' WITH (format text,DELIMITER '|') $cmd$, v_system_identifier::text ); END IF; END IF; @@ -69,7 +72,7 @@ $function$; DROP FUNCTION IF EXISTS monitor.sequence_status(); CREATE FUNCTION monitor.sequence_status() RETURNS TABLE (sequence_name text, last_value bigint, slots numeric, used numeric, percent int, cycle boolean, numleft numeric, table_usage text) - LANGUAGE sql SECURITY DEFINER + LANGUAGE sql SECURITY DEFINER STABLE AS $function$ /* @@ -126,7 +129,7 @@ $function$; DROP FUNCTION IF EXISTS monitor.sequence_exhaustion(int); CREATE FUNCTION monitor.sequence_exhaustion(p_percent integer DEFAULT 75, OUT count bigint) - LANGUAGE sql SECURITY DEFINER + LANGUAGE sql SECURITY DEFINER STABLE AS $function$ /* diff --git a/postgres_exporter/common/pg11/setup.sql b/postgres_exporter/common/pg11/setup.sql index 4a9a4d18..1ce8e4f2 100644 --- a/postgres_exporter/common/pg11/setup.sql +++ b/postgres_exporter/common/pg11/setup.sql @@ -37,6 +37,7 @@ DECLARE v_gather_timestamp timestamptz; v_throttle interval; +v_system_identifier bigint; BEGIN -- Get pgBackRest info in JSON format @@ -51,8 +52,10 @@ IF pg_catalog.pg_is_in_recovery() = 'f' THEN -- Ensure table is empty DELETE FROM monitor.pgbackrest_info; + SELECT system_identifier into v_system_identifier FROM pg_control_system(); + -- Copy data into the table directory from the pgBackRest into command - COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh' WITH (format text,DELIMITER '|'); + EXECUTE format( $cmd$ COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh %s' WITH (format text,DELIMITER '|') $cmd$, v_system_identifier::text ); END IF; END IF; @@ -69,7 +72,7 @@ $function$; DROP FUNCTION IF EXISTS monitor.sequence_status(); CREATE FUNCTION monitor.sequence_status() RETURNS TABLE (sequence_name text, last_value bigint, slots numeric, used numeric, percent int, cycle boolean, numleft numeric, table_usage text) - LANGUAGE sql SECURITY DEFINER + LANGUAGE sql SECURITY DEFINER STABLE AS $function$ /* @@ -126,7 +129,7 @@ $function$; DROP FUNCTION IF EXISTS monitor.sequence_exhaustion(int); CREATE FUNCTION monitor.sequence_exhaustion(p_percent integer DEFAULT 75, OUT count bigint) - LANGUAGE sql SECURITY DEFINER + LANGUAGE sql SECURITY DEFINER STABLE AS $function$ /* diff --git a/postgres_exporter/common/pg12/setup.sql b/postgres_exporter/common/pg12/setup.sql index 6001f1ef..2f4174ae 100644 --- a/postgres_exporter/common/pg12/setup.sql +++ b/postgres_exporter/common/pg12/setup.sql @@ -37,6 +37,7 @@ DECLARE v_gather_timestamp timestamptz; v_throttle interval; +v_system_identifier bigint; BEGIN -- Get pgBackRest info in JSON format @@ -51,8 +52,10 @@ IF pg_catalog.pg_is_in_recovery() = 'f' THEN -- Ensure table is empty DELETE FROM monitor.pgbackrest_info; + SELECT system_identifier into v_system_identifier FROM pg_control_system(); + -- Copy data into the table directory from the pgBackRest into command - COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh' WITH (format text,DELIMITER '|'); + EXECUTE format( $cmd$ COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh %s' WITH (format text,DELIMITER '|') $cmd$, v_system_identifier::text ); END IF; END IF; diff --git a/postgres_exporter/common/pg13/setup.sql b/postgres_exporter/common/pg13/setup.sql index 1d163609..30aa9b05 100644 --- a/postgres_exporter/common/pg13/setup.sql +++ b/postgres_exporter/common/pg13/setup.sql @@ -8,6 +8,12 @@ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'ccp_monitoring') THEN CREATE ROLE ccp_monitoring WITH LOGIN; END IF; + + -- The pgmonitor role is required by the pgnodemx extension in PostgreSQL versions 9.5 and 9.6 + -- and should be removed when upgrading to PostgreSQL 10 and above. + IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'pgmonitor') THEN + DROP ROLE pgmonitor; + END IF; END $$; @@ -31,6 +37,7 @@ DECLARE v_gather_timestamp timestamptz; v_throttle interval; +v_system_identifier bigint; BEGIN -- Get pgBackRest info in JSON format @@ -45,8 +52,10 @@ IF pg_catalog.pg_is_in_recovery() = 'f' THEN -- Ensure table is empty DELETE FROM monitor.pgbackrest_info; + SELECT system_identifier into v_system_identifier FROM pg_control_system(); + -- Copy data into the table directory from the pgBackRest into command - COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh' WITH (format text,DELIMITER '|'); + EXECUTE format( $cmd$ COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh %s' WITH (format text,DELIMITER '|') $cmd$, v_system_identifier::text ); END IF; END IF; diff --git a/postgres_exporter/common/pg96/setup.sql b/postgres_exporter/common/pg96/setup.sql index c29f04b4..b99a0ed1 100644 --- a/postgres_exporter/common/pg96/setup.sql +++ b/postgres_exporter/common/pg96/setup.sql @@ -77,6 +77,7 @@ DECLARE v_gather_timestamp timestamptz; v_throttle interval; +v_system_identifier bigint; BEGIN -- Get pgBackRest info in JSON format @@ -91,8 +92,10 @@ IF pg_catalog.pg_is_in_recovery() = 'f' THEN -- Ensure table is empty DELETE FROM monitor.pgbackrest_info; + SELECT system_identifier into v_system_identifier FROM pg_control_system(); + -- Copy data into the table directory from the pgBackRest into command - COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh' WITH (format text,DELIMITER '|'); + EXECUTE format( $cmd$ COPY monitor.pgbackrest_info (config_file, data) FROM program '/usr/bin/pgbackrest-info.sh %s' WITH (format text,DELIMITER '|') $cmd$, v_system_identifier::text ); END IF; END IF; @@ -107,7 +110,6 @@ END $function$; - DROP FUNCTION IF EXISTS monitor.sequence_status(); CREATE FUNCTION monitor.sequence_status() RETURNS TABLE (sequence_name text, last_value bigint, slots numeric, used numeric, percent bigint, cycle boolean, numleft numeric, table_usage text) LANGUAGE plpgsql SECURITY DEFINER diff --git a/postgres_exporter/linux/pgbackrest-info.sh b/postgres_exporter/linux/pgbackrest-info.sh index a05fe450..15964c07 100755 --- a/postgres_exporter/linux/pgbackrest-info.sh +++ b/postgres_exporter/linux/pgbackrest-info.sh @@ -5,6 +5,8 @@ # ### +SYSTEM_ID=$1 + [ -f /etc/pgmonitor.conf ] && . /etc/pgmonitor.conf if [ ${BACKREST_AUTOCONFIG_STANZAS:-0} -gt 0 ]; then @@ -20,14 +22,20 @@ elif [ ! -z "$BACKREST_CONFIGS" ] && [ -z "$BACKREST_STANZAS" ]; then read -r -a config_array <<< "$BACKREST_CONFIGS" for conf in "${config_array[@]}" do - echo $(echo -n "$conf|" | tr '/' '_'; pgbackrest --config=$conf --output=json info | tr -d '\n') + echo $(echo -n "$conf|" | tr '/' '_'; pgbackrest --config=$conf --output=json info | tr -d '\n') | grep $SYSTEM_ID + if [ $? == 0 ]; then + break + fi done elif [ -z "$BACKREST_CONFIGS" ] && [ ! -z "$BACKREST_STANZAS" ]; then read -r -a stanza_array <<< "$BACKREST_STANZAS" for stanza in "${stanza_array[@]}" do export PGBACKREST_STANZA=$stanza - echo $(echo -n "$conf|" | tr '/' '_'; pgbackrest --output=json info | tr -d '\n') + echo $(echo -n "$conf|" | tr '/' '_'; pgbackrest --output=json info | tr -d '\n') | grep $SYSTEM_ID + if [ $? == 0 ]; then + break + fi done fi From 4d64b3a7904d06d1645511f420378f6bbacb69d2 Mon Sep 17 00:00:00 2001 From: Yogesh Sharma Date: Thu, 4 Mar 2021 09:15:39 -0500 Subject: [PATCH 3/3] Add check for missing system_id argument --- postgres_exporter/linux/pgbackrest-info.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/postgres_exporter/linux/pgbackrest-info.sh b/postgres_exporter/linux/pgbackrest-info.sh index 15964c07..401d7bb8 100755 --- a/postgres_exporter/linux/pgbackrest-info.sh +++ b/postgres_exporter/linux/pgbackrest-info.sh @@ -5,6 +5,11 @@ # ### +if [ "$1" == "" ]; then + echo "Usage: $(basename $0) " + exit 1 +fi + SYSTEM_ID=$1 [ -f /etc/pgmonitor.conf ] && . /etc/pgmonitor.conf