here's some additional context - the following metrics are exported by the node exporter via text file: custom_metrics_from_server{ source="server1.example.com",status="run" } 3213 custom_metrics_from_server{ source="server1.example.com",status="pend" } 3215
hence they have source= label, whereas rest of the metrics are collected from the system by node exporter. i.e. node_cooling_device_max_state{name="7",type="Processor"} 0 On Tuesday, March 11, 2025 at 11:09:58 PM UTC+5:30 mohan garden wrote: > 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 prometheus-users+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/prometheus-users/4993ffe9-39c2-4709-817e-d35afa6e343bn%40googlegroups.com.