Grafana + MariaDB

I found something myself, my previous attemp was almost correct:

SELECT
UNIX_TIMESTAMP(DATE_FORMAT(time,“%Y-%m-%d %H:%i:%s”)) as time_sec,
value
FROM
xiaomi_th_alex_temperature_0026

I’m only missing how I can give the series a name, now all of them are called ‘unknown’:
image

3 Likes

For graphs it should be here (field called “Label”):

For tables (field Column Header):

That’s the label for the graph/table it selves, not for the series.

With InfluxDB as a datasource you have this option:
image

I only use the Table Panel for MariaDB data, so I can’t say if it has that option as well.

What happens if you define it in your SQL statement? Something like:

SELECT
UNIX_TIMESTAMP(DATE_FORMAT(time,"%Y-%m-%d %H:%i:%s")) as time_sec,
value as myvaluename
FROM
xiaomi_th_alex_temperature_0026

I had the same problem.

The first google search result pointed out the solution:

The workaround is to use the FLOOR function, e.g.

FLOOR(UNIX_TIMESTAMP(time)) as time_sec

Thx, this is working fine!

Do you also have a solution to display correct series labels?

Sure thing:

SELECT
  FLOOR(UNIX_TIMESTAMP(time)) as time_sec,
  value,
  'Your custom metric name' as metric
FROM your_sql_column_name
WHERE $__timeFilter(time)
ORDER BY time ASC;
2 Likes

thanks!

Now I can do everything with my Mariadb, no need for influxdb :slight_smile:

Guys

thanks a lot for sharing your solutions - I was already giving up with Grafana but after finding this thread its working - finally :slight_smile:

Can anyone of you tell me how to adjust this script when I want to display more than one line in a chart?

Thanks & regards
John

I simply added a second query, or a third, fourth…

Sorry to re-live this topic.
I’ve spent a little time researching this to no avail…
Using openhab2 on Raspberry pi 3, (openhabian), JDBC Persistance MYSQL, MariaDB, Grafana Graphing… I don’t understand where I can change the following from “value” to the desired name (ie GarageTemp, Greenhouse Temp, etc)
Hopefully this is a quick reply without consuming too many cycles from anyone’s busy day :slight_smile:

AND… I really wish I understood how openhab creates the tablenames in its DB… :wink:

Michael Krug shows the syntax for this but I’m not sure if this goes in Grafana or PHPMyAdmin that I’m using :slight_smile: AND how to use the proper syntax for my specific application
Thanks Guys!!

You have to change the Alias:

This should be the same name as the item name (you can setup an alias in the *.persist file)

Sounds easy enough… thanks.
I’ll have to look up how to “syntax” the .persist file.
Thanks again… this has been bugging me for a few months now… didn’t have the time to pursue. :slight_smile:

No joy…
I do not see the option “Alias” in my Grafana instance. What am I missing?

image

Well this has been a waste of 2 hours trying to figure out WHY I don’t have the “Alias” option in my Metrics. :frowning:
v 5.1.4
It’s enough to start looking for another graphing solution

See some post above, I had the same issue:

YAY… Thanks, Ward and michikrug!!
Todd

Sorry, didn’t realize you are using SQL as Source.

But happy that @wars could help :slight_smile: