{
  "uid": "nexus-postgresql",
  "title": "Nexus — PostgreSQL",
  "tags": ["postgres", "database"],
  "timezone": "browser",
  "schemaVersion": 36,
  "refresh": "30s",
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "templating": {
    "list": [
      {
        "name": "datasource",
        "type": "datasource",
        "query": "prometheus",
        "current": {
          "selected": false,
          "text": "Prometheus",
          "value": "Prometheus"
        }
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "title": "Active Connections",
      "type": "timeseries",
      "gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "targets": [
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "pg_stat_activity_count",
          "legendFormat": "Connections",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "custom": {"drawStyle": "line", "lineWidth": 2, "fillOpacity": 10},
          "unit": "short",
          "min": 0
        },
        "overrides": []
      }
    },
    {
      "id": 2,
      "title": "Transactions / sec",
      "type": "timeseries",
      "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "targets": [
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "rate(pg_stat_database_xact_commit[5m])",
          "legendFormat": "Commits",
          "refId": "A"
        },
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "rate(pg_stat_database_xact_rollback[5m])",
          "legendFormat": "Rollbacks",
          "refId": "B"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "custom": {"drawStyle": "line", "lineWidth": 2, "fillOpacity": 10},
          "unit": "tps",
          "min": 0
        },
        "overrides": []
      }
    },
    {
      "id": 3,
      "title": "Cache Hit Ratio",
      "type": "timeseries",
      "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "targets": [
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "pg_stat_database_blks_hit / (pg_stat_database_blks_hit + pg_stat_database_blks_read)",
          "legendFormat": "Hit Ratio",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "custom": {"drawStyle": "line", "lineWidth": 2, "fillOpacity": 10},
          "unit": "percentunit",
          "min": 0,
          "max": 1
        },
        "overrides": []
      }
    },
    {
      "id": 4,
      "title": "WAL Generation",
      "type": "timeseries",
      "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8},
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "targets": [
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "rate(pg_stat_bgwriter_buffers_backend_fsync[5m])",
          "legendFormat": "Backend fsync",
          "refId": "A"
        },
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "rate(pg_stat_bgwriter_buffers_backend[5m])",
          "legendFormat": "Backend buffers",
          "refId": "B"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "custom": {"drawStyle": "line", "lineWidth": 2, "fillOpacity": 10},
          "unit": "ops",
          "min": 0
        },
        "overrides": []
      }
    },
    {
      "id": 5,
      "title": "Slow Queries",
      "type": "timeseries",
      "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16},
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "targets": [
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "pg_stat_activity_count{state=\"active\"}",
          "legendFormat": "Active queries",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "custom": {"drawStyle": "line", "lineWidth": 2, "fillOpacity": 10},
          "unit": "short",
          "min": 0
        },
        "overrides": []
      }
    },
    {
      "id": 6,
      "title": "Table Bloat",
      "type": "timeseries",
      "gridPos": {"h": 8, "w": 12, "x": 12, "y": 16},
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "targets": [
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "pg_stat_user_tables_n_live_tup",
          "legendFormat": "Live tuples",
          "refId": "A"
        },
        {
          "datasource": {"type": "prometheus", "uid": "${datasource}"},
          "expr": "pg_stat_user_tables_n_dead_tup",
          "legendFormat": "Dead tuples",
          "refId": "B"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "custom": {"drawStyle": "line", "lineWidth": 2, "fillOpacity": 10},
          "unit": "short",
          "min": 0
        },
        "overrides": []
      }
    }
  ]
}
