{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "Prometheus datasource for StemeDB metrics",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "annotations": {
    "list": []
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": null,
  "links": [],
  "panels": [
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 },
      "id": 1,
      "title": "Overview",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 10000 },
              { "color": "red", "value": 100000 }
            ]
          }
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 0, "y": 1 },
      "id": 2,
      "options": { "colorMode": "background", "graphMode": "none", "textMode": "value" },
      "targets": [
        {
          "expr": "stemedb_assertions_total",
          "legendFormat": "Assertions"
        }
      ],
      "title": "Total Assertions",
      "type": "stat"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 100 },
              { "color": "red", "value": 500 }
            ]
          }
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 6, "y": 1 },
      "id": 3,
      "options": { "colorMode": "background", "graphMode": "area", "textMode": "value" },
      "targets": [
        {
          "expr": "rate(stemedb_queries_total[5m])",
          "legendFormat": "Queries/sec"
        }
      ],
      "title": "Queries / sec",
      "type": "stat"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 1 },
              { "color": "red", "value": 10 }
            ]
          }
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 12, "y": 1 },
      "id": 4,
      "options": { "colorMode": "background", "graphMode": "none", "textMode": "value" },
      "targets": [
        {
          "expr": "stemedb_quarantine_pending",
          "legendFormat": "Pending"
        }
      ],
      "title": "Quarantine Pending",
      "type": "stat"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 1 },
              { "color": "red", "value": 3 }
            ]
          }
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 18, "y": 1 },
      "id": 5,
      "options": { "colorMode": "background", "graphMode": "none", "textMode": "value" },
      "targets": [
        {
          "expr": "stemedb_circuit_breakers_open",
          "legendFormat": "Open"
        }
      ],
      "title": "Circuit Breakers Open",
      "type": "stat"
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 },
      "id": 10,
      "title": "Query Performance",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": { "drawStyle": "line", "lineInterpolation": "smooth", "fillOpacity": 10 }
        },
        "overrides": [
          { "matcher": { "id": "byName", "options": "p99" }, "properties": [{ "id": "color", "value": { "fixedColor": "red", "mode": "fixed" } }] },
          { "matcher": { "id": "byName", "options": "p95" }, "properties": [{ "id": "color", "value": { "fixedColor": "orange", "mode": "fixed" } }] },
          { "matcher": { "id": "byName", "options": "p50" }, "properties": [{ "id": "color", "value": { "fixedColor": "green", "mode": "fixed" } }] }
        ]
      },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 6 },
      "id": 11,
      "options": { "tooltip": { "mode": "multi" } },
      "targets": [
        {
          "expr": "histogram_quantile(0.50, rate(stemedb_query_latency_seconds_bucket[5m]))",
          "legendFormat": "p50"
        },
        {
          "expr": "histogram_quantile(0.95, rate(stemedb_query_latency_seconds_bucket[5m]))",
          "legendFormat": "p95"
        },
        {
          "expr": "histogram_quantile(0.99, rate(stemedb_query_latency_seconds_bucket[5m]))",
          "legendFormat": "p99"
        }
      ],
      "title": "Query Latency (p50 / p95 / p99)",
      "type": "timeseries"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": { "drawStyle": "bars", "fillOpacity": 50, "stacking": { "mode": "normal" } }
        }
      },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 6 },
      "id": 12,
      "targets": [
        {
          "expr": "rate(stemedb_queries_total{endpoint=\"query\"}[5m])",
          "legendFormat": "query"
        },
        {
          "expr": "rate(stemedb_queries_total{endpoint=\"skeptic\"}[5m])",
          "legendFormat": "skeptic"
        },
        {
          "expr": "rate(stemedb_queries_total{endpoint=\"layered\"}[5m])",
          "legendFormat": "layered"
        },
        {
          "expr": "rate(stemedb_queries_total{endpoint=\"constraints\"}[5m])",
          "legendFormat": "constraints"
        }
      ],
      "title": "Queries by Endpoint",
      "type": "timeseries"
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 14 },
      "id": 20,
      "title": "Cluster Health",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "custom": { "drawStyle": "line", "fillOpacity": 10 }
        }
      },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 15 },
      "id": 21,
      "targets": [
        {
          "expr": "stemedb_cluster_nodes_alive",
          "legendFormat": "Alive"
        },
        {
          "expr": "stemedb_cluster_nodes_suspect",
          "legendFormat": "Suspect"
        },
        {
          "expr": "stemedb_cluster_nodes_total",
          "legendFormat": "Total"
        }
      ],
      "title": "Cluster Node Counts",
      "type": "timeseries"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": { "drawStyle": "line", "fillOpacity": 10 }
        }
      },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 15 },
      "id": 22,
      "targets": [
        {
          "expr": "stemedb_sync_lag_seconds",
          "legendFormat": "{{ peer }}"
        }
      ],
      "title": "Sync Lag by Peer",
      "type": "timeseries"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": { "drawStyle": "line", "fillOpacity": 10 }
        }
      },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 15 },
      "id": 23,
      "targets": [
        {
          "expr": "histogram_quantile(0.95, rate(stemedb_convergence_latency_seconds_bucket[5m]))",
          "legendFormat": "p95 convergence"
        }
      ],
      "title": "Convergence Latency (p95)",
      "type": "timeseries"
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 23 },
      "id": 30,
      "title": "Write Path",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": { "drawStyle": "line", "fillOpacity": 20 }
        }
      },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 24 },
      "id": 31,
      "targets": [
        {
          "expr": "rate(stemedb_assertions_ingested_total[5m])",
          "legendFormat": "Assertions ingested/sec"
        }
      ],
      "title": "Assertion Ingestion Rate",
      "type": "timeseries"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": { "drawStyle": "line", "fillOpacity": 20 }
        }
      },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 24 },
      "id": 32,
      "targets": [
        {
          "expr": "rate(stemedb_assertions_synced_total[5m])",
          "legendFormat": "{{ peer }}"
        }
      ],
      "title": "Sync Throughput by Peer",
      "type": "timeseries"
    }
  ],
  "schemaVersion": 39,
  "tags": ["stemedb", "episteme"],
  "templating": { "list": [] },
  "time": { "from": "now-1h", "to": "now" },
  "timepicker": {},
  "timezone": "browser",
  "title": "StemeDB Overview",
  "uid": "stemedb-overview",
  "version": 1
}
