|
| 1 | +# Prometheus |
| 2 | + |
| 3 | +Coder has support for Prometheus metrics using the dedicated [Go client library](github.com/prometheus/client_golang). The library exposes various [metrics types](https://prometheus.io/docs/concepts/metric_types/), such as gauges, histograms, and timers, that give insight into the live Coder deployment. |
| 4 | + |
| 5 | +Feel free to browse through the [Getting started](https://prometheus.io/docs/prometheus/latest/getting_started/) guide, if you don't have an installation of the Prometheus server. |
| 6 | + |
| 7 | +## Enable Prometheus metrics |
| 8 | + |
| 9 | +Coder server exports metrics via the HTTP endpoint, which can be enabled using either the environment variable `CODER_PROMETHEUS_ENABLE` or the flag` --prometheus-enable`. |
| 10 | + |
| 11 | +Use either the environment variable `CODER_PROMETHEUS_ADDRESS` or the flag ` --prometheus-address <network-interface>:<port>` to select a custom endpoint. |
| 12 | + |
| 13 | +Once the `code server --prometheus-enable` is started, you can preview the metrics endpoint: <!-- markdown-link-check-disable -->http://localhost:2112/<!-- markdown-link-check-enable --> (default endpoint). |
| 14 | + |
| 15 | +``` |
| 16 | +# HELP coderd_api_active_users_duration_hour The number of users that have been active within the last hour. |
| 17 | +# TYPE coderd_api_active_users_duration_hour gauge |
| 18 | +coderd_api_active_users_duration_hour 0 |
| 19 | +# HELP coderd_api_concurrent_requests The number of concurrent API requests |
| 20 | +# TYPE coderd_api_concurrent_requests gauge |
| 21 | +coderd_api_concurrent_requests 2 |
| 22 | +# HELP coderd_api_concurrent_websockets The total number of concurrent API websockets |
| 23 | +# TYPE coderd_api_concurrent_websockets gauge |
| 24 | +coderd_api_concurrent_websockets 1 |
| 25 | +# HELP coderd_api_request_latencies_ms Latency distribution of requests in milliseconds |
| 26 | +# TYPE coderd_api_request_latencies_ms histogram |
| 27 | +coderd_api_request_latencies_ms_bucket{method="GET",path="",le="1"} 10 |
| 28 | +coderd_api_request_latencies_ms_bucket{method="GET",path="",le="5"} 13 |
| 29 | +coderd_api_request_latencies_ms_bucket{method="GET",path="",le="10"} 14 |
| 30 | +coderd_api_request_latencies_ms_bucket{method="GET",path="",le="25"} 15 |
| 31 | +... |
| 32 | +``` |
| 33 | + |
| 34 | +## Explore collected metrics |
| 35 | + |
| 36 | +### Coderd |
| 37 | + |
| 38 | +[Coderd](../about/architecture.md#coderd) is the service responsible for managing workspaces, provisioners, and users. Coder resources are controlled using the authorized HTTP API - Coderd API. |
| 39 | + |
| 40 | +The Prometheus collector tracks and exposes activity statistics for [platform users](https://github.com/coder/coder/blob/main/coderd/prometheusmetrics/prometheusmetrics.go#L15-L54) and [workspace](https://github.com/coder/coder/blob/main/coderd/prometheusmetrics/prometheusmetrics.go#L57-L108). |
| 41 | + |
| 42 | +It also exposes [operational metrics](https://github.com/coder/coder/blob/main/coderd/httpmw/prometheus.go#L21-L61) for HTTP requests and WebSocket connections, including a total number of calls, HTTP status, active WebSockets, request duration, etc. |
| 43 | + |
| 44 | +### Provisionerd |
| 45 | + |
| 46 | +[Provisionerd](../about/architecture.md#provisionerd) is the execution context for infrastructure providers. The runner exposes [statistics for executed jobs](https://github.com/coder/coder/blob/main/provisionerd/provisionerd.go#L133-L154) - a number of jobs currently running, and execution timings. |
| 47 | + |
| 48 | +### Go runtime, process stats |
| 49 | + |
| 50 | +[Common collectors](https://github.com/coder/coder/blob/main/cli/server.go#L555-L556) monitor the Go runtime - memory usage, garbage collection, active threads, goroutines, etc. Additionally, on Linux and on Windows, they collect CPU stats, memory, file descriptors, and process uptime. |
0 commit comments