Skip to content

Instantly share code, notes, and snippets.

@amotl
Last active March 10, 2024 00:29
Show Gist options
  • Save amotl/3370c3d64c7a005967ff7500e91d3cf4 to your computer and use it in GitHub Desktop.
Save amotl/3370c3d64c7a005967ff7500e91d3cf4 to your computer and use it in GitHub Desktop.
Grafana Prometheus query expression samples

About

A few samples of Prometheus queries in Grafana dashboards.

Details

{
  "datasource": {
    "type": "prometheus",
    "uid": "${datasource}"
  },
  "editorMode": "code",
  "expr": "sum(increase(kubecost_pod_network_egress_bytes_total{exported_namespace=\"$ns\", internet=~\"$internet\", pod_name=~\"$pod_or_service\"}[$__rate_interval])) by (pod_name)",
  "legendFormat": "egress {{pod_name}}",
  "range": true,
  "refId": "A"
}
{
    "datasource": {
        "type": "prometheus",
        "uid": "grafanacloud-prom"
    },
    "editorMode": "code",
    "expr": "count(count(node_cpu_seconds_total{instance=\"$node\",job=\"$job\"}) by (cpu))",
    "legendFormat": "__auto",
    "range": true,
    "refId": "A",
    "_panel": {
        "id": 14,
        "title": "CPU Cores",
        "type": "stat",
        "datasource": {
            "type": "prometheus",
            "uid": "grafanacloud-prom"
        }
    }
},
{
    "datasource": "grafanacloud-play-prom",
    "exemplar": false,
    "expr": "100*(\n  1 - (\n    sum by (probe, geohash)\n    (\n      rate(probe_all_success_sum{instance=\"$instance\", job=\"$job\"}[$__range])\n      *\n      on (instance, job, probe, config_version)\n      group_left(geohash)\n      max by (instance, job, probe, config_version, geohash)\n      (\n        sm_check_info{instance=\"$instance\", job=\"$job\"}\n      )\n    )\n    /\n    sum by (probe, geohash)\n    (\n      rate(probe_all_success_count{instance=\"$instance\", job=\"$job\"}[$__range])\n        *\n      on (instance, job, probe, config_version)\n      group_left(geohash)\n      max by (instance, job, probe, config_version, geohash)\n      (\n        sm_check_info{instance=\"$instance\", job=\"$job\"}\n      )\n    )\n  )\n)",
    "format": "table",
    "instant": true,
    "interval": "",
    "legendFormat": "",
    "refId": "A",
    "_panel": {
        "id": 34,
        "title": "Error rate by probe",
        "type": "geomap",
        "datasource": "grafanacloud-play-prom"
    }
},
{
    "expr": "sum(rate(probe_all_duration_seconds_sum{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range])) / sum(rate(probe_all_duration_seconds_count{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]))",
    "hide": false,
    "instant": true,
    "interval": "",
    "legendFormat": "",
    "refId": "B",
    "_panel": {
        "id": 40,
        "title": "Average latency",
        "type": "stat",
        "datasource": "grafanacloud-play-prom"
    }
},
{
    "exemplar": true,
    "expr": "node_load1{job=\"node\", instance=~\"$nodxdvfsdve:.*\"} / count by(job, instance)(count by(job, instance, cpu)(node_cpu_seconds_total{job=\"node\", instance=~\"$node:.*\"}))",
    "format": "time_series",
    "interval": "",
    "intervalFactor": 2,
    "legendFormat": "",
    "refId": "A",
    "step": 60,
    "_panel": {
        "id": 2,
        "title": "Load",
        "type": "gauge",
        "datasource": "demo.robustperception.io"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment