{
  "dashboard": {
    "id": null,
    "uid": "mockupaws-database",
    "title": "mockupAWS - Database",
    "tags": ["mockupaws", "database", "postgresql"],
    "timezone": "UTC",
    "schemaVersion": 36,
    "version": 1,
    "refresh": "30s",
    "panels": [
      {
        "id": 1,
        "title": "PostgreSQL Status",
        "type": "stat",
        "targets": [
          {
            "expr": "pg_up",
            "legendFormat": "Status",
            "refId": "A"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "mappings": [
              {"options": {"0": {"text": "Down", "color": "red"}}, "type": "value"},
              {"options": {"1": {"text": "Up", "color": "green"}}, "type": "value"}
            ]
          }
        },
        "gridPos": {"h": 4, "w": 6, "x": 0, "y": 0}
      },
      {
        "id": 2,
        "title": "Active Connections",
        "type": "stat",
        "targets": [
          {
            "expr": "pg_stat_activity_count{state=\"active\"}",
            "legendFormat": "Active",
            "refId": "A"
          },
          {
            "expr": "pg_stat_activity_count{state=\"idle\"}",
            "legendFormat": "Idle",
            "refId": "B"
          }
        ],
        "gridPos": {"h": 4, "w": 6, "x": 6, "y": 0}
      },
      {
        "id": 3,
        "title": "Connection Usage %",
        "type": "gauge",
        "targets": [
          {
            "expr": "pg_stat_activity_count / pg_settings_max_connections * 100",
            "legendFormat": "Usage %",
            "refId": "A"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "unit": "percent",
            "min": 0,
            "max": 100,
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"color": "green", "value": null},
                {"color": "yellow", "value": 70},
                {"color": "red", "value": 90}
              ]
            }
          }
        },
        "gridPos": {"h": 4, "w": 6, "x": 12, "y": 0}
      },
      {
        "id": 4,
        "title": "Database Size",
        "type": "stat",
        "targets": [
          {
            "expr": "pg_database_size_bytes / 1024 / 1024 / 1024",
            "legendFormat": "Size GB",
            "refId": "A"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "unit": "decgbytes"
          }
        },
        "gridPos": {"h": 4, "w": 6, "x": 18, "y": 0}
      },
      {
        "id": 5,
        "title": "Connections Over Time",
        "type": "timeseries",
        "targets": [
          {
            "expr": "pg_stat_activity_count{state=\"active\"}",
            "legendFormat": "Active",
            "refId": "A"
          },
          {
            "expr": "pg_stat_activity_count{state=\"idle\"}",
            "legendFormat": "Idle",
            "refId": "B"
          },
          {
            "expr": "pg_stat_activity_count{state=\"idle in transaction\"}",
            "legendFormat": "Idle in Transaction",
            "refId": "C"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 4}
      },
      {
        "id": 6,
        "title": "Transaction Rate",
        "type": "timeseries",
        "targets": [
          {
            "expr": "rate(pg_stat_database_xact_commit[5m])",
            "legendFormat": "Commits/sec",
            "refId": "A"
          },
          {
            "expr": "rate(pg_stat_database_xact_rollback[5m])",
            "legendFormat": "Rollbacks/sec",
            "refId": "B"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 4}
      },
      {
        "id": 7,
        "title": "Query Performance",
        "type": "timeseries",
        "targets": [
          {
            "expr": "rate(pg_stat_statements_total_time[5m]) / rate(pg_stat_statements_calls[5m])",
            "legendFormat": "Avg Query Time (ms)",
            "refId": "A"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "unit": "ms"
          }
        },
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 12}
      },
      {
        "id": 8,
        "title": "Slowest Queries",
        "type": "table",
        "targets": [
          {
            "expr": "topk(10, pg_stat_statements_mean_time)",
            "format": "table",
            "instant": true,
            "refId": "A"
          }
        ],
        "transformations": [
          {
            "id": "organize",
            "options": {
              "excludeByName": {
                "Time": true
              },
              "renameByName": {
                "query": "Query",
                "Value": "Mean Time (ms)"
              }
            }
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 12}
      },
      {
        "id": 9,
        "title": "Cache Hit Ratio",
        "type": "timeseries",
        "targets": [
          {
            "expr": "pg_stat_database_blks_hit / (pg_stat_database_blks_hit + pg_stat_database_blks_read) * 100",
            "legendFormat": "Cache Hit Ratio %",
            "refId": "A"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "unit": "percent",
            "min": 0,
            "max": 100,
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"color": "red", "value": null},
                {"color": "yellow", "value": 95},
                {"color": "green", "value": 99}
              ]
            }
          }
        },
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 20}
      },
      {
        "id": 10,
        "title": "Table Bloat",
        "type": "table",
        "targets": [
          {
            "expr": "pg_stat_user_tables_n_dead_tup",
            "format": "table",
            "instant": true,
            "refId": "A"
          }
        ],
        "transformations": [
          {
            "id": "organize",
            "options": {
              "excludeByName": {
                "Time": true
              },
              "renameByName": {
                "relname": "Table",
                "Value": "Dead Tuples"
              }
            }
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 20}
      }
    ]
  }
}
