Friday, 6 June 2025

Prometheus deriv() Function to track How Fast Your Metrics Are Changing

The deriv() function in Prometheus calculates how fast a value is increasing or decreasing over time.

What does deriv() do?

The deriv() function in Prometheus helps you to measure how quickly a gauge value is changing, whether it's increasing or decreasing. It does this by estimating the slope of the time series using linear regression over a specified time range.

 

A gauge is a type of metric that represents a value that can go up or down (e.g., memory usage, temperature).

 

The deriv() function calculates the rate of change per second in the given range.

 

Let’s say we want to know how fast the memory used by the Go application is changing. We can use the deriv() function on the go_memstats_stack_sys_bytes metric:

 

deriv(go_memstats_stack_sys_bytes[5m])

 

Here’s what’s happening:

 

·      go_memstats_stack_sys_bytes is a metric that tracks the number of bytes the Go application is using for the stack.

·      [5m] means we’re looking at the last 5 minutes of data.

·      deriv() calculates how fast this value is changing per second during that 5-minute period.

 

Sample Response 

{
  "status": "success",
  "data": {
    "resultType": "vector",
    "result": [
      {
        "metric": {
          "instance": "localhost:9090",
          "job": "prometheus"
        },
        "value": [1744432119.588, "-251.30299717489223"]
      },
      {
        "metric": {
          "instance": "localhost:9100",
          "job": "node_exporter"
        },
        "value": [1744432119.588, "70.62736246054475"]
      }
    ]
  }
}

Rate of Change: -251.30299717489223

This indicates that the metric value for Prometheus is decreasing at a rate of 251.30 units per second. A negative value suggests that the metric is declining over time. In this case, Prometheus is likely losing memory or some resource at a fast rate (depending on the metric being tracked).

 

In summary, for the instance "Prometheus (localhost:9090)", the metric being monitored is decreasing at a rate of 251.30 units per second. This could represent a metric like memory or storage usage that’s going down (for example, freed memory or deallocated space).

 

Rate of Change: 70.62736246054475

This means that the metric value for Node Exporter is increasing at a rate of 70.63 units per second. A positive value indicates that the metric is increasing over time. In this case, it might indicate that some resource or usage is rising (like memory or CPU usage).

 

In summary for the instance "Node Exporter (localhost:9100)"," The metric being monitored is increasing at a rate of 70.63 units per second. This might represent something like memory usage or disk space increasing, which would be expected in many system monitoring scenarios.

 

In summary, If you're interested in understanding how fast something is changing, like memory usage, system resources, or any value that fluctuates, use deriv() is the go-to function in Prometheus for calculating that rate.

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment