diff --git a/howto/prometheus.md b/howto/prometheus.md index 297933aba6c96f996ad42fd58a7238203432d0fe..5ac6cf45569e483a820d6572a5b26dd5c4965626 100644 --- a/howto/prometheus.md +++ b/howto/prometheus.md @@ -33,9 +33,35 @@ dashboards for most purposes other than debugging. If you want your service to be monitored by Prometheus, you need to [write](https://prometheus.io/docs/instrumenting/writing_exporters/) or [reuse an existing exporter](https://prometheus.io/docs/instrumenting/exporters/). [Writing an -exporter](https://prometheus.io/docs/instrumenting/writing_exporters/) is more involved, but still fairly easy and might be +exporter][] is more involved, but still fairly easy and might be necessary if you are the maintainer of an application not already -instrumented for Prometheus. +instrumented for Prometheus. + +[Writing an exporter]: https://prometheus.io/docs/instrumenting/writing_exporters/ + +The [actual documentation][Writing an exporter] is fairly good, but basically: a +Prometheus exporter is a simple HTTP server which responds to a +specific URL (`/metrics`, by convention, but it can be anything) and +responds with a key/value list of entries, one on each line. Each +"key" is a simple string with an arbitrary list of "labels" enclosed +in curly braces. For example, here's how the "node exporter" exports +CPU usage: + + # HELP node_cpu_seconds_total Seconds the cpus spent in each mode. + # TYPE node_cpu_seconds_total counter + node_cpu_seconds_total{cpu="0",mode="idle"} 948736.11 + node_cpu_seconds_total{cpu="0",mode="iowait"} 1659.94 + node_cpu_seconds_total{cpu="0",mode="irq"} 0 + node_cpu_seconds_total{cpu="0",mode="nice"} 516.23 + node_cpu_seconds_total{cpu="0",mode="softirq"} 16491.47 + node_cpu_seconds_total{cpu="0",mode="steal"} 0 + node_cpu_seconds_total{cpu="0",mode="system"} 35893.84 + node_cpu_seconds_total{cpu="0",mode="user"} 67711.74 + +Obviously, you don't necessarily have to write all that logic +yourself, however: there are [client libraries](https://prometheus.io/docs/instrumenting/clientlibs/) (see the [Golang +guide](https://prometheus.io/docs/guides/go-application/), [Python demo](https://github.com/prometheus/client_python#three-step-demo) or [C documentation](https://digitalocean.github.io/prometheus-client-c/) for examples) that +do most of the job for you. Once you have an exporter endpoint (say at `http://example.com:9090/metrics`), make sure it works: