---
title: "Increase efficiency with reusable configuration pipelines | Grafana Cloud documentation"
description: "Learn how to make your collector configurations more efficient with reusable pipelines"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Increase efficiency with reusable configuration pipelines

Save time and effort by reusing Grafana Fleet Management configuration pipelines across your fleet.

- Set environment variables for properties that vary and create a pipeline that reads those variables.
- Inject collector attributes into configuration pipelines to label telemetry.
- Use collector attributes to customize how pipelines are applied.

## Configuration properties with different values

Configuring a fleet of collectors can be cumbersome, especially when configuration contexts, such as host credentials or scrape targets, differ. To avoid creating multiple versions of the same pipeline, Fleet Management can help you efficiently reuse standard configuration pipelines across deployments, with the help of environment variables. Set variables where your collector runs and read those variables in the pipeline. Grafana Alloy uses the [`sys.env`](https://grafana.com/docs/grafana-cloud/send-data/alloy/reference/stdlib/sys/#sysenv) configuration function. The OpenTelemetry Collector uses environment variable substitution.

### Example: Scrape different targets

For example, if you want to collect metrics on all deployments but you need to scrape different targets, set a target environment variable on each host, refer to the variable in the pipeline, and then roll out the pipeline to your collectors:

#### Alloy scrape configuration

Use `sys.env` to read the target location from the host environment:

Alloy ![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
prometheus.scrape "example" {
  targets = [
    {"__address__" = sys.env("TARGET_LOCATION")},
  ]
  forward_to = [prometheus.remote_write.staging.receiver]
}
```

#### OpenTelemetry Collector scrape configuration

Set the `TARGET_LOCATION` environment variable on each collector, reference it in the Prometheus receiver configuration, and then roll out the same configuration to all collectors:

YAML ![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg) Copy

```yaml
receivers:
  prometheus:
    config:
      scrape_configs:
        - job_name: example
          static_configs:
            - targets:
                - ${env:TARGET_LOCATION}

exporters:
  prometheus_remote_write:
    endpoint: "https://<your-endpoint>"

service:
  pipelines:
    metrics:
      receivers: [prometheus]
      exporters: [prometheus_remote_write]
```

## Telemetry labels based on collector attributes

When you [assign attributes](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/onboard-collectors/standalone-alloy/#add-remote-attributes) to a collector, you are categorizing them based on meaningful characteristics, such as team ownership or environment. You might also want to persist those attributes in the labels you apply to your collected data.

Alloy supports [injecting collector attributes](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/configuration-pipelines/pipeline-attribute-injection/) into pipelines, allowing you to reuse a single pipeline rather than creating separate pipelines for each set of labels.

### Example: Add telemetry labels for owner and environment

For example, if you’ve assigned attributes to collectors for `owner` and `env` and want to export metrics with corresponding labels, relabel the telemetry in the pipeline and then roll it out to your collectors.

#### Alloy attribute injection

If you’re configuring an Alloy instance, use `argument.attributes.value` to read collector attributes and add them as telemetry labels:

Alloy ![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
discovery.relabel "example" {
  targets = prometheus.exporter.self.example.targets

  rule {
    source_labels = ["__address__"]
    target_label  = "owner"
    replacement   = argument.attributes.value["owner"]
  }

  rule {
    source_labels = ["__address__"]
    target_label  = "env"
    replacement   = argument.attributes.value["env"]
  }
}
```

## Customized pipelines by application workload or technology

Match configuration pipelines to your collectors based on the applications or technologies that are running on the host. You can add attributes to the collector that match to each workload or technology. If you have standard telemetry that needs to be collected from all hosts, such as server or database monitoring, create a single default configuration pipeline that applies to all collectors on all machines with a universal matching attribute. If you remove an application from a host, remove the attribute from that host’s collector to disable the pipeline for that instance.

### Example: Apply the Node.js integration to hosts running your application

Collect metrics from all hosts where your Node.js application is running.

1. Add the attribute `application=MYAPP` to each collector where the application is hosted. You can add a local attribute directly to the [`remotecfg` block](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/onboard-collectors/standalone-alloy/#add-remotecfg-to-local-configurations) of the local configuration or add a remote attribute in the [Fleet Management application](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/onboard-collectors/standalone-alloy/#add-remote-attributes) or with an [API request](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/collector-api/).
2. Follow the instructions to create a new configuration pipeline using an [integration template](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/configuration-pipelines/integrations/) and select the [Node.js integration](https://grafana.com/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-nodejs/).
3. Add the matching attribute `application=MYAPP` to the pipeline.
4. Activate the pipeline to begin collecting telemetry from your Node.js applications.

### Example: Apply the MySQL integration to every collector

If all of your machines are running MySQL, use a default configuration pipeline to collect metrics and logs from them.

1. Add the attribute `default=MYSQL` to every collector by selecting all collectors in the Fleet Management application and clicking the [bulk edit tool](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/onboard-collectors/standalone-alloy/#add-remote-attributes). Make sure to scroll through your entire fleet to load all your collectors before selecting them. You can also make a [`BulkUpdateCollectorsRequest`](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/collector-api/#bulkupdatecollectorsrequest) to the Collector API.
2. Follow the instructions to create a new configuration pipeline using an [integration template](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/set-up/configuration-pipelines/integrations/) and select the [MySQL integration](https://grafana.com/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-mysql/).
3. Review the configuration and set up any parameters required. For MySQL, the default configuration expects the connection string to be available in a file at `/var/lib/alloy/mysql-secret`.
4. Add the matching attribute `default=MYSQL` to the pipeline.
5. Activate the pipeline to begin collecting telemetry from your MySQL databases.
