{
  "dashboard": {
    "title": "StemeDB - Cluster Overview",
    "tags": ["stemedb", "cluster", "distributed"],
    "timezone": "browser",
    "panels": [
      {
        "id": 1,
        "title": "Node Status",
        "type": "stat",
        "targets": [
          {
            "expr": "stemedb_cluster_nodes_alive",
            "legendFormat": "Alive"
          },
          {
            "expr": "stemedb_cluster_nodes_suspect",
            "legendFormat": "Suspect"
          },
          {
            "expr": "stemedb_cluster_nodes_dead",
            "legendFormat": "Dead"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "unit": "short",
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "green"},
                {"value": 1, "color": "red"}
              ]
            }
          }
        },
        "gridPos": {"h": 8, "w": 8, "x": 0, "y": 0}
      },
      {
        "id": 2,
        "title": "Replication Lag (by peer)",
        "type": "graph",
        "targets": [
          {
            "expr": "stemedb_sync_lag_seconds",
            "legendFormat": "{{peer_id}}"
          }
        ],
        "yaxes": [
          {"format": "s", "label": "Lag"},
          {"format": "short"}
        ],
        "gridPos": {"h": 8, "w": 16, "x": 8, "y": 0},
        "alert": {
          "conditions": [
            {
              "evaluator": {"params": [300], "type": "gt"},
              "operator": {"type": "and"},
              "query": {"params": ["A", "5m", "now"]},
              "reducer": {"type": "avg"}
            }
          ],
          "name": "High Replication Lag"
        }
      },
      {
        "id": 3,
        "title": "Sync Operations/sec",
        "type": "graph",
        "targets": [
          {
            "expr": "rate(stemedb_sync_operations_total[5m])",
            "legendFormat": "{{operation}}"
          }
        ],
        "yaxes": [
          {"format": "ops", "label": "Operations/sec"},
          {"format": "short"}
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}
      },
      {
        "id": 4,
        "title": "Merkle Diff Size (by peer)",
        "type": "graph",
        "targets": [
          {
            "expr": "stemedb_merkle_diff_size",
            "legendFormat": "{{peer_id}}"
          }
        ],
        "yaxes": [
          {"format": "short", "label": "Diff Size"},
          {"format": "short"}
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}
      },
      {
        "id": 5,
        "title": "Cluster Convergence State",
        "type": "gauge",
        "targets": [
          {
            "expr": "stemedb_cluster_convergence_ratio",
            "legendFormat": "Convergence %"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "unit": "percentunit",
            "min": 0,
            "max": 1,
            "thresholds": {
              "mode": "percentage",
              "steps": [
                {"value": 0, "color": "red"},
                {"value": 0.9, "color": "yellow"},
                {"value": 0.99, "color": "green"}
              ]
            }
          }
        },
        "gridPos": {"h": 8, "w": 8, "x": 0, "y": 16}
      },
      {
        "id": 6,
        "title": "Gossip Message Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "rate(stemedb_gossip_messages_sent_total[5m])",
            "legendFormat": "Sent"
          },
          {
            "expr": "rate(stemedb_gossip_messages_received_total[5m])",
            "legendFormat": "Received"
          }
        ],
        "yaxes": [
          {"format": "msgs", "label": "Messages/sec"},
          {"format": "short"}
        ],
        "gridPos": {"h": 8, "w": 16, "x": 8, "y": 16}
      }
    ],
    "refresh": "10s",
    "schemaVersion": 30,
    "version": 1
  }
}
