【问题标题】:How to put labels on mtail metrics for prometheus?如何在 prometheus 的 mtail 指标上添加标签?
【发布时间】:2018-01-17 11:11:38
【问题描述】:
# linecounter.mtail
counter line_count
/$/ {
  line_count++
}

对于linecounter.mtail 程序,Prometheusline_count{prog="linecounter.mtail",instance="bd0a0d119df6"} 2

如何在metric 中添加额外的labels

我找不到任何关于它的描述。

【问题讨论】:

  • 你是如何设置 Prometheus 的,你想添加什么样的标签?
  • @svenwltr,我想放任何标签,它是否与Prometheus 设置相关?如果我想让mtail 响应包含user-define-lebelsmetrics 而不是mtail-host-ip:port/metrics HTTP 请求。
  • 我正在寻找相同的。 @SangminKi​​m 你有没有发现?

标签: prometheus exporter


【解决方案1】:

标签由 mtail 根据声明的指标自动创建!

所有指标都在指标声明中,例如:

counter my_http_requests_total by log_file, request_method

示例:

假设您有一个 HTTP 服务器日志文件,其中包含 GETPOST

192.168.0.1 GET /foo
192.168.0.2 GET /bar
192.168.0.1 POST /bar

使用以下 Mtail 程序:

counter my_http_requests_total by log_file, request_method

/^/ +
/(?P<hostname>[0-9A-Za-z\.:-]+) / +
/(?P<request_method>[A-Z]+) / +
/(?P<URI>\S+).*/ +
/$/ {
    my_http_requests_total[getfilename()][$request_method][]++
}

Prometheus 生成的指标是:

my_http_requests_total{log_file="test.log",request_method="GET",prog="test.mtail"} 4242
my_http_requests_total{log_file="test.log",request_method="POST",prog="test.mtail"} 42

--

这里有两个神奇的指标(可以使用 Prometheus 重新标记规则来破坏):

  • prog 是 mtail 程序名称(脚本
  • mtail 函数getfilename() 返回包含日志行的日志文件名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 2019-08-09
    • 1970-01-01
    • 2021-12-16
    • 2021-10-27
    相关资源
    最近更新 更多