Chapter 12. Writing Exporters
Sometimes you will not be able to either add direct instrumentation to an application, nor find an existing exporter that covers it. This leaves you with having to write an exporter yourself. The good news is that exporters are relatively easy to write. The hard part is figuring out what the metrics exposed by applications mean. Units are often unknown, and documentation, if it exists at all, can be vague. In this chapter you will learn how to write exporters.
Consul Telemetry
Iâm going to write a small exporter for Consul to demonstrate the process. While we already saw version 0.3.0 of the Consul exporter in âConsulâ, that version is missing metrics from the newly added telemetry API.1
While you can write exporters in any programming language, the majority are written in Go, and that is the language I will use here. However, you will find a small number of exporters written in Python, and an even smaller number in Java.
If your Consul is not running, start it again following the instructions in Example 8-6. If you visit http://localhost:8500/v1/agent/metrics you will see the JSON output that you will be working with, which is similar to Example 12-1. Conveniently, Consul provides a Go library that you can use, so you donât have to worry about parsing the JSON yourself.
Example 12-1. An abbreviated example output from a Consul agentâs metrics output
{
"Timestamp"
:
"2018-01-31 14:42:10 +0000 UTC"
,
"Gauges"
:
[
{
"Name"
:
"consul.autopilot.failure_tolerance" ...
Get Prometheus: Up & Running now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.