---
title: Work with Prometheus gauges
description: Use Flux to query and transform Prometheus gauge metrics stored in InfluxDB. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
url: https://docs.influxdata.com/flux/v0/prometheus/metric-types/gauge/
estimated_tokens: 3608
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/prometheus/metric-types/gauge/
date: '2023-11-06T17:08:22-07:00'
lastmod: '2023-11-06T17:08:22-07:00'
---

Use Flux to query and transform Prometheus **gauge** metrics stored in InfluxDB.

>
>
> A *gauge* is a metric that represents a single numerical value that can arbitrarily go up and down.
>
>
>
> [Prometheus metric types](https://prometheus.io/docs/concepts/metric_types/#gauge)
>
>

##### Example gauge metric in Prometheus data

```sh
# HELP example_gauge_current Current number of items as example gauge metric
# TYPE example_gauge_current gauge
example_gauge_current 128
```

Generally gauge metrics can be used as they are reported and don’t require any
additional processing.

The examples below include example data collected from the **InfluxDB OSS 2.x `/metrics` endpoint**using `prometheus.scrape()` and stored in InfluxDB.

#### Prometheus metric parsing formats

Query structure depends on the [Prometheus metric parsing format](/influxdb/v2/reference/prometheus-metrics/)used to scrape the Prometheus metrics.
Select the appropriate metric format version below.

* [Calculate the rate of change in gauge values](#calculate-the-rate-of-change-in-gauge-values)
* [Calculate the average rate of change in specified time windows](#calculate-the-average-rate-of-change-in-specified-time-windows)

## Calculate the rate of change in gauge values

#### Metric version 2 ####

1. Filter results by the `prometheus` measurement and **counter metric name** field.
2. Use [`derivative()`](/flux/v0/stdlib/universe/derivative/) to calculate the rate
   of change between gauge values.
   By default, `derivative()` returns the rate of change per second.
   Use the [`unit` parameter](/flux/v0/stdlib/universe/derivative/#unit) to
   customize the rate unit.
   To replace negative derivatives with null values, set the[`nonNegative` parameter](/flux/v0/stdlib/universe/derivative/#unit) to `true`.

```js
from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "prometheus" and r._field == "go_goroutines")
    |> derivative(nonNegative: true)
```

<img alt="Raw Prometheus gauge metric in InfluxDB" width="364" src="/img/flux/0-x-prometheus-gauge-input.png">

<img alt="Derivative of Prometheus gauge metrics in InfluxDB" src="/img/flux/0-x-prometheus-gauge-derivative-output.png" width="364">

[](#view-example-input-and-output-data)

View example input and output data

#### Example normalized counter data

|       \_time       |\_measurement|   \_field    |\_value|
|--------------------|-------------|--------------|-------|
|2021-01-01T00:00:00Z| prometheus  |go\_goroutines|1571.97|
|2021-01-01T00:00:10Z| prometheus  |go\_goroutines|1577.35|
|2021-01-01T00:00:20Z| prometheus  |go\_goroutines|1591.67|
|2021-01-01T00:00:30Z| prometheus  |go\_goroutines|1598.85|
|2021-01-01T00:00:40Z| prometheus  |go\_goroutines|1600.0 |
|2021-01-01T00:00:50Z| prometheus  |go\_goroutines|1598.04|
|2021-01-01T00:01:00Z| prometheus  |go\_goroutines|1602.93|

#### Example difference output

|       \_time       |\_measurement|   \_field    |     \_value      |
|--------------------|-------------|--------------|------------------|
|2021-01-01T00:00:10Z| prometheus  |go\_goroutines|0.5379999999999882|
|2021-01-01T00:00:20Z| prometheus  |go\_goroutines|1.4320000000000164|
|2021-01-01T00:00:30Z| prometheus  |go\_goroutines|0.7179999999999837|
|2021-01-01T00:00:40Z| prometheus  |go\_goroutines|0.1150000000000091|
|2021-01-01T00:00:50Z| prometheus  |go\_goroutines|                  |
|2021-01-01T00:01:00Z| prometheus  |go\_goroutines| 0.48900000000001 |

1. Filter results by the **counter metric name** measurement and `gauge` field.
2. Use [`derivative()`](/flux/v0/stdlib/universe/derivative/) to calculate the rate
   of change between gauge values.
   By default, `derivative()` returns the rate of change per second.
   Use the [`unit` parameter](/flux/v0/stdlib/universe/derivative/#unit) to
   customize the rate unit.
   To replace negative derivatives with null values, set the[`nonNegative` parameter](/flux/v0/stdlib/universe/derivative/#unit) to `true`.

```js
from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "go_goroutines" and r._field == "gauge")
    |> derivative(nonNegative: true)
```

<img alt="Raw Prometheus gauge metric in InfluxDB" width="364" src="/img/flux/0-x-prometheus-gauge-input.png">

<img width="364" src="/img/flux/0-x-prometheus-gauge-derivative-output.png" alt="Derivative of Prometheus gauge metrics in InfluxDB">

[](#view-example-input-and-output-data)

View example input and output data

#### Example gauge data

|       \_time       |\_measurement |\_field|\_value|
|--------------------|--------------|-------|-------|
|2021-01-01T00:00:00Z|go\_goroutines| gauge |1571.97|
|2021-01-01T00:00:10Z|go\_goroutines| gauge |1577.35|
|2021-01-01T00:00:20Z|go\_goroutines| gauge |1591.67|
|2021-01-01T00:00:30Z|go\_goroutines| gauge |1598.85|
|2021-01-01T00:00:40Z|go\_goroutines| gauge |1600.0 |
|2021-01-01T00:00:50Z|go\_goroutines| gauge |1598.04|
|2021-01-01T00:01:00Z|go\_goroutines| gauge |1602.93|

#### Example difference output

|       \_time       |\_measurement |\_field|     \_value      |
|--------------------|--------------|-------|------------------|
|2021-01-01T00:00:10Z|go\_goroutines| gauge |0.5379999999999882|
|2021-01-01T00:00:20Z|go\_goroutines| gauge |1.4320000000000164|
|2021-01-01T00:00:30Z|go\_goroutines| gauge |0.7179999999999837|
|2021-01-01T00:00:40Z|go\_goroutines| gauge |0.1150000000000091|
|2021-01-01T00:00:50Z|go\_goroutines| gauge |                  |
|2021-01-01T00:01:00Z|go\_goroutines| gauge | 0.48900000000001 |

## Calculate the average rate of change in specified time windows

#### Metric version 2 ####

1. Import the [`experimental/aggregate` package](/flux/v0/stdlib/experimental/aggregate/).

2. Filter results by the `prometheus` measurement and **counter metric name** field.

3. Use [`aggregate.rate()`](/flux/v0/stdlib/experimental/aggregate/rate/)to calculate the average rate of change per time window.

   * Use the [`every` parameter](/flux/v0/stdlib/experimental/aggregate/rate/#every)to define the time window interval.
   * Use the [`unit` parameter](/flux/v0/stdlib/experimental/aggregate/rate/#unit)to customize the rate unit. By default, `aggregate.rate()` returns the per second
     (`1s`) rate of change.
   * Use the [`groupColumns` parameter](/flux/v0/stdlib/experimental/aggregate/rate/#groupcolumns)to specify columns to group by when performing the aggregation.

```js
import "experimental/aggregate"

from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "prometheus" and r._field == "go_goroutines")
    |> aggregate.rate(every: 10s, unit: 1s)
```

<img alt="Raw Prometheus gauge metric in InfluxDB" width="364" src="/img/flux/0-x-prometheus-gauge-input.png">

<img alt="Calculate the average rate of change of Prometheus gauge metrics per time window with Flux" src="/img/flux/0-x-prometheus-gauge-aggregate-rate-output.png" width="364">

[](#view-example-input-and-output-data)

View example input and output data

> [!Note]
> > [!Note]
> `_start` and `_stop` columns have been omitted.

#### Example gauge data

|       \_time       |\_measurement|   \_field    |\_value|
|--------------------|-------------|--------------|-------|
|2021-01-01T00:00:00Z| prometheus  |go\_goroutines|1571.97|
|2021-01-01T00:00:10Z| prometheus  |go\_goroutines|1577.35|
|2021-01-01T00:00:20Z| prometheus  |go\_goroutines|1591.67|
|2021-01-01T00:00:30Z| prometheus  |go\_goroutines|1598.85|
|2021-01-01T00:00:40Z| prometheus  |go\_goroutines|1600.0 |
|2021-01-01T00:00:50Z| prometheus  |go\_goroutines|1598.04|
|2021-01-01T00:01:00Z| prometheus  |go\_goroutines|1602.93|

#### Example aggregate.rate output

|       \_time       |     \_value      |
|--------------------|------------------|
|2021-01-01T00:00:10Z|                  |
|2021-01-01T00:00:20Z|0.5379999999999882|
|2021-01-01T00:00:30Z|1.4320000000000164|
|2021-01-01T00:00:40Z|0.7179999999999837|
|2021-01-01T00:00:50Z|0.1150000000000091|
|2021-01-01T00:01:00Z|                  |

1. Import the [`experimental/aggregate` package](/flux/v0/stdlib/experimental/aggregate/).

2. Filter results by the **counter metric name** measurement and `gauge` field.

3. Use [`aggregate.rate()`](/flux/v0/stdlib/experimental/aggregate/rate/)to calculate the average rate of change per time window.

   * Use the [`every` parameter](/flux/v0/stdlib/experimental/aggregate/rate/#every)to define the time window interval.
   * Use the [`unit` parameter](/flux/v0/stdlib/experimental/aggregate/rate/#unit)to customize the rate unit. By default, `aggregate.rate()` returns the per second
     (`1s`) rate of change.
   * Use the [`groupColumns` parameter](/flux/v0/stdlib/experimental/aggregate/rate/#groupcolumns)to specify columns to group by when performing the aggregation.

```js
import "experimental/aggregate"

from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "go_goroutines" and r._field == "gauge")
    |> aggregate.rate(every: 10s, unit: 1s)
```

<img width="364" alt="Raw Prometheus gauge metric in InfluxDB" src="/img/flux/0-x-prometheus-gauge-input.png">

<img width="364" src="/img/flux/0-x-prometheus-gauge-aggregate-rate-output.png" alt="Calculate the average rate of change of Prometheus gauge metrics per time window with Flux">

[](#view-example-input-and-output-data)

View example input and output data

`_start` and `_stop` columns have been omitted.

#### Example normalized counter data

|       \_time       |\_measurement |\_field|\_value|
|--------------------|--------------|-------|-------|
|2021-01-01T00:00:00Z|go\_goroutines| gauge |1571.97|
|2021-01-01T00:00:10Z|go\_goroutines| gauge |1577.35|
|2021-01-01T00:00:20Z|go\_goroutines| gauge |1591.67|
|2021-01-01T00:00:30Z|go\_goroutines| gauge |1598.85|
|2021-01-01T00:00:40Z|go\_goroutines| gauge |1600.0 |
|2021-01-01T00:00:50Z|go\_goroutines| gauge |1598.04|
|2021-01-01T00:01:00Z|go\_goroutines| gauge |1602.93|

#### Example aggregate.rate output

|       \_time       |     \_value      |
|--------------------|------------------|
|2021-01-01T00:00:10Z|                  |
|2021-01-01T00:00:20Z|0.5379999999999882|
|2021-01-01T00:00:30Z|1.4320000000000164|
|2021-01-01T00:00:40Z|0.7179999999999837|
|2021-01-01T00:00:50Z|0.1150000000000091|
|2021-01-01T00:01:00Z|                  |

#### Related

* [Prometheus metric types](https://prometheus.io/docs/concepts/metric_types/)
* [Prometheus metric parsing formats](/influxdb/v2/reference/prometheus-metrics/)

[prometheus](/flux/v0/tags/prometheus/)
| _time | _measurement | _field | _value |
| --- | --- | --- | --- |
| _time | _measurement | _field | _value |
| 2021-01-01T00:00:00Z | prometheus | go_goroutines | 1571.97 |
| 2021-01-01T00:00:10Z | prometheus | go_goroutines | 1577.35 |
| 2021-01-01T00:00:20Z | prometheus | go_goroutines | 1591.67 |
| 2021-01-01T00:00:30Z | prometheus | go_goroutines | 1598.85 |
| 2021-01-01T00:00:40Z | prometheus | go_goroutines | 1600.0 |
| 2021-01-01T00:00:50Z | prometheus | go_goroutines | 1598.04 |
| 2021-01-01T00:01:00Z | prometheus | go_goroutines | 1602.93 |

| _time | _measurement | _field | _value |
| --- | --- | --- | --- |
| _time | _measurement | _field | _value |
| 2021-01-01T00:00:10Z | prometheus | go_goroutines | 0.5379999999999882 |
| 2021-01-01T00:00:20Z | prometheus | go_goroutines | 1.4320000000000164 |
| 2021-01-01T00:00:30Z | prometheus | go_goroutines | 0.7179999999999837 |
| 2021-01-01T00:00:40Z | prometheus | go_goroutines | 0.1150000000000091 |
| 2021-01-01T00:00:50Z | prometheus | go_goroutines |  |
| 2021-01-01T00:01:00Z | prometheus | go_goroutines | 0.48900000000001 |

| _time | _measurement | _field | _value |
| --- | --- | --- | --- |
| _time | _measurement | _field | _value |
| 2021-01-01T00:00:00Z | go_goroutines | gauge | 1571.97 |
| 2021-01-01T00:00:10Z | go_goroutines | gauge | 1577.35 |
| 2021-01-01T00:00:20Z | go_goroutines | gauge | 1591.67 |
| 2021-01-01T00:00:30Z | go_goroutines | gauge | 1598.85 |
| 2021-01-01T00:00:40Z | go_goroutines | gauge | 1600.0 |
| 2021-01-01T00:00:50Z | go_goroutines | gauge | 1598.04 |
| 2021-01-01T00:01:00Z | go_goroutines | gauge | 1602.93 |

| _time | _measurement | _field | _value |
| --- | --- | --- | --- |
| _time | _measurement | _field | _value |
| 2021-01-01T00:00:10Z | go_goroutines | gauge | 0.5379999999999882 |
| 2021-01-01T00:00:20Z | go_goroutines | gauge | 1.4320000000000164 |
| 2021-01-01T00:00:30Z | go_goroutines | gauge | 0.7179999999999837 |
| 2021-01-01T00:00:40Z | go_goroutines | gauge | 0.1150000000000091 |
| 2021-01-01T00:00:50Z | go_goroutines | gauge |  |
| 2021-01-01T00:01:00Z | go_goroutines | gauge | 0.48900000000001 |

| _time | _measurement | _field | _value |
| --- | --- | --- | --- |
| _time | _measurement | _field | _value |
| 2021-01-01T00:00:00Z | prometheus | go_goroutines | 1571.97 |
| 2021-01-01T00:00:10Z | prometheus | go_goroutines | 1577.35 |
| 2021-01-01T00:00:20Z | prometheus | go_goroutines | 1591.67 |
| 2021-01-01T00:00:30Z | prometheus | go_goroutines | 1598.85 |
| 2021-01-01T00:00:40Z | prometheus | go_goroutines | 1600.0 |
| 2021-01-01T00:00:50Z | prometheus | go_goroutines | 1598.04 |
| 2021-01-01T00:01:00Z | prometheus | go_goroutines | 1602.93 |

| _time | _value |
| --- | --- |
| _time | _value |
| 2021-01-01T00:00:10Z |  |
| 2021-01-01T00:00:20Z | 0.5379999999999882 |
| 2021-01-01T00:00:30Z | 1.4320000000000164 |
| 2021-01-01T00:00:40Z | 0.7179999999999837 |
| 2021-01-01T00:00:50Z | 0.1150000000000091 |
| 2021-01-01T00:01:00Z |  |

| _time | _measurement | _field | _value |
| --- | --- | --- | --- |
| _time | _measurement | _field | _value |
| 2021-01-01T00:00:00Z | go_goroutines | gauge | 1571.97 |
| 2021-01-01T00:00:10Z | go_goroutines | gauge | 1577.35 |
| 2021-01-01T00:00:20Z | go_goroutines | gauge | 1591.67 |
| 2021-01-01T00:00:30Z | go_goroutines | gauge | 1598.85 |
| 2021-01-01T00:00:40Z | go_goroutines | gauge | 1600.0 |
| 2021-01-01T00:00:50Z | go_goroutines | gauge | 1598.04 |
| 2021-01-01T00:01:00Z | go_goroutines | gauge | 1602.93 |

| _time | _value |
| --- | --- |
| _time | _value |
| 2021-01-01T00:00:10Z |  |
| 2021-01-01T00:00:20Z | 0.5379999999999882 |
| 2021-01-01T00:00:30Z | 1.4320000000000164 |
| 2021-01-01T00:00:40Z | 0.7179999999999837 |
| 2021-01-01T00:00:50Z | 0.1150000000000091 |
| 2021-01-01T00:01:00Z |  |
