Exposing Metrics

There are a number of applications that are natively instrumented with Prometheus metrics. Those applications simply expose the metrics through an HTTP server.

The Prometheus developers and the community are maintaining client libraries for various languages. If you want to monitor your own applications and instrument them natively, chances are there is already a client library for your language.

Not all software is natively instrumented with Prometheus metrics, but still record metrics in some other form. For these kinds of applications there are so called exporters.

Exporters can generally be divided into two categories:

  • Instance exporters: These expose metrics about a single instance of an application. For example the HTTP requests that a single HTTP server has exporters served. These exporters are deployed as a side-car container in the same pod as the actual instance of the respective application. A real life example is the dnsmasq metrics sidecar, which converts the proprietary metrics format communicated over the DNS protocol by dnsmasq to the Prometheus exposition format and exposes it on an HTTP server.

  • Cluster-state exporters: These expose metrics about an entire system. For example these could be the number of 3D objects in a game, or metrics about a Kubernetes deployment. These exporters are typically deployed as a normal Kubernetes deployment, but can vary depending on the nature of the particular exporter. A real life example of this is the kube-state-metrics exporter, which exposes metrics about the cluster state of a Kubernetes cluster.

Lastly in some cases it is not a viable option to expose metrics via an HTTP server. For example a CronJob may only run for a few seconds - not long enough for Prometheus to be able to scrape the HTTP endpoint. The Pushgateway was developed to be able to collect metrics for that kind of a scenario. If possible it is highly recommended not to use the Pushgateway. Read more about when to use the Pushgateway and alternative strategies here: https://prometheus.io/docs/practices/pushing/#should-i-be-using-the-pushgateway.