Why sum(increase(metric[10m])) return all 0 value?

  • What Grafana version and what operating system are you using?
    grafana cloud + prom-client + node.js

  • What are you trying to achieve?

Draw a chart about a counter metric increase.

  • How are you trying to achieve it?

I tried query sum(CLS), it shows the total count correctly, but is not the increase count of each time span I want :

Then I tried sum(increase(CLS[10m])) query.

  • What happened?
    I got all 0 value, which is not my expect:

  • What did you expect to happen?
    The value of chart should be increase count of each time span, not all 0 value.

My CLS metric has different label value, eg:

  1. {name: ‘CLS’, delta: 123 }
  2. {name: ‘CLS’, delta: 456 }
  3. {name: ‘CLS’, delta: 789 }

Does the different label value result to all 0 increase value? Should I avoid different label value?

  • Can you copy/paste the configuration(s) that you are having problems with?
    Here is my config of chart:
{
  "id": 9,
  "type": "timeseries",
  "title": "test",
  "gridPos": {
    "x": 0,
    "y": 21,
    "h": 8,
    "w": 24
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "drawStyle": "line",
        "lineInterpolation": "linear",
        "barAlignment": 0,
        "barWidthFactor": 0.6,
        "lineWidth": 1,
        "fillOpacity": 59,
        "gradientMode": "none",
        "spanNulls": false,
        "insertNulls": false,
        "showPoints": "never",
        "pointSize": 5,
        "stacking": {
          "mode": "normal",
          "group": "A"
        },
        "axisPlacement": "auto",
        "axisLabel": "",
        "axisColorMode": "text",
        "axisBorderShow": false,
        "scaleDistribution": {
          "type": "linear"
        },
        "axisCenteredZero": false,
        "hideFrom": {
          "tooltip": false,
          "viz": false,
          "legend": false
        },
        "thresholdsStyle": {
          "mode": "off"
        }
      },
      "color": {
        "mode": "palette-classic"
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "unit": "none"
    },
    "overrides": []
  },
  "pluginVersion": "11.6.0-84214",
  "targets": [
    {
      "disableTextWrap": false,
      "editorMode": "code",
      "exemplar": false,
      "expr": "sum(CLS) - sum(CLS offset 10m)",
      "fullMetaSearch": false,
      "hide": true,
      "includeNullMetadata": true,
      "legendFormat": "__auto",
      "range": true,
      "refId": "A",
      "useBackend": false
    },
    {
      "disableTextWrap": false,
      "editorMode": "builder",
      "exemplar": false,
      "expr": "sum(increase(CLS[$__rate_interval]))",
      "fullMetaSearch": false,
      "hide": false,
      "includeNullMetadata": true,
      "legendFormat": "__auto",
      "range": true,
      "refId": "E",
      "useBackend": false,
      "datasource": {
        "uid": "grafanacloud-prom",
        "type": "prometheus"
      }
    }
  ],
  "datasource": {
    "type": "prometheus",
    "uid": "grafanacloud-prom"
  },
  "interval": "10m",
  "options": {
    "tooltip": {
      "mode": "multi",
      "sort": "none",
      "hideZeros": false
    },
    "legend": {
      "showLegend": true,
      "displayMode": "table",
      "placement": "right",
      "calcs": [
        "sum",
        "min",
        "max"
      ]
    }
  }
}

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No errors.

  • Did you follow any online instructions? If so, what is the URL?
    Related issues :

  1. Displaying results of increase() for every time window - #4 by mghildiy
  2. prometheus - Why is increase() showing only zero values when I can see the metric value increasing? - Stack Overflow

03-19 Update:
After try sum(CLS) - sum(CLS offset 10m), I got a chart seems like the increase value I want:

So anything wrong with my metric or increase() func?

Hi, can you share how the metric looks like?
Just run CLS and screen the result?

Thanks for your help, here is the chart when I just query CLS:

It has hundreds of labels and lines, this is not my expectation too.

Is there anything wrong with my data report to prom && grafana?

Update:
I think the root cause is I should NOT use the unique value delta as label. Isn’t it ?:red_question_mark:

And what is the best practice for report 1 metric with different label value?

So, from what I can tell the series presented are constant. An increase over a constant value is 0, so sum over 0s is 0 - that’s the most probable answer for your original question.

I think the root cause is I should NOT use the unique value delta as label.

Yeah, you really shouldn’t :smile: The rule of thumb I always use is “Has this label potential to be infinite”? If the answer is yes, it should not be a label in a metric. There’s a caution here that describes why is it a bad idea but - briefly - the more unique series, the greater overhead on Prometheus instance.

And what is the best practice for report 1 metric with different label value?

I don’t quite get your question, can you go into more details? E.g. give an example? (If you’re speaking of CLS metric, what does delta label represent?)