MySQL data with Grafana Graph problem

Hallo ,
i have problem when i try to create a graph with Grafana for my MySQL Data:
my table (jobs) has the following coloms:

  1. id int(11) as primary Key
  2. Current int(11)
    3.date_at timestamp default:CURRENT_TIMESTAMP

    now the problem is when i am trying to run this query
    SELECT
    UNIX_TIMESTAMP(date_at) as time_sec,
    Current as value,
    ‘Current’ as metric
    FROM jobs
    ORDER BY date_at

i am getting under the time_sec field somthing like this (1.52Bil) which is the a number in seconds i guess.


and when i am running the follwoing query
SELECT UNIX_TIMESTAMP(date_at) as time_sec, Current as value, ‘Current’ as metric FROM jobs WHERE $__timeFilter(date_at) ORDER BY date_at desc

so the graph is not showing the previous value of current. it shows just the last two points or values
my questions:

  1. how i can show the different value of Current job as graph with lines and points change with changing the value of current and its timestamp in database.
    2.how i can show the date of each value in readable form 2018-03-23 12:24:06 for example.
  2. if i have multiple lines or records for Current job in my database with its corresponding timestamp how i can rewrite my query so i can show it like a line and point graph.

i will be thankful for a quick Answer

Hi,

Please go to Column Styles tab and add time_sec to the Apply to columns named field, then change the Type to Date.

I don’t understand what you mean. Looks to me that you have no more data in the time range (upper right corner) you’ve selected. Can you provide something that visualizes what you’re trying to accomplish?

Marcus

Hi,
i have changed the type to Date in Column Styles and its working.


but for the other questions i have the following data in my database:

the graph is working also but when i want to show the date as u can see in the table form it is showing somthing like this :

how i can change the date to the current date.
and how i can rewrite my query so i can get the value of Current , Finished , Pending ,Error jobs as columns in the table which will change whenever the time_sec column value will change.

Oh right. For the table panel you don’t need to adhere to columns named time_sec, value and metric - those are specific for time series queries and you should have read about that in the documentation.

Just do a

SELECT 
  date_at,
  Current,
  Finished,
  Pending,
  Error
FROM
  jobs 
WHERE 
  $__timeFilter(date_at) 

Then you’ll need to adjust the column styles again for at least your date column which now is called date_at.

Marcus

thanx it working now


just the problem that the time does not match with my time its showing +2 hours to our current time

That’s a timezone issue. We strongly suggest that you write your dates in UTC to the database. If not, you can do some time zone conversion using for example this function.

One other thing you can try is to convert it to epoch:

UNIX_TIMESTAMP(date_at) as date_at

Marcus

i have done that but that’s what i am getting


and in my database is like this:

This issue should fix that problem. It’s not in any stable release yet, but available in nightly builds and if you build from source.

Marcus