477518e5eb
API instrumentation - metrics and logging * api instrumentation prometheus metrics and logging for all routes * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/prometheus * add log_level and sync the config initialize * docs * cleanup * add to compose:up:test * docs for prometheus testing * custom metrics * cleanup * merge main * add tests * cleanup docs * cleanup * lint * fix unit tests (attempt) * fix tests * resolvesetlogger * expose 8080 * compose changes * bugfixesformichael * don't build _test * merge in main * job_sync_runner
40 lines
1.2 KiB
Markdown
40 lines
1.2 KiB
Markdown
# Prometheus sample code
|
|
|
|
This is a sample main that will use the custom doczy prometheus library to expose some typical
|
|
metrics.
|
|
|
|
`task compose:up:test` (to start prometheus)
|
|
Then run
|
|
`go run ./cmd/metricsExample_test/main.go`
|
|
to start the metrics example server.
|
|
|
|
Prometheus console is at http://localhost:9090/
|
|
|
|
## Example queries for the
|
|
Use these queries in the prometheus console to see the metrics from the sample main.go
|
|
|
|
### Total requests per endpoint (rate over 5m)
|
|
rate(myapp_api_api_requests_total[5m])
|
|
|
|
### Request rate by status code
|
|
sum by (status) (rate(myapp_api_api_requests_total[5m]))
|
|
|
|
### Request rate by method
|
|
sum by (method) (rate(myapp_api_api_requests_total[5m]))
|
|
|
|
### Current active users by type
|
|
myapp_api_active_users
|
|
|
|
### Total active users across all types
|
|
sum(myapp_api_active_users)
|
|
|
|
## Histograms
|
|
### 95th percentile request duration by endpoint
|
|
histogram_quantile(0.95, sum(rate(myapp_api_request_duration_seconds_bucket[5m])) by (endpoint, le))
|
|
|
|
### Average request duration
|
|
rate(myapp_api_request_duration_seconds_sum[5m]) / rate(myapp_api_request_duration_seconds_count[5m])
|
|
|
|
### Request duration heatmap (if you have Grafana)
|
|
myapp_api_request_duration_seconds_bucket
|