How to plot horizontal line in Timeseries in Grafana

Viewed 1894

I use grafana to plot timeseries data. In a timeseries plot i want to add a constant line which comes from a monitoring level. The value of that level is dynamic (from a postgres database) the timeseries come from a ifluxdb Datasource.

The monitoring level have no timestamp. The result should look like this:

enter image description here

I have searched quite a while how to do this, but not found a good explanation.

3 Answers

Another way to do it in a dirty way is to create panel with a mixed data source. Create your variable in grafana - it can be a query, constant or custom. Just remember to keep it a single floating point. Add your original query and add the prometheus data source to query your variable.

${net_ordered_storage}

You will have to play a little bit with the number of data points displayed (query options>max data points) and minimum step of data point in prometheus query to make grafana connect dots.

Green horizontal line from variable

You can now add thresholds (bottom of the edit screen).

Each threshold can be represented as a solid line and/or region with individual color

enter image description here

To draw a line like that you have to "fake" a timeseries. (thresholds don't work since they can not be dynamic as far as I know)

First thing to keep in mind is that grafana needs timestamp to plot it, for this reason the global variables ${__to} and ${__from} come in handy.

Then, to draw a line, grafana needs at least two points. ([t0, t1][y0, y1])

So this is the sql (postgre) query that lead to the desired result:

SELECT
  ${__from} AS time,
  level_1,
FROM my_table where display_name = '${my_grafana_var:raw}'
union all
SELECT
  ${__to} AS time,
  level_1,
FROM my_table where display_name = '${my_grafana_var:raw}';
Related