Grafana - show metric grouped by day is shifted by 1 day

I am using Grafana v8.4.4 to visualize Docker container metrics. I would like to show amount of received traffic (upload), grouped by day. For this purpose, I am using container_network_receive_bytes_total metric provided by cAdvisor.

I am using the following Prometheus query:

sum(increase(container_network_receive_bytes_total[1d]))

Once visualized in Grafana, it looks like this (user selected Last 7 days at the top right of Grafana UI). I set Min step to 1d (red rectangle in the photo):

enter image description here

enter image description here

I am writing this post on 6-Apr-2022. I noticed that the days in the graph are off by 1:

  1. Today’s data isn’t displayed on the graph at all
  2. The bar on the far right actually shows data from yesterday (5-Apr-2022), but its label still says 6-Apr-2022

I found a “hack” to show today’s data as well. I had to set Time shift in query options to -1d (0d+1d in Grafana syntax):

enter image description here

enter image description here

Questions:

  1. Why are dates off by 1 day? How can I fix this?
  2. Why are there there 8 bars despite the fact that I selected Last 7 days?

can you share your dashboard json? What are the time settings in the timepicker? Are you using browser time?

This is dashboard JSON:

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 20,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "axisSoftMin": 0,
            "fillOpacity": 80,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineWidth": 1,
            "scaleDistribution": {
              "type": "linear"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "hideTimeOverride": true,
      "id": 2,
      "options": {
        "barRadius": 0,
        "barWidth": 0.97,
        "groupWidth": 0.7,
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "orientation": "auto",
        "showValue": "auto",
        "stacking": "none",
        "tooltip": {
          "mode": "single",
          "sort": "none"
        },
        "xTickLabelRotation": 0,
        "xTickLabelSpacing": 0
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "PBFA97CFB590B2093"
          },
          "exemplar": true,
          "expr": "sum(increase(container_network_receive_bytes_total{container_label_com_docker_stack_namespace=\"BlogBackend\"}[1d]))",
          "interval": "1d",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "timeShift": "0d+1d",
      "title": "Ingress traffic",
      "type": "barchart"
    }
  ],
  "refresh": "",
  "schemaVersion": 35,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-7d",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Test dashboard (delete later)",
  "uid": "HJuRoaUnz",
  "version": 2,
  "weekStart": ""
}

I selected “Last 7 days” in time picker at the top right corner of Grafana GUI.

I am using browser time (UTC+02:00).

Hi, did you ever found a solution to this ?
I am having the same issue.
I am trying to group by day but grafana is adding an extra row to my table.

I have the same issue. Anyone that has a solution?

Could it be that you miss the tz() option? My Solution:

Hi,

I’m having the same issue and I’ve spent days trying to figure this one out without any resolution.

In my case the shift is by 2 days and I have to use the

increase(kWh_value{entity_id="total_energy"}) offset -2d

to correct for the shift. Your hack with 0d+2d also works for me.

It just feels like something is wrong with my whole setup or db configuration. I’d love to understand the root cause behind this issue and solve it properly rather than through offsetting incorrect values.

I’m using Grafana with VictoriaMetrics and trying to plot hourly and daily energy usage with sensor data coming from HomeAssistant.

After doing some local testing, I established that the time shift happens for every value of the Min interval set in the Query options. Whenever I set Min inverval to T I have the offset the graph by at least 2 * T. Below is a graph without the offset

And here you can see that after adding a negative offset the missing data points pop up.

Why are the end points cut off? Does anyone know what the problem here is?

Thanks!

What timezone are you using for the date time column? Is it UTC

Thanks. I believe that VictoriaMetrics keeps all of its data in UTC.

In the previous post I was using BST time in Grafana panel. Switching to UTC partially fixed the issue. I now have to shift by 1 day instead of 2.

increase(kWh_value{entity_id="total_energy"}) offset -1d

The shift is still required unfortunately.

I also noticed that my daily consumption bar chart shows time as 00:00 on the X axis, whereas the table view shows 01:00 in the Time column. I don’t know if this discrepancy is related, but it seems unexpected too.


Do you have any more ideas on what could be wrong?

Not sure why you need hours when you are looking for daily consumption?

like you not ste query step