{
  "annotations": {
    "list": []
  },
  "description": "Posit Connect OpenTelemetry operational dashboard. Queries sourced from the Connect OTel documentation.",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "links": [],
  "panels": [
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 },
      "id": 1,
      "title": "Health overview",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": null },
              { "color": "green", "value": 1 }
            ]
          },
          "mappings": [
            { "options": { "0": { "text": "DOWN" } }, "type": "value" }
          ]
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 0, "y": 1 },
      "id": 2,
      "options": { "colorMode": "background", "graphMode": "none", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "Service health (core DB pool)",
      "type": "stat",
      "targets": [
        { "expr": "sum by(pool_name) (db_sql_connection_open{pool_name=\"core\",service_namespace=~\"$service_namespace\"})", "legendFormat": "{{pool_name}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 70 },
              { "color": "red", "value": 90 }
            ]
          }
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 6, "y": 1 },
      "id": 3,
      "options": { "colorMode": "background", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "DB connection pool utilization",
      "type": "stat",
      "targets": [
        { "expr": "(db_sql_connection_open{status=\"inuse\",service_namespace=~\"$service_namespace\"} / db_sql_connection_max_open{service_namespace=~\"$service_namespace\"}) * 100", "legendFormat": "{{pool_name}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "red", "value": 1 }
            ]
          }
        }
      },
      "gridPos": { "h": 4, "w": 6, "x": 12, "y": 1 },
      "id": 4,
      "options": { "colorMode": "background", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "Scheduled report failures",
      "type": "stat",
      "targets": [
        { "expr": "schedule_count{schedule_status=\"failure\",service_namespace=~\"$service_namespace\"}", "legendFormat": "failures" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 4, "w": 6, "x": 18, "y": 1 },
      "id": 5,
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "Running applications",
      "type": "stat",
      "targets": [
        { "expr": "application_count{service_namespace=~\"$service_namespace\"}", "legendFormat": "applications" }
      ]
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 },
      "id": 10,
      "title": "Performance investigation",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "unit": "ms",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 50 },
              { "color": "red", "value": 200 }
            ]
          },
          "custom": { "thresholdsStyle": { "mode": "line" } }
        }
      },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 6 },
      "id": 11,
      "title": "DB connection wait time (avg per request)",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(db_sql_connection_wait_duration_milliseconds_total{pool_name=\"core\",service_namespace=~\"$service_namespace\"}[5m])\n  / rate(db_sql_connection_wait_total{pool_name=\"core\",service_namespace=~\"$service_namespace\"}[5m])", "legendFormat": "avg wait (core)" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "ms", "custom": { "scaleDistribution": { "type": "log", "log": 2 } } } },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 6 },
      "id": 12,
      "title": "DB query latency",
      "type": "heatmap",
      "options": { "calculate": false, "yAxis": { "unit": "ms" } },
      "targets": [
        { "expr": "rate(db_sql_latency_milliseconds_bucket{service_namespace=~\"$service_namespace\"}[$__rate_interval])", "legendFormat": "{{le}}", "format": "heatmap" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "s" } },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 6 },
      "id": 13,
      "title": "API endpoint performance (P95)",
      "type": "timeseries",
      "targets": [
        { "expr": "histogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket{service_namespace=~\"$service_namespace\"}[5m])))", "legendFormat": "{{http_route}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 14 },
      "id": 14,
      "title": "Launcher retry exhaustion",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(launcher_client_retry_exhausted_total{service_namespace=~\"$service_namespace\"}[5m])", "legendFormat": "exhausted retries/s" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 14 },
      "id": 15,
      "title": "Running processes by type",
      "type": "timeseries",
      "targets": [
        { "expr": "sum by (process_tag) (process_count{service_namespace=~\"$service_namespace\"})", "legendFormat": "{{process_tag}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 14 },
      "id": 16,
      "title": "Running applications by type",
      "type": "timeseries",
      "targets": [
        { "expr": "sum by (application_type) (application_count{service_namespace=~\"$service_namespace\"})", "legendFormat": "{{application_type}}" }
      ]
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 22 },
      "id": 20,
      "title": "Job queue operations",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 23 },
      "id": 21,
      "title": "Job completions by status",
      "type": "timeseries",
      "options": { "tooltip": { "mode": "multi" } },
      "fieldConfig": { "defaults": { "custom": { "stacking": { "mode": "normal" } } } },
      "targets": [
        { "expr": "sum by (job_status) (increase(job_duration_seconds_count{service_namespace=~\"$service_namespace\"}[5m]))", "legendFormat": "{{job_status}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 23 },
      "id": 22,
      "title": "Worker pool utilization",
      "type": "timeseries",
      "fieldConfig": { "defaults": { "unit": "percentunit", "max": 1 } },
      "targets": [
        { "expr": "avg by (application_type) (worker_pool_utilization{service_namespace=~\"$service_namespace\"})", "legendFormat": "{{application_type}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 23 },
      "id": 23,
      "title": "Job timeouts",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(job_timeout_total{service_namespace=~\"$service_namespace\"}[5m])", "legendFormat": "timeouts/s" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "s" } },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 31 },
      "id": 24,
      "title": "Job duration percentiles",
      "type": "timeseries",
      "targets": [
        { "expr": "histogram_quantile(0.50, rate(job_duration_seconds_bucket{job_status=\"success\",service_namespace=~\"$service_namespace\"}[1h]))", "legendFormat": "P50" },
        { "expr": "histogram_quantile(0.95, rate(job_duration_seconds_bucket{job_status=\"success\",service_namespace=~\"$service_namespace\"}[1h]))", "legendFormat": "P95" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 31 },
      "id": 25,
      "title": "Queue size by queue",
      "type": "timeseries",
      "targets": [
        { "expr": "max by (queue_name) (queue_items_size{service_namespace=~\"$service_namespace\"})", "legendFormat": "{{queue_name}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "s" } },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 31 },
      "id": 26,
      "title": "Queue age by queue",
      "type": "timeseries",
      "targets": [
        { "expr": "max by (queue_name) (queue_items_age_seconds{service_namespace=~\"$service_namespace\"})", "legendFormat": "{{queue_name}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "s" } },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 39 },
      "id": 27,
      "title": "Queue drain time (estimated)",
      "type": "timeseries",
      "targets": [
        { "expr": "max(queue_items_size{service_namespace=~\"$service_namespace\"}) / clamp_min(sum(rate(job_duration_seconds_count{service_namespace=~\"$service_namespace\"}[5m])), 0.0001)", "legendFormat": "drain time" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "s" } },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 39 },
      "id": 28,
      "title": "Oldest in-flight job duration",
      "type": "timeseries",
      "targets": [
        { "expr": "queue_items_active_duration_seconds{queue_name=\"default\",service_namespace=~\"$service_namespace\"}", "legendFormat": "{{queue_name}}" }
      ]
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 47 },
      "id": 30,
      "title": "Content operations",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 48 },
      "id": 31,
      "title": "Job throughput",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(job_completion_total{service_namespace=~\"$service_namespace\"}[5m])", "legendFormat": "completions/s" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "s" } },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 48 },
      "id": 32,
      "title": "Job duration P95",
      "type": "timeseries",
      "targets": [
        { "expr": "histogram_quantile(0.95, rate(job_duration_seconds_bucket{service_namespace=~\"$service_namespace\"}[5m]))", "legendFormat": "P95" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "percent" } },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 48 },
      "id": 33,
      "title": "Job failure ratio",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(job_completion_total{job_status=\"failure\",service_namespace=~\"$service_namespace\"}[5m]) / rate(job_completion_total{service_namespace=~\"$service_namespace\"}[5m]) * 100", "legendFormat": "failure %" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 56 },
      "id": 34,
      "title": "Job failure rate",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(job_completion_total{job_status=\"failure\",service_namespace=~\"$service_namespace\"}[5m])", "legendFormat": "failures/s" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 56 },
      "id": 35,
      "title": "Queue item failures by queue",
      "type": "timeseries",
      "targets": [
        { "expr": "sum by (queue_name) (rate(queue_items_completed_total{job_status=\"failure\",service_namespace=~\"$service_namespace\"}[5m]))", "legendFormat": "{{queue_name}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 56 },
      "id": 36,
      "title": "Failures by exit code",
      "type": "timeseries",
      "fieldConfig": { "defaults": { "custom": { "stacking": { "mode": "normal" } } } },
      "targets": [
        { "expr": "sum by (job_exit_code) (job_completion_total{job_status=\"failure\",service_namespace=~\"$service_namespace\"})", "legendFormat": "exit {{job_exit_code}}" }
      ]
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 64 },
      "id": 40,
      "title": "License capacity",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 70 },
              { "color": "orange", "value": 80 },
              { "color": "red", "value": 90 }
            ]
          }
        }
      },
      "gridPos": { "h": 6, "w": 8, "x": 0, "y": 65 },
      "id": 41,
      "options": { "colorMode": "background", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "Named user utilization",
      "type": "stat",
      "targets": [
        { "expr": "license_users_current{service_namespace=~\"$service_namespace\"} / license_users_limit{service_namespace=~\"$service_namespace\"} * 100", "legendFormat": "utilization" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 70 },
              { "color": "orange", "value": 80 },
              { "color": "red", "value": 90 }
            ]
          }
        }
      },
      "gridPos": { "h": 6, "w": 8, "x": 8, "y": 65 },
      "id": 42,
      "options": { "colorMode": "background", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "Concurrent Shiny user utilization",
      "type": "stat",
      "targets": [
        { "expr": "license_shiny_users_current{service_namespace=~\"$service_namespace\"} / license_shiny_users_limit{service_namespace=~\"$service_namespace\"} * 100", "legendFormat": "utilization" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "unit": "d",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": null },
              { "color": "orange", "value": 7 },
              { "color": "yellow", "value": 30 },
              { "color": "green", "value": 90 }
            ]
          }
        }
      },
      "gridPos": { "h": 6, "w": 8, "x": 16, "y": 65 },
      "id": 43,
      "options": { "colorMode": "background", "graphMode": "none", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "title": "License expiration",
      "type": "stat",
      "targets": [
        { "expr": "floor(license_expiration_days_remaining{service_namespace=~\"$service_namespace\"})", "legendFormat": "days remaining" }
      ]
    },
    {
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 71 },
      "id": 50,
      "title": "Request rejections",
      "type": "row"
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 6, "x": 0, "y": 72 },
      "id": 51,
      "title": "Total rejections",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(requests_rejected_total{service_namespace=~\"$service_namespace\"}[5m])", "legendFormat": "rejections/s" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 6, "x": 6, "y": 72 },
      "id": 52,
      "title": "Rejections by reason",
      "type": "timeseries",
      "targets": [
        { "expr": "sum by (rejection_reason) (rate(requests_rejected_total{service_namespace=~\"$service_namespace\"}[5m]))", "legendFormat": "{{rejection_reason}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "gridPos": { "h": 8, "w": 6, "x": 12, "y": 72 },
      "id": 53,
      "title": "Rejections by content type",
      "type": "timeseries",
      "targets": [
        { "expr": "sum by (rejection_type) (rate(requests_rejected_total{service_namespace=~\"$service_namespace\"}[5m]))", "legendFormat": "{{rejection_type}}" }
      ]
    },
    {
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": { "defaults": { "unit": "percent" } },
      "gridPos": { "h": 8, "w": 6, "x": 18, "y": 72 },
      "id": 54,
      "title": "Rejection rate (% of total)",
      "type": "timeseries",
      "targets": [
        { "expr": "rate(requests_rejected_total{service_namespace=~\"$service_namespace\"}[5m]) / rate(http_server_request_duration_seconds_count{service_namespace=~\"$service_namespace\"}[5m]) * 100", "legendFormat": "rejection %" }
      ]
    }
  ],
  "schemaVersion": 39,
  "tags": ["connect", "opentelemetry", "posit"],
  "templating": {
    "list": [
      {
        "current": { "selected": false, "text": "Prometheus", "value": "prometheus" },
        "hide": 0,
        "includeAll": false,
        "label": "Data Source",
        "multi": false,
        "name": "datasource",
        "options": [],
        "query": "prometheus",
        "refresh": 1,
        "regex": "",
        "type": "datasource"
      },
      {
        "current": { "selected": true, "text": "All", "value": "$__all" },
        "definition": "label_values(service_namespace)",
        "hide": 0,
        "includeAll": true,
        "label": "Service Namespace",
        "multi": true,
        "name": "service_namespace",
        "options": [],
        "query": { "qryType": 1, "query": "label_values(service_namespace)" },
        "refresh": 2,
        "regex": "",
        "type": "query"
      }
    ]
  },
  "time": { "from": "now-1h", "to": "now" },
  "title": "Posit Connect OpenTelemetry",
  "uid": "posit-connect-otel"
}
