3
# linecounter.mtail
counter line_count
/$/ {
  line_count++
}

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

如何labelsmetric?

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

4

1 回答 1

0

标签由 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()返回包含日志行的日志文件名。
于 2018-10-01T08:35:08.190 回答