Skip to content

Observability

mockd provides comprehensive observability features for monitoring, debugging, and integrating with your existing observability stack.

The admin API exposes Prometheus-compatible metrics at /metrics.

Metrics are available by default on the admin port:

4290/metrics
mockd serve --admin-port 4290
# Server uptime
mockd_uptime_seconds 3600
# HTTP request counters
mockd_http_requests_total{method="GET",path="/api/users",status="200"} 42
# Request latency histogram
mockd_http_request_duration_seconds_bucket{le="0.01"} 100
mockd_http_request_duration_seconds_bucket{le="0.1"} 150
mockd_http_request_duration_seconds_bucket{le="+Inf"} 155
# Go runtime metrics
go_goroutines 12
go_memstats_heap_alloc_bytes 4194304
prometheus.yml
scrape_configs:
- job_name: 'mockd'
static_configs:
- targets: ['localhost:4290']
metrics_path: /metrics
scrape_interval: 15s

Example Grafana queries:

# Request rate
rate(mockd_http_requests_total[5m])
# Error rate
sum(rate(mockd_http_requests_total{status=~"5.."}[5m]))
/ sum(rate(mockd_http_requests_total[5m]))
# P95 latency
histogram_quantile(0.95, rate(mockd_http_request_duration_seconds_bucket[5m]))

Send mockd logs to Grafana Loki for centralized log aggregation.

Terminal window
mockd serve --loki-endpoint http://localhost:3100/loki/api/v1/push

Logs are sent with the following labels:

LabelDescription
appAlways mockd
levelLog level (debug, info, warn, error)
componentComponent name (server, admin, engine)

Ensure Loki is running and accessible:

docker-compose.yml
services:
loki:
image: grafana/loki:2.9.0
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
# All mockd logs
{app="mockd"}
# Errors only
{app="mockd", level="error"}
# Request logs
{app="mockd"} |= "request"
# Filter by path
{app="mockd"} | json | path="/api/users"

Logs are batched for efficiency:

  • Batch size: 100 entries or 1 second (whichever comes first)
  • Automatic retry on failure
  • Graceful shutdown flushes pending logs

Send distributed traces to any OpenTelemetry-compatible backend (Jaeger, Zipkin, Tempo, etc.).

Terminal window
mockd serve --otlp-endpoint http://localhost:4318/v1/traces

Control the sampling rate (default: 100%):

Terminal window
# Sample 10% of traces
mockd serve --otlp-endpoint http://localhost:4318/v1/traces --trace-sampler 0.1

Each span includes:

AttributeDescription
http.methodHTTP method
http.urlRequest URL
http.status_codeResponse status code
mockd.mock_idMatched mock ID
mockd.matchedWhether a mock matched
docker-compose.yml
services:
jaeger:
image: jaegertracing/all-in-one:1.50
ports:
- "16686:16686" # UI
- "4318:4318" # OTLP HTTP
environment:
- COLLECTOR_OTLP_ENABLED=true
Terminal window
mockd serve --otlp-endpoint http://localhost:4318/v1/traces
# View traces at: http://localhost:16686
docker-compose.yml
services:
tempo:
image: grafana/tempo:latest
command: ["-config.file=/etc/tempo.yaml"]
ports:
- "4318:4318"

Run mockd with full observability:

Terminal window
mockd serve \
--log-level debug \
--log-format json \
--loki-endpoint http://localhost:3100/loki/api/v1/push \
--otlp-endpoint http://localhost:4318/v1/traces \
--trace-sampler 1.0
version: '3.8'
services:
mockd:
image: ghcr.io/getmockd/mockd:latest
ports:
- "4280:4280"
- "4290:4290"
command: >
serve
--loki-endpoint http://loki:3100/loki/api/v1/push
--otlp-endpoint http://tempo:4318/v1/traces
depends_on:
- loki
- tempo
loki:
image: grafana/loki:2.9.0
ports:
- "3100:3100"
tempo:
image: grafana/tempo:latest
ports:
- "4318:4318"
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin

For real-time request monitoring, use the SSE endpoint:

Terminal window
curl -N http://localhost:4290/requests/stream

See Admin API Reference for details.