Set y-axis range as percentage of mean

  • What Grafana version and what operating system are you using?

    • Version 12.0.1
    • Raspberry PI OS 64 bit (but if needed switch to proper amd64 debian and run on the same computer as the TimescaleDB server used as main source)
    • Postgresql with TimescaleDB as data source
    • Role of the system: monitoring the status of a laser amplifier chain and other parts of the experiment. The main use case is viewing the last 1min of the data and checking if there are issues requiring immediate action.
  • What are you trying to achieve?

    • Get the y-axis to either have a range defined by some calculation on the data or pulled from a variable. Optimally I would like to be able to write a function that takes in some stats about the data (mean and variance) and returns the y-axis limits. But the most basic case would be to just have the limits be set at [mean ± 5% mean].

      The data is voltages measured on a few photodiodes. They were previously monitored using a Labview program. The program had a button to recenter the signal in the y-range. Depending on how the photodiodes are installed, the voltages stabilize around 2-4 volts (different for each photodiode). The expected stability is about 0.3% RMS. The signal can have spikes if for instance someone dropped a wrench or something, that’s benign. Or it can be a real issue causing damages to the system. So when we work we keep track of the RMS value. If we see that the RMS value is too high we glance at the time series to see if it was just a spike or something different. Certain problems have recognizable patterns that we can see on the time-series. But we’re used to seeing them with a fixed y-range corresponding to a few percent of the actual value. That way the amplitude of the instability is immediately obvious.
      This is best done when the scale of the data doesn’t really change (which is why the labview program had the range set to a few percent of the average, which is essentially a constant value). I could hard-code the limits but:

      • At startup, the signal progressively increases by more than 10% over an hour or so, so monitoring fluctuations in a window of a few minutes is still useful. If I were to hardcode limits, either the range would be too big or the signal would start up outside of the range
      • I have 8 such signals to monitor and would prefer to avoid manually setting up each panel. So I have it set up as repeating panels.
  • How are you trying to achieve it?

    • I’m not quite sure, I’m looking for advice on how best to solve it. Ideally I would really like to be able to write a python function that takes in the values or some stats and use its result for the y-min and y-max. That way I could just define some non-trivial rules based on what the users expect.
    • The only idea I have is to normalise the data to 1 within the observation window and set the limits to 0.95 and 1.05 or something. This is not ideal though since at some point I will add the calibration factor from voltages to actual millijoules of power and I want to be able to see the real values in the y-axis.
  • What happened?

    • Not implemented yet, want to know best course of action
  • What did you expect to happen?

    • Not applicable
  • Can you copy/paste the configuration(s) that you are having problems with?

    • Not applicable
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

    • Not applicable
  • Did you follow any online instructions? If so, what is the URL?

    • No, though I did search online for answers but only found unresolved issues with people asking for dynamically defined limits.

Apologies if the question is asked unclearly. I can try to provide some example data but I’m not quite sure how useful that would be in this case.

Write that business logic to calculate min/max value based on mean in your Timescale DB query and add it as additional panel query. Then use transformation to use those values: Transform data | Grafana documentation

That was perfect, worked like a charm!
Thank you so much