MariaDB : Help a noobie to use timerange

44 Views Asked by At

I don't know a lot about MyQSL.

Here is my code (to extract code from a monitoring tool)

SELECT DISTINCT
     FROM_UNIXTIME(data_bin.ctime), index_data.host_name, index_data.service_description, metrics.metric_name, data_bin.value
        FROM metrics 
     inner join index_data ON index_data.id = metrics.index_id 
     inner join data_bin   ON data_bin.id_metric = metrics.metric_id
ORDER BY data_bin.ctime;

Despites my efforts, I don't manage to :

  1. Filter by timerange (with human readable time)
  2. Obtain that output :

Timerange, Hostname, ServiceA, metricA1, metricA2, ... ServiceB, metricB1, metricB2 ... -> the goal is to group by identical Timerange and Hostname

1

There are 1 best solutions below

2
AudioBubble On

I think your question is missing some key points, and I'll adjust this if you can specify what you're looking for a bit better with some example data from each of these tables.

But in the meantime, I think I have a good understanding, maybe this is what you're looking for:

SELECT DISTINCT
     FROM_UNIXTIME(data_bin.ctime) AS timerange, index_data.host_name, index_data.service_description, metrics.metric_name, data_bin.value
        FROM metrics 
     inner join index_data ON index_data.id = metrics.index_id 
     inner join data_bin   ON data_bin.id_metric = metrics.metric_id
GROUP BY index_data.host_name, timerange
ORDER BY timerange;