{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "title": "goodcharge SDK",
  "uid": "goodcharge-sdk",
  "schemaVersion": 39,
  "version": 1,
  "editable": true,
  "time": { "from": "now-6h", "to": "now" },
  "refresh": "1m",
  "tags": ["goodcharge"],
  "templating": {
    "list": [
      {
        "name": "station",
        "label": "Station",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
        "query": "label_values(goodcharge_heartbeat_running, station)",
        "refresh": 2,
        "includeAll": true,
        "allValue": ".*",
        "multi": true
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Current dot",
      "gridPos": { "h": 5, "w": 6, "x": 0, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "goodcharge_station_status{station=~\"$station\"} == 1",
          "legendFormat": "{{station}}: {{dot}}",
          "instant": true
        }
      ],
      "options": { "textMode": "name", "reduceOptions": { "calcs": ["lastNotNull"] } }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Published",
      "gridPos": { "h": 5, "w": 6, "x": 6, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "goodcharge_station_published{station=~\"$station\"}",
          "legendFormat": "{{station}}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "mappings": [
            { "type": "value", "options": { "0": { "text": "no" }, "1": { "text": "yes" } } }
          ]
        }
      }
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Age of last accepted data",
      "gridPos": { "h": 5, "w": 6, "x": 12, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "time() - goodcharge_station_last_data_timestamp_seconds{station=~\"$station\"}",
          "legendFormat": "{{station}}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 600 },
              { "color": "red", "value": 900 }
            ]
          }
        }
      }
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Heartbeat running",
      "gridPos": { "h": 5, "w": 6, "x": 18, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "goodcharge_heartbeat_running{station=~\"$station\"}",
          "legendFormat": "{{station}}"
        }
      ]
    },
    {
      "id": 5,
      "type": "timeseries",
      "title": "Calls per second by outcome",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 5 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (station, method, outcome) (rate(goodcharge_requests_total{station=~\"$station\"}[5m]))",
          "legendFormat": "{{station}} {{method}} {{outcome}}"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "reqps" } }
    },
    {
      "id": 6,
      "type": "timeseries",
      "title": "Attempt latency p50 / p95",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 5 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "histogram_quantile(0.5, sum by (le, method) (rate(goodcharge_request_duration_seconds_bucket{station=~\"$station\"}[5m])))",
          "legendFormat": "p50 {{method}}"
        },
        {
          "refId": "B",
          "expr": "histogram_quantile(0.95, sum by (le, method) (rate(goodcharge_request_duration_seconds_bucket{station=~\"$station\"}[5m])))",
          "legendFormat": "p95 {{method}}"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "s" } }
    },
    {
      "id": 7,
      "type": "timeseries",
      "title": "Retries per minute",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 13 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (station, method) (rate(goodcharge_retries_total{station=~\"$station\"}[5m])) * 60",
          "legendFormat": "{{station}} {{method}}"
        }
      ]
    },
    {
      "id": 8,
      "type": "stat",
      "title": "Last rejection",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 13 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "refId": "A",
          "expr": "goodcharge_station_last_rejection_timestamp_seconds{station=~\"$station\"} * 1000",
          "legendFormat": "{{station}}"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "dateTimeFromNow" } }
    }
  ]
}
