Table of Contents
An apparently little used feature in Prometheus is the ability to create so-called consoles or console templates. Even though Prometheus ships some example consoles, this type of interface seems to be rarely used in practice. This is probably due to the reason that Grafana provides an excellent and polished interface for all visialization needs, while Prometheus' builtin web interface covers most administrative tasks and works well in all gimme-raw-metrics-right-quick-style scenarios.
I’ve however found the flexibility the consoles interface offers working well for specialized views into your data. In my opinion, console templates and especially the dashboard-style alternatives shipped by Prometheus are not an adequate Grafana replacement. However, creating custom console templates is entirely possible and offers nearly infinite possibilities.
Command Line Interfaces with curl #
One application of consoles is the ability to create interfaces intended for
curl instead of a regular browser. This is a well-known concept, there is
for example the popular and
curl-enabled wttr.in. Applying this concept
to Prometheus consoles,
curl "http://hostname:9090/consoles/show_int?hostname=fra-decix-1" can yield this:
The code required to make this work is the Golang template at the end of this paragraph. These templates can get quite messy and tend to contain some amount of boilerplate code. The magic happens in the highlighted lines, which take a HTTP GET param and use that to build Prometheus queries, which in turn is being iterated over from line 20 on. This example relies on all three series being returned in the same order, but one can easily adapt this to look up corresponding values in case the stored time series are less homogenous.
What to do with this? #
I’m not sure yet. While I’ve dubbed above example
show_int after the common
router command (which lacks the current bits per second of course), it’s
unclear where to go from here.
Using this interface for machine readable output does not seem wise, although one could in theory output the InfluxDB line protocol, for instance. However, InfluxDB can use Prometheus’ remote read API endpoint directly.