Create a pipeline that adds the team label to metrics
In this milestone, you create a configuration pipeline that does the following:
Collects Linux host metrics
Labels those metrics with the
teamattribute of each collector using pipeline attribute injectionSends the metrics to Grafana Cloud.
To create and assign the pipeline, complete the following steps. If you already know your collectors have a team attribute, skip the optional steps at the start.
Go to Fleet Management.
Optional: Check whether your collectors have a
teamattribute.In the Select Attribute dropdown, check that
teamis listed. If it isn’t, no collector has ateamattribute yet. You must assign theteamattribute to your collectors before continuing.If
teamis listed, select it, set the operator to=~, and enter.+as the value. Check that the collector list includes all the collectors you want to assign. If any are missing, assign theteamattribute to them before you continue.For help assigning attributes, refer to Categorize a collector fleet and then return to this milestone.
Click the Inventory tab.
Click Filter to add an attribute filter.
Click the Select Attribute dropdown.
Click the Remote configuration tab.
Click Create configuration pipeline.
Make sure Alloy is selected as the collector type, then click Custom configuration.
Click Next to define the pipeline.
In the Name field, enter this name for the pipeline:
team_cost_metrics.Copy the following pipeline, paste it into the editor, and replace the
PROMETHEUS_REMOTE_WRITE_URLandMETRICS_USERNAMEplaceholders with your own values. To find both values, sign in to your Grafana Cloud Portal, select your stack, and click Details in the Prometheus section. The Remote Write Endpoint section lists the URL and the username.prometheus.exporter.unix "default" { } prometheus.scrape "default" { targets = prometheus.exporter.unix.default.targets forward_to = [prometheus.relabel.team.receiver] job_name = "integrations/node_exporter" } prometheus.relabel "team" { forward_to = [prometheus.remote_write.grafana_cloud.receiver] rule { action = "replace" target_label = "team" replacement = argument.attributes.value["team"] } } prometheus.remote_write "grafana_cloud" { endpoint { url = "PROMETHEUS_REMOTE_WRITE_URL" basic_auth { username = "METRICS_USERNAME" password = sys.env("GCLOUD_RW_API_KEY") } } }Click Test configuration pipeline and wait for the Configuration test passed message.
Click Next to assign the pipeline to collectors.
In the Select Attribute dropdown, select
team.Set the operator to
=~to match with a regular expression.In the Select Value field, enter
.+. The collector list updates in real time and shows every collector that has ateamvalue.Click + to add a second matching attribute. The pipeline collects Linux host metrics, so it must match only Linux collectors.
In the new row, select the
osattribute, keep the=operator, and enterlinuxas the value.Click Save, then confirm in the dialog to save the pipeline.
In the Active column, turn on the toggle for the
team_cost_metricspipeline. A new pipeline is inactive until you activate it.Caution: When you activate the pipeline, every matched collector starts sending metrics to Grafana Cloud at their next poll. This telemetry can affect your bill.
Click Activate to confirm.
Your pipeline is active. Each matched collector applies the pipeline on its next poll and starts sending metrics with a team label.
In the next milestone, you confirm that the team label appears on your metrics.