apiVersion: v1
data:
  query_statistics.json: |-
   {
     "__inputs": [
       {
         "name": "DS_PROMETHEUS",
         "label": "PROMETHEUS",
         "description": "",
         "type": "datasource",
         "pluginId": "prometheus",
         "pluginName": "Prometheus"
       }
     ],
     "__requires": [
       {
         "type": "grafana",
         "id": "grafana",
         "name": "Grafana",
         "version": "7.4.5"
       },
       {
         "type": "panel",
         "id": "graph",
         "name": "Graph",
         "version": ""
       },
       {
         "type": "datasource",
         "id": "prometheus",
         "name": "Prometheus",
         "version": "1.0.0"
       },
       {
         "type": "panel",
         "id": "stat",
         "name": "Stat",
         "version": ""
       },
       {
         "type": "panel",
         "id": "table",
         "name": "Table",
         "version": ""
       }
     ],
     "annotations": {
       "list": [
         {
           "builtIn": 1,
           "datasource": "-- Grafana --",
           "enable": true,
           "hide": true,
           "iconColor": "rgba(0, 211, 255, 1)",
           "name": "Annotations & Alerts",
           "type": "dashboard"
         }
       ]
     },
     "description": "",
     "editable": false,
     "gnetId": null,
     "graphTooltip": 0,
     "id": null,
     "iteration": 1625070004605,
     "links": [
       {
         "icon": "external link",
         "tags": [
           "vendor=crunchydata"
         ],
         "type": "dashboards"
       }
     ],
     "panels": [
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {},
             "mappings": [],
             "thresholds": {
               "mode": "absolute",
               "steps": [
                 {
                   "color": "blue",
                   "value": null
                 }
               ]
             },
             "unit": "none"
           },
           "overrides": []
         },
         "gridPos": {
           "h": 3,
           "w": 5,
           "x": 0,
           "y": 0
         },
         "id": 8,
         "options": {
           "colorMode": "value",
           "graphMode": "area",
           "justifyMode": "auto",
           "orientation": "auto",
           "reduceOptions": {
             "calcs": [],
             "fields": "",
             "values": false
           },
           "text": {},
           "textMode": "value"
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "sum(sum_over_time(ccp_pg_stat_statements_total_calls_count{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment,pod,dbname,exported_role)",
             "instant": false,
             "interval": "",
             "legendFormat": "",
             "refId": "A"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Queries Executed",
         "type": "stat"
       },
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {},
             "mappings": [],
             "thresholds": {
               "mode": "absolute",
               "steps": [
                 {
                   "color": "blue",
                   "value": null
                 }
               ]
             },
             "unit": "ms"
           },
           "overrides": []
         },
         "gridPos": {
           "h": 3,
           "w": 6,
           "x": 5,
           "y": 0
         },
         "id": 9,
         "options": {
           "colorMode": "value",
           "graphMode": "area",
           "justifyMode": "auto",
           "orientation": "auto",
           "reduceOptions": {
             "calcs": [],
             "fields": "",
             "values": false
           },
           "text": {},
           "textMode": "value"
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "sum(sum_over_time(ccp_pg_stat_statements_total_exec_time_ms{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment,pod,dbname,exported_role)",
             "format": "time_series",
             "instant": false,
             "interval": "",
             "legendFormat": "",
             "refId": "A"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Query Runtime ",
         "type": "stat"
       },
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {},
             "mappings": [],
             "thresholds": {
               "mode": "absolute",
               "steps": [
                 {
                   "color": "blue",
                   "value": null
                 }
               ]
             },
             "unit": "ms"
           },
           "overrides": []
         },
         "gridPos": {
           "h": 3,
           "w": 6,
           "x": 11,
           "y": 0
         },
         "id": 10,
         "options": {
           "colorMode": "value",
           "graphMode": "area",
           "justifyMode": "auto",
           "orientation": "auto",
           "reduceOptions": {
             "calcs": [
               "mean"
             ],
             "fields": "",
             "values": false
           },
           "text": {},
           "textMode": "value"
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "avg(sum_over_time(ccp_pg_stat_statements_total_mean_exec_time_ms{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment,pod,dbname,exported_role)",
             "format": "time_series",
             "instant": false,
             "interval": "",
             "legendFormat": "",
             "refId": "A"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Query Mean Runtime",
         "type": "stat"
       },
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {},
             "mappings": [],
             "thresholds": {
               "mode": "absolute",
               "steps": [
                 {
                   "color": "blue",
                   "value": null
                 }
               ]
             },
             "unit": "none"
           },
           "overrides": []
         },
         "gridPos": {
           "h": 3,
           "w": 6,
           "x": 17,
           "y": 0
         },
         "id": 11,
         "options": {
           "colorMode": "value",
           "graphMode": "area",
           "justifyMode": "auto",
           "orientation": "auto",
           "reduceOptions": {
             "calcs": [
               "mean"
             ],
             "fields": "",
             "values": false
           },
           "text": {},
           "textMode": "value"
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "sum(sum_over_time(ccp_pg_stat_statements_total_row_count{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment, pod,dbname,exported_role)",
             "format": "time_series",
             "instant": false,
             "interval": "",
             "legendFormat": "",
             "refId": "A"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Rows Retrieved or Affected",
         "type": "stat"
       },
       {
         "aliasColors": {},
         "bars": false,
         "dashLength": 10,
         "dashes": false,
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {}
           },
           "overrides": []
         },
         "fill": 1,
         "fillGradient": 0,
         "gridPos": {
           "h": 7,
           "w": 23,
           "x": 0,
           "y": 3
         },
         "hiddenSeries": false,
         "id": 2,
         "legend": {
           "alignAsTable": true,
           "avg": false,
           "current": false,
           "max": false,
           "min": false,
           "rightSide": true,
           "show": true,
           "sideWidth": null,
           "total": false,
           "values": false
         },
         "lines": true,
         "linewidth": 1,
         "nullPointMode": "null",
         "options": {
           "alertThreshold": true
         },
         "percentage": false,
         "pluginVersion": "7.4.5",
         "pointradius": 2,
         "points": false,
         "renderer": "flot",
         "seriesOverrides": [],
         "spaceLength": 10,
         "stack": false,
         "steppedLine": false,
         "targets": [
           {
             "expr": "sum(irate(ccp_pg_stat_statements_total_calls_count{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment, pod)",
             "instant": false,
             "interval": "",
             "legendFormat": "db: {{dbname}}, user: {{exported_role}}",
             "refId": "A"
           }
         ],
         "thresholds": [],
         "timeFrom": null,
         "timeRegions": [],
         "timeShift": null,
         "title": "Query Executions",
         "tooltip": {
           "shared": true,
           "sort": 0,
           "value_type": "individual"
         },
         "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
           }
         ],
         "yaxis": {
           "align": false,
           "alignLevel": null
         }
       },
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {
               "align": null,
               "displayMode": "auto",
               "filterable": false
             },
             "mappings": [],
             "thresholds": {
               "mode": "percentage",
               "steps": [
                 {
                   "color": "green",
                   "value": null
                 },
                 {
                   "color": "red",
                   "value": 80
                 }
               ]
             }
           },
           "overrides": [
             {
               "matcher": {
                 "id": "byName",
                 "options": "Runtime"
               },
               "properties": [
                 {
                   "id": "unit",
                   "value": "ms"
                 },
                 {
                   "id": "custom.displayMode",
                   "value": "color-background"
                 },
                 {
                   "id": "thresholds",
                   "value": {
                     "mode": "percentage",
                     "steps": [
                       {
                         "color": "green",
                         "value": null
                       },
                       {
                         "color": "red",
                         "value": 90
                       }
                     ]
                   }
                 },
                 {
                   "id": "custom.width",
                   "value": 169
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "queryid"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 189
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "query"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 308
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "role"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 82
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "dbname"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 184
                 }
               ]
             }
           ]
         },
         "gridPos": {
           "h": 8,
           "w": 23,
           "x": 0,
           "y": 10
         },
         "id": 4,
         "options": {
           "showHeader": true,
           "sortBy": [
             {
               "desc": true,
               "displayName": "Runtime"
             }
           ]
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "avg(avg_over_time(ccp_pg_stat_statements_top_mean_exec_time_ms{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment,pod)",
             "format": "table",
             "hide": false,
             "instant": true,
             "interval": "",
             "legendFormat": "",
             "refId": "B"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Query Mean Runtime (Top N)",
         "transformations": [
           {
             "id": "organize",
             "options": {
               "excludeByName": {
                 "Time": true,
                 "__name__": true,
                 "exp_type": true,
                 "job": true,
                 "kubernetes_namespace": true,
                 "queryid": false,
                 "role": false,
                 "server": true
               },
               "indexByName": {
                 "Time": 6,
                 "Value": 5,
                 "__name__": 7,
                 "dbname": 0,
                 "exp_type": 8,
                 "instance": 2,
                 "job": 9,
                 "query": 3,
                 "queryid": 4,
                 "role": 1
               },
               "renameByName": {
                 "Value": "Runtime"
               }
             }
           }
         ],
         "type": "table"
       },
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {
               "align": null,
               "displayMode": "auto",
               "filterable": false
             },
             "mappings": [],
             "thresholds": {
               "mode": "percentage",
               "steps": [
                 {
                   "color": "green",
                   "value": null
                 },
                 {
                   "color": "red",
                   "value": 80
                 }
               ]
             }
           },
           "overrides": [
             {
               "matcher": {
                 "id": "byName",
                 "options": "Runtime"
               },
               "properties": [
                 {
                   "id": "unit",
                   "value": "ms"
                 },
                 {
                   "id": "custom.displayMode",
                   "value": "color-background"
                 },
                 {
                   "id": "thresholds",
                   "value": {
                     "mode": "percentage",
                     "steps": [
                       {
                         "color": "green",
                         "value": null
                       },
                       {
                         "color": "red",
                         "value": 90
                       }
                     ]
                   }
                 },
                 {
                   "id": "custom.width",
                   "value": 170
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "dbname"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 184
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "role"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 82
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "query"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 310
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "queryid"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 186
                 }
               ]
             }
           ]
         },
         "gridPos": {
           "h": 8,
           "w": 23,
           "x": 0,
           "y": 18
         },
         "id": 6,
         "options": {
           "showHeader": true,
           "sortBy": [
             {
               "desc": true,
               "displayName": "Runtime"
             }
           ]
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "max(max_over_time(ccp_pg_stat_statements_top_max_exec_time_ms{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment,pod)",
             "format": "table",
             "hide": false,
             "instant": true,
             "interval": "",
             "legendFormat": "",
             "refId": "B"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Query Max Runtime (Top N)",
         "transformations": [
           {
             "id": "organize",
             "options": {
               "excludeByName": {
                 "Time": true,
                 "__name__": true,
                 "exp_type": true,
                 "job": true,
                 "kubernetes_namespace": true,
                 "queryid": false,
                 "role": false,
                 "server": true
               },
               "indexByName": {
                 "Time": 6,
                 "Value": 5,
                 "__name__": 7,
                 "dbname": 0,
                 "exp_type": 8,
                 "instance": 2,
                 "job": 9,
                 "query": 3,
                 "queryid": 4,
                 "role": 1
               },
               "renameByName": {
                 "Value": "Runtime"
               }
             }
           }
         ],
         "type": "table"
       },
       {
         "datasource": "Prometheus",
         "fieldConfig": {
           "defaults": {
             "custom": {
               "align": null,
               "filterable": false
             },
             "mappings": [],
             "thresholds": {
               "mode": "absolute",
               "steps": [
                 {
                   "color": "green",
                   "value": null
                 },
                 {
                   "color": "red",
                   "value": 80
                 }
               ]
             }
           },
           "overrides": [
             {
               "matcher": {
                 "id": "byName",
                 "options": "Runtime"
               },
               "properties": [
                 {
                   "id": "unit",
                   "value": "ms"
                 },
                 {
                   "id": "custom.displayMode",
                   "value": "color-background"
                 },
                 {
                   "id": "thresholds",
                   "value": {
                     "mode": "percentage",
                     "steps": [
                       {
                         "color": "green",
                         "value": null
                       },
                       {
                         "color": "red",
                         "value": 90
                       }
                     ]
                   }
                 },
                 {
                   "id": "custom.width",
                   "value": 172
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "dbname"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 182
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "role"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 84
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "query"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 309
                 }
               ]
             },
             {
               "matcher": {
                 "id": "byName",
                 "options": "queryid"
               },
               "properties": [
                 {
                   "id": "custom.width",
                   "value": 189
                 }
               ]
             }
           ]
         },
         "gridPos": {
           "h": 8,
           "w": 23,
           "x": 0,
           "y": 26
         },
         "id": 5,
         "options": {
           "showHeader": true,
           "sortBy": [
             {
               "desc": true,
               "displayName": "Runtime"
             }
           ]
         },
         "pluginVersion": "7.4.5",
         "targets": [
           {
             "expr": "sum(irate(ccp_pg_stat_statements_top_total_exec_time_ms{pg_cluster=\"[[cluster]]\", role=\"[[role]]\",dbname=~\"[[dbname]]\",exported_role=~\"[[dbuser]]\"}[$__range])) without(instance, ip, deployment,pod)",
             "format": "table",
             "instant": true,
             "interval": "",
             "legendFormat": "",
             "refId": "A"
           }
         ],
         "timeFrom": null,
         "timeShift": null,
         "title": "Query Total Runtime (Top N)",
         "transformations": [
           {
             "id": "organize",
             "options": {
               "excludeByName": {
                 "Time": true,
                 "__name__": true,
                 "exp_type": true,
                 "job": true,
                 "kubernetes_namespace": true,
                 "queryid": false,
                 "role": false,
                 "server": true
               },
               "indexByName": {
                 "Time": 6,
                 "Value": 5,
                 "__name__": 7,
                 "dbname": 0,
                 "exp_type": 8,
                 "instance": 2,
                 "job": 9,
                 "query": 3,
                 "queryid": 4,
                 "role": 1
               },
               "renameByName": {
                 "Value": "Runtime"
               }
             }
           }
         ],
         "type": "table"
       }
     ],
     "refresh": "15m",
     "schemaVersion": 27,
     "style": "dark",
     "tags": [
       "vendor=crunchydata"
     ],
     "templating": {
       "list": [
         {
           "allValue": null,
           "current": {},
           "datasource": "Prometheus",
           "definition": "label_values(pg_cluster)",
           "description": null,
           "error": null,
           "hide": 0,
           "includeAll": false,
           "label": "cluster",
           "multi": false,
           "name": "cluster",
           "options": [],
           "query": {
             "query": "label_values(pg_cluster)",
             "refId": "StandardVariableQuery"
           },
           "refresh": 1,
           "regex": "",
           "skipUrlSync": false,
           "sort": 1,
           "tagValuesQuery": "",
           "tags": [],
           "tagsQuery": "",
           "type": "query",
           "useTags": false
         },
         {
           "allValue": null,
           "current": {},
           "datasource": "Prometheus",
           "definition": "label_values({pg_cluster=\"[[cluster]]\"},role)",
           "description": null,
           "error": null,
           "hide": 0,
           "includeAll": false,
           "label": "service",
           "multi": false,
           "name": "role",
           "options": [],
           "query": {
             "query": "label_values({pg_cluster=\"[[cluster]]\"},role)",
             "refId": "StandardVariableQuery"
           },
           "refresh": 2,
           "regex": "",
           "skipUrlSync": false,
           "sort": 1,
           "tagValuesQuery": "",
           "tags": [],
           "tagsQuery": "",
           "type": "query",
           "useTags": false
         },
         {
           "allValue": null,
           "current": {},
           "datasource": "Prometheus",
           "definition": "label_values(ccp_database_size_bytes{pg_cluster=\"[[cluster]]\"},dbname)",
           "description": null,
           "error": null,
           "hide": 0,
           "includeAll": true,
           "label": "dbname",
           "multi": false,
           "name": "dbname",
           "options": [],
           "query": {
             "query": "label_values(ccp_database_size_bytes{pg_cluster=\"[[cluster]]\"},dbname)",
             "refId": "StandardVariableQuery"
           },
           "refresh": 1,
           "regex": "",
           "skipUrlSync": false,
           "sort": 0,
           "tagValuesQuery": "",
           "tags": [],
           "tagsQuery": "",
           "type": "query",
           "useTags": false
         },
         {
           "allValue": null,
           "current": {},
           "datasource": "Prometheus",
           "definition": "label_values(ccp_pg_stat_statements_total_calls_count{pg_cluster=\"[[cluster]]\", dbname=~\"[[dbname]]\"},exported_role)",
           "description": null,
           "error": null,
           "hide": 0,
           "includeAll": true,
           "label": "dbuser",
           "multi": false,
           "name": "dbuser",
           "options": [],
           "query": {
             "query": "label_values(ccp_pg_stat_statements_total_calls_count{pg_cluster=\"[[cluster]]\", dbname=~\"[[dbname]]\"},exported_role)",
             "refId": "StandardVariableQuery"
           },
           "refresh": 1,
           "regex": "",
           "skipUrlSync": false,
           "sort": 0,
           "tagValuesQuery": "",
           "tags": [],
           "tagsQuery": "",
           "type": "query",
           "useTags": false
         }
       ]
     },
     "time": {
       "from": "now-1h",
       "to": "now"
     },
     "timepicker": {
       "time_options": [
         "5m",
         "15m",
         "1h",
         "6h",
         "12h",
         "24h",
         "2d",
         "7d",
         "30d"
       ]
     },
     "timezone": "browser",
     "title": "Query Statistics",
     "uid": "ZKoTOHDGk",
     "version": 1
   }
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: grafana-dashboard-crunchy-query-statistics
