---
title: "Filter Prometheus metrics | Grafana Agent documentation"
description: "Learn how to filter Prometheus metrics"
---

# Filter Prometheus metrics

In this tutorial, you’ll add a new component [prometheus.relabel](/docs/agent/v0.43/flow/reference/components/prometheus.relabel/) using [relabel.river](/docs/agent/v0.43/flow/tutorials/assets/flow_configs/relabel.river) to filter metrics. This tutorial uses the same base as [Collecting Prometheus metrics](/docs/agent/v0.43/flow/tutorials/collecting-prometheus-metrics/).

## Prerequisites

- [Docker](https://www.docker.com/products/docker-desktop)

## Run the example

The `prometheus.relabel` component is used to drop, add, or filter metrics.

Run the following:

Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```bash
curl https://raw.githubusercontent.com/grafana/agent/main/docs/sources/flow/tutorials/assets/runt.sh -O && bash ./runt.sh relabel.river
```

The `runt.sh` script does:

1. Downloads the configurations necessary for Mimir, Grafana and Grafana Agent.
2. Downloads the docker image for Grafana Agent explicitly.
3. Runs the docker-compose up command to bring all the services up.

Allow Grafana Agent to run for two minutes, then navigate to [Grafana](http://localhost:3000/explore?orgId=1&left=%5B%22now-1h%22%2C%22now%22%2C%22Mimir%22%2C%7B%22refId%22%3A%22A%22%2C%22instant%22%3Atrue%2C%22range%22%3Atrue%2C%22exemplar%22%3Atrue%2C%22expr%22%3A%22agent_build_info%7B%7D%22%7D%5D) page and the `service` label will be there with the `api_server` value.

## What’s happening?

1. The Prometheus scraper is sending the metrics to the filter.
2. The filter is adding a new label named `service` with the value `api_server`.
3. The filter is then sending metrics to the remote\_write endpoint.

## Update the service value

Open the `relabel.river` file that was downloaded and change the name of the service to `api_server_v2`, then run `bash ./runt.sh relabel.river`. Allow Grafana Agent to run for two minutes, then navigate to the [Grafana](http://localhost:3000/explore?orgId=1&left=%5B%22now-1h%22%2C%22now%22%2C%22Mimir%22%2C%7B%22refId%22%3A%22A%22%2C%22instant%22%3Atrue%2C%22range%22%3Atrue%2C%22exemplar%22%3Atrue%2C%22expr%22%3A%22agent_build_info%7B%7D%22%7D%5D) page, and the new label will be updated. The old value `api_server` may still show up in the graph but hovering over the lines will show that that value stopped being scraped and was replaced with `api_server_v2`.
