Path: blob/main/docs/sources/flow/tutorials/collecting-prometheus-metrics.md
4096 views
---
---
Collecting 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 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 configs necessary for Mimir, Grafana and the Grafana Agent.
Downloads the docker image for Grafana Agent explicitly.
Runs the docker-compose up command to bring all the services up.
Allow the 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
]({{< relref "../reference/components/prometheus.scrape.md" >}}) component is responsible for scraping the metrics of a particular endpoint and passing them on to another component.
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]({{< relref "../concepts/configuration_language/#attributes" >}}) is an [argument]({{< relref "../concepts/components.md">}}). 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]({{< relref "../concepts/components.md">}}) 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
]({{< relref "../reference/components/prometheus.remote_write.md" >}}) component is responsible for writing the metrics to a Prometheus-compatible endpoint (Mimir).
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>
.