Hi Everyone,

I need to handle a scenario where I add a label to ingested metrics, but 
only if the label does not already exist in the collected data. If the 
label is present in a metric, it should remain unchanged.

For example, given a set of metrics:

custom_metrics_from_server{ source="server1.example.com",status="run" } 
3213  
custom_metrics_from_server{ source="server1.example.com",status="pend" } 
3215

When additional metrics are collected from a node exporter, some will 
already have a "source=" label, while others will not:

custom_metrics_from_server{ source="server1.example.com",status="run" } 
3213  
custom_metrics_from_server{ source="server1.example.com",status="pend" } 
3215  
node_cooling_device_max_state{name="7",type="Processor"} 0

To ensure that all metrics contain the "source=" label without overriding 
existing ones, I figured the following approach using honor_labels and 
relabel_configs:

honor_labels: true  
relabel_configs:  
  - source_labels: [ _address_ ]  
    regex: "(.*):(.*)"  
    target_label: "source"  
    replacement: '${1}'

Is this the best way to handle this, or is there a more optimal approach?
Please advice.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/prometheus-users/5ffbef9e-d220-47dd-8ef4-9b60e4022381n%40googlegroups.com.

Reply via email to