Skip to main content

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

Counter
Labels: provider, status (initiated/success/failure)Total number of OAuth authorization flows by provider and outcome.
Histogram
Labels: provider, statusBuckets: 0.5s, 1s, 2s, 5s, 10s, 30s, 60sOAuth flow duration from initiation to token storage.

Token Refresh Metrics

Counter
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.
Histogram
Labels: statusBuckets: 0.1s, 0.5s, 1s, 2s, 5s, 10sToken refresh operation duration.
Counter
Labels: reason (reuse_detected/manual/expired/security)Total number of token revocations.
Gauge
Current number of active, unexpired OAuth tokens.

PKCE Metrics

Counter
Labels: status (success/failure), reason (valid/expired/invalid_hash/not_found)Total PKCE state validations.
Counter
Total number of PKCE states created.
Counter
Labels: reason (expired/manual/server_deleted)Total number of PKCE states cleaned up.
Gauge
Current number of active PKCE states.

Security Metrics

Counter
Labels: event_type, severity (low/medium/high/critical)Event Types: token_reuse, integrity_violation, code_injectionTotal security events.
Counter
Labels: violation_type (hash_mismatch/state_reuse/user_mismatch)Total OAuth integrity violations.
Counter
Authorization code injection attempts detected.

Discovery Metrics

Counter
Labels: method (rfc9728/www-authenticate/manual), statusOAuth metadata discovery attempts.
Histogram
Labels: method, statusBuckets: 0.5s, 1s, 2s, 5s, 10sDiscovery operation duration.

Client Registration Metrics

Counter
Labels: status (success/failure)Dynamic client registration attempts (RFC 7591).
Histogram
Labels: statusBuckets: 0.5s, 1s, 2s, 5s, 10sClient registration operation duration.

Common PromQL Queries

Health & SLO Monitoring

OAuth Flow Success Rate (SLO: >95%):
Token Refresh Success Rate (SLO: >99%):
PKCE Validation Success Rate (SLO: >98%):

Performance Monitoring

OAuth Flow p50/p95/p99 Duration:
Token Refresh p95 Duration (Alert if >2s):
Slow OAuth Flows (>10s):

Security Monitoring

Token Reuse Detection (Critical Alert):
Code Injection Attempts (Critical Alert):
Integrity Violations (High Alert):
High Security Event Rate (>10/min):

Capacity Planning

OAuth Flow Rate (flows/second):
Token Refresh Rate (refreshes/second):
PKCE State Creation Rate (states/second):
Active Token Growth Rate:

Error Analysis

Top Refresh Failure Reasons:
Top PKCE Validation Failure Reasons:
OAuth Flow Failures by Provider:

Recording Rules

Add to Prometheus config for pre-computed queries:

Alert Rules

Grafana Dashboard Queries

Panel: OAuth Flow Success Rate

Query:
Settings:
  • Type: Gauge
  • Min: 0
  • Max: 100
  • Unit: Percent
  • Thresholds: Red <95%, Yellow 95-98%, Green >98%

Panel: Token Refresh Duration (p50, p95, p99)

Queries:
Settings:
  • Type: Time series
  • Unit: Seconds
  • Legend: p50, p95, p99

Panel: Security Events Timeline

Query:
Settings:
  • Type: Bar chart
  • Stacking: Normal
  • Color scheme by severity

Panel: OAuth Operations Rate

Queries:
Settings:
  • Type: Time series
  • Unit: ops/min
  • Legend: Flows, Refreshes, PKCE

Troubleshooting

Ensure metrics route is configured in Next.js:
Check Prometheus config:
Adjust buckets in oauth-metrics.ts:
Avoid user IDs or UUIDs in metric labels. Use bounded values only:
  • ✅ provider (limited set)
  • ✅ status (success/failure)
  • ❌ userId (unbounded)
  • ❌ serverUuid (unbounded)

Next Steps

Logs & LogQL

Combine metrics with log analysis

Grafana Dashboards

Build comprehensive dashboards