Time series data with missing-value metric issue

I am facing issues with bar graphs when data source is one of PostGres or Mysql.
This problem persists both in Mysql and Postgresql.
The issue is visualized like this: (the image is intentionally in day interval so that I can show you the problem. Otherwise it still persist when it is aggregated monthly)

image

This problem exists when I use pure sql like this date_trunc('month', dateColumn) as time or like this ‘unix_timestamp(date_format(dateColumn, ‘%Y-%m-01’)) as time’ and this problem rises when one bar is missing a data point for a metric. There is no way of indicating what to do with missing data point for a metric in specific interval in pure sql. As a solution Grafana has timeGroup and it can be used like this $__timeGroup(dateColumn, '43800', 0). But this form also has issues. It tries to put the center of the bar on the first day of the month which causes the aggregation to happen for instance from 01-21 till 02-19 instead of 02-01 till 02-28.

Is there any way that I can get graph bars aggregated correctly from first day of month till end day of that month with out having a visual mistake?

Grafana Version: Grafana v5.3.2 (0d821d0)

make your your group by time and fill missing values with 0 (the last argument in __timeGroup)

Hey :slight_smile:
I have done that. But as I said above, $__timeGroup does not do the correct aggregation I am looking for.
I want to aggregate values from start of a month until end of a month

Like this:

But what $__timeGroup offers starts date from around 19th of previous month. And the aggregation the is not from start of the month but it is from 19th, 20th or 21st of the previous month
Like this:

image

Where you able to solve your issue? I am facing similar issue when ingesting data from Postgres. Let me know if you the solution

I found one accidental (not good for maintenance) work around.
The trick is while you write your time series column with pure SQL, you write the equivalent of the same as a comment.
Here, look for an example:

SELECT 
  -- $__timeGroup(date, '43800m', 0) as time, 
  unix_timestamp(date_format(date, '%Y-%m-01')) as time, 
  count(*), 
  status as metrics
FROM table 
GROUP BY time, metrics;

This I had it written for Mysql. I hope it also works for Postgres.

It was the timezone that was causing the issue. After I changed it to UTC in grafana it is working fine.

How did you change it in grafana… I am using influxdb and getting the error as Data is not numeric field.

@saranyababu2005

As that thread is 3 years old, and given the very sparse description of your problem, I am not sure anyone will be able to offer you much help.

Can you articulately describe your problem? Might be best to start a new thread with a good descriptive title.

1 Like