11

There's an article "Tracking Every Release" which tells about displaying a vertical line on graphs for every code deployment. They are using Graphite. I would like to do something similar with Prometheus 2.2 and Grafana 5.1. More specifically I want to get an "application start" event displayed on a graph.

Grafana annotations seem to be the appropriate mechanism for this but I can't figure out what type of prometheus metric to use and how to query it.

and
  • 2,024
  • 3
  • 24
  • 31

3 Answers3

11

The simplest way to do this is via the same basic approach as in the article, by having your deployment tool tell Grafana when it performs a deployment.

Grafan has a built-in system for storing annotations, which are displayed on graphs as vertical lines and can have text associated with them. It would be as simple as creating an API key in your Grafana instance and adding a curl call to your deploy script:

curl -H "Authorization: Bearer <apikey>" http://grafana:3000/api/annotations -H "Content-Type: application/json" -d '{"text":"version 1.2.3 deployed","tags":["deploy","production"]}'

For more info on the available options check the documentation:

http://docs.grafana.org/http_api/annotations/

Once you have your deployments being added as annotations, you can display those on your dashboard by going to the annotations tab in the dashboard settings and adding a new annotation source: adding annotation source

Then the annotations will be shown on the panels in your dashboard: panel showing annotation

AussieDan
  • 2,116
  • 15
  • 11
6

You can get the same result purely from Prometheus metrics, no need to push anything into Grafana:

Annotation from Prometheus query

If you wanted to track all restarts your search expression could be something like:

changes(start_time_seconds{job="foo",env="prod"} > 0

Or something like this if you only wanted to track version changes (and you had some sort of info metric that provided the version):

alertmanager_build_info unless max_over_time(alertmanager_build_info[1d] offset 5m)

The latter expression should only produce an output for 5 minutes whenever a new alertmanager_build_info metric appears (i.e. one with different labels such as version). You can further tweak it to only produce an output when version changes, e.g. by aggregating away all other labels.

Alin Sînpălean
  • 8,774
  • 1
  • 25
  • 29
  • is there a way to just show just the most recent version? For instance I deploy a new app version, and I get another new metric( so I have two now) , but how do I filter it to just show the new version? I tried but haven't found a workable solution...Tom – Tomislav Mikulin May 29 '19 at 08:56
  • If you use the latter query, you should only see timeseries created during the last 5 minutes. So I guess I don't understand your question. Do you mean you're looking at a week-long interval and want to see an annotation for the last version only; not the last one now and the previous one, 3 days ago? – Alin Sînpălean May 29 '19 at 11:36
  • yes but after those 5 minutes I get nothing...so I was thinking is there a way to always see the lastest version of the app version... – Tomislav Mikulin May 29 '19 at 12:18
  • Well, outside of Prometheus' default 5 minutes staleness limit (a timeseries with no fresh samples will continue to be returned for 5 minutes), you should only get the currently deployed versions when querying e.g. `alertmanager_build_info`. If that returns multiple versions, then it simply means you have multiple versions deployed. And it's really hard to tell which of those is the "lastest" version: is it the one that restarted last, is it the one that's larger numerically, the one with a "-beta" suffix? – Alin Sînpălean May 29 '19 at 14:21
0

A note here as technology has evolved. We get deployment job state information in Prometheus metrics format scraped directly from the community edition of Hashicorp's Nomad and we view this information in Grafana.

In your case, you would just add an additional query to an existing panel to overlay job start events, which is equivalent to a new deployment for us. There are a lot of related metrics "out of the box," such as for a change in job version that can be considered as well. The main point is no additional work is required besides adding a query in Grafana.

enter image description here