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.
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.
"2018-01-31 14:42:10 +0000 UTC"