---
title: "Components | Grafana Cloud documentation"
description: "Learn about components"
---

# Components

*Components* are the building blocks of Alloy. Each component performs a single task, such as retrieving secrets, collecting metrics, or processing data.

You learned about blocks, attributes, and expressions in the previous section. Components use the same syntax structure. They’re special blocks that Alloy knows how to execute. When you define a component block in your configuration, Alloy creates a running instance that performs the component’s specific task.

Components are the key to the flexibility of Alloy. You can combine them to create data pipelines that collect, transform, and send telemetry data exactly how you need.

## Component structure

Every component has two main parts:

- **Arguments:** Settings that configure the component’s behavior. These are the attributes and blocks you define inside the component block.
- **Exports:** Values that the component makes available to other components. The running component generates these exports and they can change over time.

When Alloy loads your configuration:

1. It reads the arguments you provided in each component block.
2. It creates a running instance of the component with those arguments.
3. The component starts its work and may update its exports as it runs.
4. Other components can reference these exports in their arguments.

## Component syntax

Components use the block syntax you learned about earlier. The general pattern is:

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

```alloy
COMPONENT_NAME "LABEL" {
  // Arguments (attributes and nested blocks)
  attribute_name = "value"

  nested_block {
    setting = "value"
  }
}
```

The `COMPONENT_NAME` tells Alloy which type of component to create. The `"LABEL"` is a unique identifier you choose to distinguish between multiple instances of the same component type.

## Component names

Each component has a name that describes its purpose. For example:

- `local.file` retrieves file contents from disk.
- `prometheus.scrape` collects Prometheus metrics.
- `loki.write` sends log data to Loki.

You define components by specifying the component name with a user-defined label:

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

```alloy
local.file "my_config" {
  filename = "/etc/app/config.yaml"
}

prometheus.scrape "api_metrics" {
  targets = [{"__address__" = "localhost:8080"}]
  forward_to = [prometheus.remote_write.default.receiver]
}
```

## Component references

You reference components by combining their name with their label. For example, you can reference the `local.file` component labeled `my_config` as `local.file.my_config`.

The combination of component name and label must be unique in your configuration. This allows you to define multiple instances of the same component type:

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

```alloy
prometheus.scrape "api" {
  targets = [{"__address__" = "api.example.com:8080"}]
  forward_to = [prometheus.remote_write.production.receiver]
}

prometheus.scrape "database" {
  targets = [{"__address__" = "db.example.com:9090"}]
  forward_to = [prometheus.remote_write.production.receiver]
}
```

## Component exports

Components can share data through exports. When one component references another component’s export, it creates a connection between them. You’ll learn more about these component references in [Expressions](/docs/grafana-cloud/send-data/alloy/get-started/expressions).

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

```alloy
local.file "api_key" {
  filename = "/etc/secrets/api.key"
}

prometheus.remote_write "production" {
  endpoint {
    url = "https://prometheus.example.com/api/v1/write"

    basic_auth {
      username = "metrics"
      password = local.file.api_key.content  // Reference the file content
    }
  }
}
```

In this example:

1. The `local.file` component reads a file and exports its content.
2. The `prometheus.remote_write` component uses that content as a password.
3. When the file changes, Alloy automatically updates the `local.file` component’s exports.
4. This causes Alloy to re-evaluate the `prometheus.remote_write` component with the new password.

You’ll learn the details of how to write these references in [Expressions](/docs/grafana-cloud/send-data/alloy/get-started/expressions).

## Next steps

Now that you understand what components are and how they work, learn how to use them effectively:

- [Configure components](/docs/grafana-cloud/send-data/alloy/get-started/components/configure-components) - Learn how to define and configure components with arguments and blocks
- [Build data pipelines](/docs/grafana-cloud/send-data/alloy/get-started/components/build-pipelines) - Connect components together to create data processing workflows
- [Component controller](/docs/grafana-cloud/send-data/alloy/get-started/components/component-controller) - Understand how Alloy manages components at runtime

To extend component functionality:

- [Custom components](/docs/grafana-cloud/send-data/alloy/get-started/components/custom-components) - Create reusable custom components for your specific needs
- [Community components](/docs/grafana-cloud/send-data/alloy/get-started/components/community-components) - Use components shared by the Alloy community

For hands-on learning:

- [Tutorials](/docs/grafana-cloud/send-data/alloy/tutorials) - Build complete data collection pipelines step by step

For reference:

- [Expressions](/docs/grafana-cloud/send-data/alloy/get-started/expressions) - Use component exports in dynamic configurations
- [Alloy syntax](/docs/grafana-cloud/send-data/alloy/get-started/syntax) - Explore advanced syntax features and patterns
- [Component reference](/docs/grafana-cloud/send-data/alloy/reference/components) - Browse all available components and their options
