OAuth Metrics & PromQL Queries
Plugged.in exposes 17 Prometheus metrics for comprehensive OAuth 2.1 monitoring, covering flows, tokens, PKCE, security, and discovery operations.Metrics Endpoint
Available Metrics
OAuth Flow Metrics
Labels:
provider, status (initiated/success/failure)Total number of OAuth authorization flows by provider and outcome.Labels:
provider, statusBuckets: 0.5s, 1s, 2s, 5s, 10s, 30s, 60sOAuth flow duration from initiation to token storage.Token Refresh Metrics
Labels:
status (success/failure/reuse_detected), reasonReasons: normal, no_refresh_token, no_record, ownership_failed, reuse_detected, exceptionTotal token refresh attempts with outcome and reason.Labels:
statusBuckets: 0.1s, 0.5s, 1s, 2s, 5s, 10sToken refresh operation duration.Labels:
reason (reuse_detected/manual/expired/security)Total number of token revocations.Current number of active, unexpired OAuth tokens.
PKCE Metrics
Labels:
status (success/failure), reason (valid/expired/invalid_hash/not_found)Total PKCE state validations.Total number of PKCE states created.
Labels:
reason (expired/manual/server_deleted)Total number of PKCE states cleaned up.Current number of active PKCE states.
Security Metrics
Labels:
event_type, severity (low/medium/high/critical)Event Types: token_reuse, integrity_violation, code_injectionTotal security events.Labels:
violation_type (hash_mismatch/state_reuse/user_mismatch)Total OAuth integrity violations.Authorization code injection attempts detected.
Discovery Metrics
Labels:
method (rfc9728/www-authenticate/manual), statusOAuth metadata discovery attempts.Labels:
method, statusBuckets: 0.5s, 1s, 2s, 5s, 10sDiscovery operation duration.Client Registration Metrics
Labels:
status (success/failure)Dynamic client registration attempts (RFC 7591).Labels:
statusBuckets: 0.5s, 1s, 2s, 5s, 10sClient registration operation duration.Common PromQL Queries
Health & SLO Monitoring
OAuth Flow Success Rate (SLO: >95%):Performance Monitoring
OAuth Flow p50/p95/p99 Duration:Security Monitoring
Token Reuse Detection (Critical Alert):Capacity Planning
OAuth Flow Rate (flows/second):Error Analysis
Top Refresh Failure Reasons:Recording Rules
Add to Prometheus config for pre-computed queries:Alert Rules
Grafana Dashboard Queries
Panel: OAuth Flow Success Rate
Query:- Type: Gauge
- Min: 0
- Max: 100
- Unit: Percent
- Thresholds: Red <95%, Yellow 95-98%, Green >98%
Panel: Token Refresh Duration (p50, p95, p99)
Queries:- Type: Time series
- Unit: Seconds
- Legend: p50, p95, p99
Panel: Security Events Timeline
Query:- Type: Bar chart
- Stacking: Normal
- Color scheme by severity
Panel: OAuth Operations Rate
Queries:- Type: Time series
- Unit: ops/min
- Legend: Flows, Refreshes, PKCE
Troubleshooting
Metrics endpoint returns 404
Metrics endpoint returns 404
Ensure metrics route is configured in Next.js:
Prometheus can't scrape metrics
Prometheus can't scrape metrics
Check Prometheus config:
Histogram buckets not appropriate
Histogram buckets not appropriate
Adjust buckets in oauth-metrics.ts:
High cardinality warnings
High cardinality warnings
Avoid user IDs or UUIDs in metric labels. Use bounded values only:
- ✅ provider (limited set)
- ✅ status (success/failure)
- ❌ userId (unbounded)
- ❌ serverUuid (unbounded)

