|
| 1 | +--- |
| 2 | +canonical: https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.mapping/ |
| 3 | +description: Learn about prometheus.mapping |
| 4 | +title: prometheus.mapping |
| 5 | +--- |
| 6 | + |
| 7 | +# prometheus.mapping |
| 8 | + |
| 9 | +Prometheus metrics follow the [OpenMetrics](https://openmetrics.io/) format. |
| 10 | +Each time series is uniquely identified by its metric name, plus optional |
| 11 | +key-value pairs called labels. Each sample represents a datapoint in the |
| 12 | +time series and contains a value and an optional timestamp. |
| 13 | + |
| 14 | +```text |
| 15 | +<metric name>{<label_1>=<label_val_1>, <label_2>=<label_val_2> ...} <value> [timestamp] |
| 16 | +``` |
| 17 | + |
| 18 | +The `prometheus.mapping` component create new labels on each metric passed |
| 19 | +along to the exported receiver by applying a mapping table to a label value. |
| 20 | + |
| 21 | +The most common use of `prometheus.mapping` is to create new labels with a high |
| 22 | +cardinality source label value (>1k) when a large set of regex is inefficient. |
| 23 | + |
| 24 | +You can specify multiple `prometheus.mapping` components by givin them |
| 25 | +different labels. |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```alloy |
| 30 | +prometheus.mapping "LABEL" { |
| 31 | + forward_to = RECEIVER_LIST |
| 32 | +
|
| 33 | + source_label = "labelA" |
| 34 | +
|
| 35 | + mapping = { |
| 36 | + "from" = {"labelB" = "to"}, |
| 37 | + ... |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## Arguments |
| 43 | + |
| 44 | +The following arguments are supported: |
| 45 | + |
| 46 | +Name | Type | Description | Default | Required |
| 47 | +---------------|---------------------------|-------------------------------------------------------------------------|---------|--------- |
| 48 | +`forward_to` | `list(MetricsReceiver)` | Where the metrics should be forwarded to, after relabeling takes place. | | yes |
| 49 | +`source_label` | `string` | Name of the source label to use for mapping. | | yes |
| 50 | +`mapping` | `map(string,map(string))` | Mapping from source label value to target labels name/value. | | yes |
| 51 | + |
| 52 | +## Exported fields |
| 53 | + |
| 54 | +The following fields are exported and can be referenced by other components: |
| 55 | + |
| 56 | +Name | Type | Description |
| 57 | +-----------|-------------------|----------------------------------------------------------- |
| 58 | +`receiver` | `MetricsReceiver` | The input receiver where samples are sent to be relabeled. |
| 59 | + |
| 60 | +## Component health |
| 61 | + |
| 62 | +`prometheus.mapping` is only reported as unhealthy if given an invalid |
| 63 | +configuration. In those cases, exported fields are kept at their last healthy |
| 64 | +values. |
| 65 | + |
| 66 | +## Debug information |
| 67 | + |
| 68 | +`prometheus.mapping` doesn't expose any component-specific debug information. |
| 69 | + |
| 70 | +## Debug metrics |
| 71 | + |
| 72 | +* `prometheus_mapping_metrics_processed` (counter): Total number of metrics processed. |
| 73 | +* `prometheus_mapping_metrics_written` (counter): Total number of metrics written. |
| 74 | + |
| 75 | +## Example |
| 76 | + |
| 77 | +You can create and an instance of a see `prometheus.mapping` component and see how |
| 78 | +it acts on the following metrics. |
| 79 | + |
| 80 | +```alloy |
| 81 | +prometheus.mapping "keep_backend_only" { |
| 82 | + forward_to = [prometheus.remote_write.onprem.receiver] |
| 83 | +
|
| 84 | + source_label = "app" |
| 85 | +
|
| 86 | + mapping = { |
| 87 | + "frontend" = {"team" = "teamA"} |
| 88 | + "backend" = {"team" = "teamB"} |
| 89 | + "database" = {"team" = "teamC"} |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +``` |
| 95 | +metric_a{__address__ = "localhost", instance = "development", app = "frontend"} 10 |
| 96 | +metric_a{__address__ = "localhost", instance = "development", app = "backend"} 2 |
| 97 | +metric_a{__address__ = "cluster_a", instance = "production", app = "frontend"} 7 |
| 98 | +metric_a{__address__ = "cluster_a", instance = "production", app = "backend"} 9 |
| 99 | +metric_a{__address__ = "cluster_b", instance = "production", app = "database"} 4 |
| 100 | +``` |
| 101 | + |
| 102 | +After applying the mapping a new `team` label is created based on mapping table |
| 103 | +and `app` label value. |
| 104 | + |
| 105 | +``` |
| 106 | +metric_a{team = "teamA", __address__ = "localhost", instance = "development", app = "frontend"} 10 |
| 107 | +metric_a{team = "teamB", __address__ = "localhost", instance = "development", app = "backend"} 2 |
| 108 | +metric_a{team = "teamA", __address__ = "cluster_a", instance = "production", app = "frontend"} 7 |
| 109 | +metric_a{team = "teamA", __address__ = "cluster_a", instance = "production", app = "backend"} 9 |
| 110 | +metric_a{team = "teamC", __address__ = "cluster_a", instance = "production", app = "database"} 4 |
| 111 | +``` |
| 112 | + |
| 113 | +The resulting metrics are then propagated to each receiver defined in the |
| 114 | +`forward_to` argument. |
| 115 | +<!-- START GENERATED COMPATIBLE COMPONENTS --> |
| 116 | + |
| 117 | +## Compatible components |
| 118 | + |
| 119 | +`prometheus.mapping` can accept arguments from the following components: |
| 120 | + |
| 121 | +- Components that export [Prometheus `MetricsReceiver`](../../../compatibility/#prometheus-metricsreceiver-exporters) |
| 122 | + |
| 123 | +`prometheus.mapping` has exports that can be consumed by the following components: |
| 124 | + |
| 125 | +- Components that consume [Prometheus `MetricsReceiver`](../../../compatibility/#prometheus-metricsreceiver-consumers) |
| 126 | + |
| 127 | +{{< admonition type="note" >}} |
| 128 | +Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. |
| 129 | +Refer to the linked documentation for more details. |
| 130 | +{{< /admonition >}} |
| 131 | + |
| 132 | +<!-- END GENERATED COMPATIBLE COMPONENTS --> |
0 commit comments