Search code examples
prometheuspromql

Getting a start and stop time points of returning HTTP codes by HTTP endpoint, in Prometheus


Let's assume we have a time range of day - 00:00 - 23:59 and HTTP endpoint(which is being probed by Blackbox-exporter) returns status codes:

  • from 00:00 to 7:00 endpoint was returning 200
  • then from 7:00 to 7:05 was returning 500
  • then from 7:05 to 20:00 was returning 200
  • then from 20:00 to 20:10 was returning 404
  • and from 20:10 to 23:59 was returning 200

Can I reflect it somehow in Prometheus, i.e. when one code ends up being returned and another one started? And maybe it's possible to output somehow in Grafana on a time-range plot?


Solution

  • If all you want is just to visualize status code, you don't need some clever promQL query for this.

    You can simply create "State timeline" panel with probe_http_status_code query.

    To make this panel show data in understandable way:

    1. Expand query options (under query), select Legend: Custom, and put {{instance}} into it.
    2. Go to Panel options: Standard options > Color scheme > Single color.
    3. Value mappings: add HTTP codes with corresponding colors. You can make mappings single value or range based.

    In the result you'll get something like this: enter image description here