Cameron
Cameron

Reputation: 78

Is there a way to force the output of a Stat panel in Grafana to only show values in days

I'm building a Grafana dashboard with some Stat panels that show average, minimum, and maximum time values (see below) for specific fields in my database. I'm storing the data in seconds and setting the value's units to seconds after which the panel displays the time in weeks, days, hours, etc. For the sake of consistency, I would like everything to be shown in days but I haven't been able to find a way to force units for the output value. If it's possible to do this, could someone please point me to some docs, or something that could show me which configurations to make in my panels?

sample panels

So far, I've tried (without success):

  1. Configure each panel to use units of days
    • The result of this was that everything showed up in years, etc.
  2. Configure each panel to create a new field by performing a binary calculation where I converted from seconds to days and then I updated the units to be days
    • The result was that the values were not changed at all -> instead of showing X days, or whatever, it just showed the value in seconds without the units. I'm not sure what I messed up there, but it didn’t change anything.
  3. I found this link that discusses setting a time range for queries
    • This didn’t end up being useful for what I was trying to do because it was actually geared towards changing the query to a specific date range rather than the output.
  4. I looked through the transformations documentation, stat panel documentation, and a few other panel documentation pages in an effort to see if there was any information on how to do it but I was unable to find anything on forcing the output value to use a specific unit.

Edit:

So I kept messing around with the dashboard and got a solution that works - i.e. it's a "good-enough" solution (see below) - but, now, I'm curious if it's possible to show the units along with the value without it converting it to some other unit. Does anyone have any ideas about this?

updated version without units as part of value

Upvotes: 2

Views: 3028

Answers (2)

Carpi2001
Carpi2001

Reputation: 11

You can use a custom unit. It is a bit tricky to enter the unit in the UI because of the automatic selection but if you enter i.e. "days" (without the quotes) in the Unit field and instead of leaving the field with tab or mouse click use the scrollbar of the combobox and select the last entry "Custom Unit: days".

Hope it helps. And for the record: I am using Grafana version 7.1.4

Upvotes: 1

Melroy van den Berg
Melroy van den Berg

Reputation: 3166

In de settings: Standard options -> Unit-> enter: "Days (without quotes) and select "Custom units: days".

What Carpi2001 explained earlier.

But since the received amount is in seconds and not in days, I need to manually convert the values from seconds to days. I'm using InfluxDB query:

SELECT last("uptime")/3600/24 FROM "system" WHERE ("host" =~ /^$hostname$/) AND $timeFilter GROUP BY time($__interval) 

Which will results into:

enter image description here

Upvotes: 1

Related Questions