{
  "title": "StellaOps Authority - Token & Access Monitoring",
  "uid": "authority-token-monitoring",
  "schemaVersion": 38,
  "version": 1,
  "editable": true,
  "timezone": "",
  "graphTooltip": 0,
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "templating": {
    "list": [
      {
        "name": "datasource",
        "type": "datasource",
        "query": "prometheus",
        "refresh": 1,
        "hide": 0,
        "current": {}
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "title": "Token Requests – Success vs Failure",
      "type": "timeseries",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "req/s",
          "displayName": "{{grant_type}} ({{status}})"
        },
        "overrides": []
      },
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (grant_type, status) (rate(http_server_duration_seconds_count{service_name=\"stellaops-authority\", http_route=\"/token\"}[5m]))",
          "legendFormat": "{{grant_type}} {{status}}"
        }
      ],
      "options": {
        "legend": {
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      }
    },
    {
      "id": 2,
      "title": "Rate Limiter Rejections",
      "type": "timeseries",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "req/s",
          "displayName": "{{limiter}}"
        },
        "overrides": []
      },
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (limiter) (rate(aspnetcore_rate_limiting_rejections_total{service_name=\"stellaops-authority\"}[5m]))",
          "legendFormat": "{{limiter}}"
        }
      ]
    },
    {
      "id": 3,
      "title": "Bypass Events (5m)",
      "type": "stat",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": {
            "mode": "thresholds"
          },
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 1 },
              { "color": "red", "value": 5 }
            ]
          }
        },
        "overrides": []
      },
      "targets": [
        {
          "refId": "A",
          "expr": "sum(rate(log_messages_total{message_template=\"Granting StellaOps bypass for remote {RemoteIp}; required scopes {RequiredScopes}.\"}[5m]))"
        }
      ],
      "options": {
        "reduceOptions": {
          "calcs": ["last"],
          "fields": "",
          "values": false
        },
        "orientation": "horizontal",
        "textMode": "auto"
      }
    },
    {
      "id": 4,
      "title": "Lockout Events (15m)",
      "type": "stat",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": {
            "mode": "thresholds"
          },
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 5 },
              { "color": "red", "value": 10 }
            ]
          }
        },
        "overrides": []
      },
      "targets": [
        {
          "refId": "A",
          "expr": "sum(rate(log_messages_total{message_template=\"Plugin {PluginName} denied access for {Username} due to lockout (retry after {RetryAfter}).\"}[15m]))"
        }
      ],
      "options": {
        "reduceOptions": {
          "calcs": ["last"],
          "fields": "",
          "values": false
        },
        "orientation": "horizontal",
        "textMode": "auto"
      }
    },
    {
      "id": 5,
      "title": "Trace Explorer Shortcut",
      "type": "text",
      "options": {
        "mode": "markdown",
        "content": "[Open Trace Explorer](#/explore?left={\"datasource\":\"tempo\",\"queries\":[{\"query\":\"{service.name=\\\"stellaops-authority\\\", span_name=~\\\"authority.token.*\\\"}\",\"refId\":\"A\"}]})"
      }
    }
  ],
  "links": []
}
