{
  "dashboard": {
    "title": "DBIS Core - Ledger Operations",
    "tags": ["ledger", "transactions", "settlement"],
    "timezone": "browser",
    "schemaVersion": 27,
    "version": 1,
    "refresh": "30s",
    "panels": [
      {
        "id": 1,
        "title": "Ledger Entry Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(ledger_entries_total[5m])) by (ledger_id)",
            "legendFormat": "{{ledger_id}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 0}
      },
      {
        "id": 2,
        "title": "Ledger Entry Amount by Ledger",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(ledger_entry_amount_total[5m])) by (ledger_id, currency_code)",
            "legendFormat": "{{ledger_id}} - {{currency_code}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0}
      },
      {
        "id": 3,
        "title": "Settlement Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(settlement_total[5m])) by (status)",
            "legendFormat": "{{status}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}
      },
      {
        "id": 4,
        "title": "Settlement Duration",
        "type": "graph",
        "targets": [
          {
            "expr": "histogram_quantile(0.50, sum(rate(settlement_duration_seconds_bucket[5m])) by (le))",
            "legendFormat": "P50"
          },
          {
            "expr": "histogram_quantile(0.95, sum(rate(settlement_duration_seconds_bucket[5m])) by (le))",
            "legendFormat": "P95"
          },
          {
            "expr": "histogram_quantile(0.99, sum(rate(settlement_duration_seconds_bucket[5m])) by (le))",
            "legendFormat": "P99"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}
      },
      {
        "id": 5,
        "title": "Outbox Queue Status",
        "type": "graph",
        "targets": [
          {
            "expr": "dbis_outbox_queue_length",
            "legendFormat": "Queue Length"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16}
      },
      {
        "id": 6,
        "title": "Outbox Processing Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(outbox_processed_total[5m])) by (status)",
            "legendFormat": "{{status}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 16}
      },
      {
        "id": 7,
        "title": "Balance Updates",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(balance_updates_total[5m])) by (currency_code)",
            "legendFormat": "{{currency_code}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 24}
      },
      {
        "id": 8,
        "title": "Failed Posting Operations",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(ledger_posting_errors_total[5m])) by (error_type)",
            "legendFormat": "{{error_type}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 24}
      },
      {
        "id": 9,
        "title": "Total Ledger Entries",
        "type": "stat",
        "targets": [
          {
            "expr": "ledger_entries_count",
            "legendFormat": "Total Entries"
          }
        ],
        "gridPos": {"h": 4, "w": 6, "x": 0, "y": 32}
      },
      {
        "id": 10,
        "title": "Active Accounts",
        "type": "stat",
        "targets": [
          {
            "expr": "bank_accounts_count",
            "legendFormat": "Active Accounts"
          }
        ],
        "gridPos": {"h": 4, "w": 6, "x": 6, "y": 32}
      },
      {
        "id": 11,
        "title": "Pending Settlements",
        "type": "stat",
        "targets": [
          {
            "expr": "settlements_pending_count",
            "legendFormat": "Pending"
          }
        ],
        "gridPos": {"h": 4, "w": 6, "x": 12, "y": 32}
      },
      {
        "id": 12,
        "title": "Successful Settlements (24h)",
        "type": "stat",
        "targets": [
          {
            "expr": "increase(settlement_total{status=\"SETTLED\"}[24h])",
            "legendFormat": "Successful"
          }
        ],
        "gridPos": {"h": 4, "w": 6, "x": 18, "y": 32}
      }
    ]
  }
}
