Path

Create an Alloy pipeline that adds the team attribute to metrics as a label and assign it to Linux collectors that have a team attribute.

Estimated time: 3 min

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 team attribute of each collector using pipeline attribute injection

  • Sends 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.

  1. Go to Fleet Management.

  2. Optional: Check whether your collectors have a team attribute.

    In the Select Attribute dropdown, check that team is listed. If it isn’t, no collector has a team attribute yet. You must assign the team attribute to your collectors before continuing.

    If team is 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 the team attribute to them before you continue.

    For help assigning attributes, refer to Categorize a collector fleet and then return to this milestone.

    1. Click the Inventory tab.

    2. Click Filter to add an attribute filter.

    3. Click the Select Attribute dropdown.

  3. Click the Remote configuration tab.

  4. Click Create configuration pipeline.

  5. Make sure Alloy is selected as the collector type, then click Custom configuration.

  6. Click Next to define the pipeline.

  7. In the Name field, enter this name for the pipeline: team_cost_metrics.

  8. Copy the following pipeline, paste it into the editor, and replace the PROMETHEUS_REMOTE_WRITE_URL and METRICS_USERNAME placeholders 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.

    Alloy
    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")
        }
      }
    }
  9. Click Test configuration pipeline and wait for the Configuration test passed message.

  10. Click Next to assign the pipeline to collectors.

  11. In the Select Attribute dropdown, select team.

  12. Set the operator to =~ to match with a regular expression.

  13. In the Select Value field, enter .+. The collector list updates in real time and shows every collector that has a team value.

  14. Click + to add a second matching attribute. The pipeline collects Linux host metrics, so it must match only Linux collectors.

  15. In the new row, select the os attribute, keep the = operator, and enter linux as the value.

  16. Click Save, then confirm in the dialog to save the pipeline.

  17. In the Active column, turn on the toggle for the team_cost_metrics pipeline. 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.

  18. 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.