Performance Monitoring
Sentinel automatically tracks per-route latency and throughput using lightweight middleware. Every HTTP request is measured — no manual instrumentation required. Metrics are aggregated in memory and exposed via API endpoints and the built-in dashboard.
Always On
PerformanceConfig to tune slow-request thresholds and retention.What Gets Tracked
The performance middleware captures the following data points for every request:
| Data Point | Description |
|---|---|
Duration | Total time from request received to response written, measured with time.Since. |
StatusCode | HTTP status code returned to the client. |
ResponseSize | Size of the response body in bytes. |
Method | HTTP method (GET, POST, etc.). |
Path | Request path, used for per-route aggregation. |
Configuration
Customize performance monitoring through PerformanceConfig. The only tunable field is the slow-request threshold — everything else works out of the box.
1import (2 "time"34 sentinel "github.com/MUKE-coder/sentinel"5 "github.com/gin-gonic/gin"6)78func main() {9 r := gin.Default()1011 sentinel.Mount(r, nil, sentinel.Config{12 Performance: sentinel.PerformanceConfig{13 SlowRequestThreshold: 2 * time.Second,14 },15 })1617 r.GET("/api/data", func(c *gin.Context) {18 c.JSON(200, gin.H{"status": "ok"})19 })2021 r.Run(":8080")22}
PerformanceConfig Reference
| Field | Type | Default | Description |
|---|---|---|---|
SlowRequestThreshold | time.Duration | 1 * time.Second | Requests exceeding this duration are flagged as slow in metrics and the dashboard. |
Metrics
Sentinel computes the following aggregate metrics from collected request data. Metrics are maintained per route and system-wide.
| Metric | Scope | Description |
|---|---|---|
p50 | Per-route / Global | Median latency — 50th percentile of request durations. |
p95 | Per-route / Global | 95th percentile latency — captures tail performance. |
p99 | Per-route / Global | 99th percentile latency — worst-case excluding extreme outliers. |
errorRate | Per-route / Global | Percentage of requests returning 5xx status codes. |
throughput | Per-route / Global | Requests per second over the most recent measurement window. |
avgResponseSize | Per-route | Average response body size in bytes. |
slowRequests | Per-route / Global | Count of requests exceeding SlowRequestThreshold. |
API Endpoints
Performance data is available through two REST endpoints served by the Sentinel dashboard router.
System Overview
Returns a high-level snapshot of system-wide performance metrics.
GET /sentinel/api/performance/overview
1{2 "totalRequests": 48210,3 "avgResponseTime": "12ms",4 "p50": "8ms",5 "p95": "45ms",6 "p99": "120ms",7 "errorRate": 0.023,8 "throughput": 82.5,9 "slowRequests": 3710}
Per-Route Breakdown
Returns latency, throughput, and error metrics broken down by route.
GET /sentinel/api/performance/routes
1{2 "routes": [3 {4 "method": "GET",5 "path": "/api/users",6 "totalRequests": 12400,7 "avgDuration": "15ms",8 "p50": "10ms",9 "p95": "52ms",10 "p99": "140ms",11 "errorRate": 0.01,12 "throughput": 21.3,13 "avgResponseSize": 2048,14 "slowRequests": 815 },16 {17 "method": "POST",18 "path": "/api/orders",19 "totalRequests": 3500,20 "avgDuration": "85ms",21 "p50": "60ms",22 "p95": "210ms",23 "p99": "450ms",24 "errorRate": 0.04,25 "throughput": 6.1,26 "avgResponseSize": 512,27 "slowRequests": 1228 }29 ]30}
Dashboard
The Sentinel dashboard includes a dedicated Performance page that displays a sortable route metrics table. Each row shows a route's method, path, request count, latency percentiles (p50 / p95 / p99), error rate, throughput, and slow request count. Use the table to identify your slowest and most error-prone endpoints at a glance.
Real-Time Updates
Slow Request Detection
Any request whose duration exceeds SlowRequestThreshold is flagged as a slow request. Slow requests are counted separately in both the system overview and per-route metrics, making it easy to spot routes that need optimization.
// Flag requests taking longer than 500msPerformance: sentinel.PerformanceConfig{SlowRequestThreshold: 500 * time.Millisecond,}// Flag requests taking longer than 3 secondsPerformance: sentinel.PerformanceConfig{SlowRequestThreshold: 3 * time.Second,}
Threshold Tuning
1 * time.Second and adjust after observing real traffic.How It Works
Performance monitoring is implemented as Gin middleware that wraps every request handler.
- Before handler — The middleware records
time.Now()as the start time. - Handler executes — The request is passed through to your route handler via
c.Next(). - After handler — The middleware computes the duration (
time.Since(start)), captures the status code and response size, and builds aPerformanceMetricstruct. - Pipeline emission — The metric is emitted to Sentinel's async event pipeline via a non-blocking send. This decouples metric aggregation from request handling, adding no meaningful latency.
- Aggregation — A pipeline handler receives the metric and updates in-memory aggregates: increments request counters, inserts the duration into a percentile sketch, updates error counts, and checks against
SlowRequestThreshold.
# Request lifecycle with performance monitoring:## Request ──> Middleware records start time# │# v# c.Next() ──> Your handler runs# │# v# Compute duration, status, size# │# v# Emit PerformanceMetric to pipeline (non-blocking)# │# v# Response sent to client## Pipeline (async):# PerformanceMetric ──> Update aggregates# ├── Percentile sketch (p50/p95/p99)# ├── Error rate counter# ├── Throughput counter# └── Slow request check
Zero Latency Impact
Next Steps
- Configuration Reference — Full PerformanceConfig field reference
- Anomaly Detection — Detect unusual traffic patterns using behavioral baselines
- Rate Limiting — Throttle excessive traffic before it impacts performance
- Dashboard — Explore the Performance page and other dashboard features