Caution
Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.
Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Collect Prometheus metrics
Grafana Agent is a telemetry collector with the primary goal of moving telemetry data from one location to another. In this tutorial, you’ll set up a Grafana Agent in Flow mode.
Prerequisites
Run the example
Run the following command in a terminal window:
curl https://raw.githubusercontent.com/grafana/agent/main/docs/sources/flow/tutorials/assets/runt.sh -O && bash ./runt.sh agent.river
The runt.sh
script does:
- Downloads the configurations necessary for Mimir, Grafana, and Grafana Agent.
- Downloads the docker image for Grafana Agent explicitly.
- Runs the docker-compose up command to bring all the services up.
Allow Grafana Agent to run for two minutes, then navigate to Grafana.
This example scrapes the Grafana Agent’s http://localhost:12345/metrics
endpoint and pushes those metrics to the Mimir instance.
Navigate to http://localhost:12345/graph
to view the Grafana Agent Flow UI.
The Agent displays the component pipeline in a dependency graph. See Scraping component and Remote Write component for details about the components used in this configuration. Click the nodes to navigate to the associated component page. There, you can view the state, health information, and, if applicable, the debug information.
Scraping component
The prometheus.scrape
component is responsible for scraping the metrics of a particular endpoint and passing them on to another component.
// prometheus.scrape is the name of the component and "default" is its label.
prometheus.scrape "default" {
// Tell the scraper to scrape at http://localhost:12345/metrics.
// The http:// and metrics are implied but able to be overwritten.
targets = [{"__address__" = "localhost:12345"}]
// Forward the scrape results to the receiver. In general,
// Flow uses forward_to to tell which receiver to send results to.
// The forward_to is an argument of prometheus.scrape.default and
// the receiver is an exported field of prometheus.remote_write.prom.
forward_to = [prometheus.remote_write.prom.receiver]
}
The prometheus.scrape "default"
annotation indicates the name of the component, prometheus.scrape
, and its label, default
. All components must have a unique combination of name and if applicable label.
The targets
attribute is an argument. targets
is a list of labels that specify the target via the special key __address__
. The scraper is targeting the Agent’s /metrics
endpoint. Both http
and /metrics
are implied but can be overridden.
The forward_to
attribute is an argument that references the export of the prometheus.remote_write.prom
component. This is where the scraper will send the metrics for further processing.
Remote Write component
The prometheus.remote_write
component is responsible for writing the metrics to a Prometheus-compatible endpoint (Mimir).
prometheus.remote_write "prom" {
endpoint {
url = "http://mimir:9009/api/v1/push"
}
}
Running without Docker
To try out the Grafana Agent without using Docker:
- Download the Grafana Agent.
- Set the environment variable
AGENT_MODE=flow
. - Run the agent with
grafana-agent run <path_to_flow_config>
.