How to add Time series queries with grafana and MySQL?

Are you using a mysql query against a postgres datasource? pq is the postgres driver.

1 Like

i used postgre. I solved that problem. Thank you. But i have another problem. On database I have column with datetype time without timezone (it is a contunue on site time, like 00:02:53 and etc) I want to build graph like this image . How grafa shows me mistake “Value column must have numeric datatype, column: value type: string value: 00:02:53”

Can you post your query? Your query seems to return string for the field you wanna visualize.

select
extract(epoch from “Datestamp”) as time,
“OpCo” as metric,
“Web13” as value
FROM public.“Timeon”
where
$__timeFilter(“Datestamp”)
group by “OpCo”, “Datestamp”, “Web13”
order by “Datestamp”

Grafana shows error^ Value column must have numeric datatype, column: value type: string value: 0:01:51

Web13 seems to be a text datatype and not a number.

You probably want something like the following query where you convert your time to seconds and then tell grafana that the unit is seconds so the legend will be correct.

select
extract(epoch from "Datestamp") as time,
"OpCo" as metric,
extract(epoch from "Web13"::time) as value
FROM public.“Timeon”
where
$__timeFilter("Datestamp")
group by "OpCo", "Datestamp", "Web13"
order by "Datestamp"

Greate, thank u!
Now grafana show 2.45 min, could it shows in format like 2:45?

There is no custom format so you have to pick one of the predefined formats.

ok, thank you! I have another problem:
My database in Postgre:
ID Datestamp OpCo(text) App CC Shops IVR Share

Could i make a filter OpCo like(AM)?

i want to show dashboard^

This where solved it for me, gold!

where from_unixtime(aint) >= $__timeFrom() AND from_unixtime(aint) <= $__timeTo()
1 Like

Hello,i am having the same problem and i fail to understand why my approach is not working,any one to help me?

You have not told us what your approach is so it is impossible for us to guess why it is not working.

@clanlaw i have a database of records of loans given to people… i have managed to group them into amount offered for a specific year
SELECT YEAR(outsource_date),COUNT(*) FROMcase_filesGROUP BY YEAR(outsource_date) will give me the record i need from the database.

I will get
|2018|111973|
|2019|382652|
that means for 2018 a loan of 111973 dollars was given out,in 2019 a loan of 382652 was given out.I would love to have a bar chart for the above

I believe you have to end up with a time column so grafana knows what to do with it. See the earlier examples here. How you then force it to a show by year I am not sure.

I want for 2018 and 2019 to be displayed in a bar graph and i am getting a very funny output

SELECT UNIX_TIMESTAMP(cast(outsource_date as date)) as time_sec ,SUM(loan_amount) FROM case_files GROUP BY YEAR(outsource_date) this query gives me the following graph… yes i want a bar graph

What date range is there data in the db for?

|2018-10-25 | 728156825.00 |

|2019-01-02 | 4189209818.14 |

SELECT outsource_date as 'Date', SUM(loan_amount) as 'Total' FROM case_files GROUP BY YEAR(outsource_date)

Why have you posted a different query? Does that one do what you want? It looks to me as if the first one is drawing the bars correctly. Though that may not be what you want.