Prometheus Label Functions
In Prometheus, labels are key-value pairs associated with time series data. They allow you to add metadata and context to your metrics, enabling more granular and specific querying. Prometheus provides various label functions to manipulate and filter time series data based on these labels. Here are the main label functions in Prometheus:
1. label_replace: This function allows you to replace or modify labels of a time series. It takes four arguments: the input vector, the target label name, a regular expression to match the source label value, and a replacement string.
2. label_join: With this function, you can concatenate label values into a new label. It takes two arguments: the input vector and a delimiter string to join the labels.
3. label_drop: This function removes specified labels from the input vector, effectively reducing the dimensionality of the data.
4. label_keep: The "label_keep" function filters out all labels from the input vector except the specified ones. It helps to focus on specific labels while discarding the rest.
5. label_match: This function selects time series that match a given regular expression pattern for a specific label. It takes two arguments: the input vector and the regular expression pattern.
6. label_replace_all: Similar to "label_replace", this function replaces or modifies multiple labels of a time series in one step. It takes three arguments: the input vector, a set of pairs of regular expressions and replacement strings, and an optional parameter to control the behavior of replacing multiple labels.
7. label_map: This function maps source label values to target label values based on a provided mapping. It takes three arguments: the input vector, a mapping of source to target labels, and an optional default value for unmatched source labels.
8. label_set: With this function, you can add or modify label values of a time series. It takes three arguments: the input vector, the label name to set or modify, and the label value to assign.
These label functions provide powerful capabilities for manipulating and filtering time series data based on their labels in Prometheus. They allow you to modify, transform, or select specific time series based on the metadata associated with them, enabling more targeted and flexible querying and analysis.