---
title: "prometheus.exporter.snmp | Grafana Agent documentation"
description: "Learn about prometheus.exporter.snmp"
---

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

# prometheus.exporter.snmp

The `prometheus.exporter.snmp` component embeds [`snmp_exporter`](https://github.com/prometheus/snmp_exporter). `snmp_exporter` lets you collect SNMP data and expose them as Prometheus metrics.

> Note
> 
> `prometheus.exporter.snmp` uses the latest configuration introduced in version 0.26 of the Prometheus `snmp_exporter`.

## Usage

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

```alloy
prometheus.exporter.snmp "LABEL" {
  config_file = SNMP_CONFIG_FILE_PATH

  target "TARGET_NAME" {
    address = TARGET_ADDRESS
  }
}
```

## Arguments

The following arguments can be used to configure the exporter’s behavior. Omitted fields take their default values.

Expand table

| Name          | Type                 | Description                                      | Default | Required |
|---------------|----------------------|--------------------------------------------------|---------|----------|
| `config_file` | `string`             | SNMP configuration file defining custom modules. |         | no       |
| `config`      | `string` or `secret` | SNMP configuration as inline string.             |         | no       |

The `config_file` argument points to a YAML file defining which snmp\_exporter modules to use. Refer to [snmp\_exporter](https://github.com/prometheus/snmp_exporter#generating-configuration) for details on how to generate a configuration file.

The `config` argument must be a YAML document as string defining which SNMP modules and auths to use. `config` is typically loaded by using the exports of another component. For example,

- `local.file.LABEL.content`
- `remote.http.LABEL.content`
- `remote.s3.LABEL.content`

## Blocks

The following blocks are supported inside the definition of `prometheus.exporter.snmp` to configure collector-specific options:

Expand table

| Hierarchy   | Name                             | Description                                                 | Required |
|-------------|----------------------------------|-------------------------------------------------------------|----------|
| target      | [target](#target-block)          | Configures an SNMP target.                                  | yes      |
| walk\_param | [walk\_param](#walk_param-block) | SNMP connection profiles to override default SNMP settings. | no       |

### target block

The `target` block defines an individual SNMP target. The `target` block may be specified multiple times to define multiple targets. The label of the block is required and will be used in the target’s `job` label.

Expand table

| Name           | Type     | Description                                                           | Default | Required |
|----------------|----------|-----------------------------------------------------------------------|---------|----------|
| `address`      | `string` | The address of SNMP device.                                           |         | yes      |
| `module`       | `string` | SNMP module to use for polling.                                       | `""`    | no       |
| `auth`         | `string` | SNMP authentication profile to use.                                   | `""`    | no       |
| `walk_params`  | `string` | Config to use for this target.                                        | `""`    | no       |
| `snmp_context` | `string` | Override the `context_name` parameter in the SNMP configuration file. | `""`    | no       |

### walk\_param block

The `walk_param` block defines an individual SNMP connection profile that can be used to override default SNMP settings. The `walk_param` block may be specified multiple times to define multiple SNMP connection profiles.

Expand table

| Name              | Type       | Description                                   | Default | Required |
|-------------------|------------|-----------------------------------------------|---------|----------|
| `name`            | `string`   | Name of the module to override.               |         | no       |
| `max_repetitions` | `int`      | How many objects to request with GET/GETBULK. | `25`    | no       |
| `retries`         | `int`      | How many times to retry a failed request.     | `3`     | no       |
| `timeout`         | `duration` | Timeout for each individual SNMP request.     |         | no       |

## Exported fields

The following fields are exported and can be referenced by other components.

Expand table

| Name      | Type                | Description                                               |
|-----------|---------------------|-----------------------------------------------------------|
| `targets` | `list(map(string))` | The targets that can be used to collect exporter metrics. |

For example, the `targets` can either be passed to a `discovery.relabel` component to rewrite the targets’ label sets or to a `prometheus.scrape` component that collects the exposed metrics.

The exported targets use the configured [in-memory traffic](/docs/agent/latest/flow/concepts/component_controller/#in-memory-traffic) address specified by the [run command](/docs/agent/latest/flow/reference/cli/run/).

## Component health

`prometheus.exporter.snmp` is only reported as unhealthy if given an invalid configuration. In those cases, exported fields retain their last healthy values.

## Debug information

`prometheus.exporter.snmp` does not expose any component-specific debug information.

## Debug metrics

`prometheus.exporter.snmp` does not expose any component-specific debug metrics.

## Example

This example uses a [`prometheus.scrape` component](../prometheus.scrape/) to collect metrics from `prometheus.exporter.snmp`:

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

```alloy
prometheus.exporter.snmp "example" {
    config_file = "snmp_modules.yml"

    target "network_switch_1" {
        address     = "192.168.1.2"
        module      = "if_mib"
        walk_params = "public"
    }

    target "network_router_2" {
        address     = "192.168.1.3"
        module      = "mikrotik"
        walk_params = "private"
    }

    walk_param "private" {
        retries = "2"
    }

    walk_param "public" {
        retries = "2"
    }
}
// Configure a prometheus.scrape component to collect SNMP metrics.
prometheus.scrape "demo" {
    targets    = prometheus.exporter.snmp.example.targets
    forward_to = [ /* ... */ ]
}
```

This example is the same above with using an embedded configuration (with secrets):

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

```alloy
local.file "snmp_config" {
    path      = "snmp_modules.yml"
    is_secret = true
}

prometheus.exporter.snmp "example" {
    config = local.file.snmp_config.content

    target "network_switch_1" {
        address     = "192.168.1.2"
        module      = "if_mib"
        walk_params = "public"
    }

    target "network_router_2" {
        address     = "192.168.1.3"
        module      = "mikrotik"
        walk_params = "private"
    }

    walk_param "private" {
        retries = "2"
    }

    walk_param "public" {
        retries = "2"
    }
}
// Configure a prometheus.scrape component to collect SNMP metrics.
prometheus.scrape "demo" {
    targets    = prometheus.exporter.snmp.example.targets
    forward_to = [prometheus.remote_write.demo.receiver]
}

prometheus.remote_write "demo" {
    endpoint {
        url = PROMETHEUS_REMOTE_WRITE_URL

        basic_auth {
            username = USERNAME
            password = PASSWORD
        }
    }
}
```

Replace the following:

- `PROMETHEUS_REMOTE_WRITE_URL`: The URL of the Prometheus remote\_write-compatible server to send metrics to.
- `USERNAME`: The username to use for authentication to the remote\_write API.
- `PASSWORD`: The password to use for authentication to the remote\_write API.

## Compatible components

`prometheus.exporter.snmp` has exports that can be consumed by the following components:

- Components that consume [Targets](../../compatibility/#targets-consumers)

> Note
> 
> Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.
