将自定义标签注入 up 指标

Inject custom labels into up metric

无法使用重新标记向 up 指标添加标签。这是我从 Brian Prometheus Up 和 运行.

的书中记得的内容

我想知道在我不控制 Prometheus 导出器的情况下如何添加标签。

metric_relabel_configs 确实不适用于 up,因为:

Metric relabeling does not apply to automatically generated timeseries such as up.

但是,如果你真的需要它,relabel_config can add the label at configuration time (or using labels config of static_config):

  relabel_configs:
  - source_labels: job
    target_label:  my_new_label
    replacement:   label_value

使用 relabel_config 会将标签添加到所有摄取的指标,如果您需要它仅应用于 up,您可以在摄取所有指标时将其删除:

  metric_relabel_configs:
  - regex: my_new_label
    action: labeldrop