4

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.

renzop
  • 1,194
  • 2
  • 12
  • 26

4 Answers4

3

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

Raph
  • 326
  • 3
  • 15
  • How can you read the thresholds from a datasource? – renzop Jul 04 '23 at 07:55
  • I don't know if thresholds can be dynamically read from a datasource (I understand that's what you want to do?). At time of writing the above answer all you could do what hard code them if I remember correctly. edit: @HTE seems to have a solution for dynamic threshold – Raph Jul 04 '23 at 21:27
3

It is possible to add dynamic thresholds using the Config from query option.

  1. Add a new query below your standard metric query. This will likely be called B. Here you query the static reference value. Eg SELECT expected_number_of_widgets FROM baseline
  2. Open Transformation tab
  3. Find Configuration from Query results
  4. Choose Config query = B
  5. At the dropdown for expected_number_of_widgets, choose Use as: Threshold1.
  6. In the right panel, under Thresholds, make sure Show Tresholds is enabled and remove the default threshold of 80.

For more details, see https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/transform-data/#config-from-query-results

HTE
  • 113
  • 5
2

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}';
renzop
  • 1,194
  • 2
  • 12
  • 26
1

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

ouflak
  • 2,458
  • 10
  • 44
  • 49
mraczka
  • 11
  • 3