martin-helmich / prometheus-nginxlog-exporter

Export metrics from Nginx access log files to Prometheus
Apache License 2.0
958 stars 173 forks source link

Something wrong with relabel match regexp | not working in some cases #377

Open itshikanov opened 10 months ago

itshikanov commented 10 months ago

Describe the bug hello. relabel match not working in some cases

To Reproduce nginx:

log_format syslog'$host\t$status\t$upstream_addr\t$request_method\t$upstream_response_time\t$request_time\t$request_length\t$body_bytes_sent\t$request';
access_log syslog:server=127.0.0.1:8887,tag=nginx syslog;

nginxlog-exporter config:

listen {
  port = 9102
}

namespace "nginx" {
  source = {
    syslog {
      listen_address = "udp://127.0.0.1:8887"
      format = "auto"
      tags = ["nginx"]
    }
  }
  format = "$host\t$status\t$upstream_addr\t$request_method\t$upstream_response_time\t$request_time\t$request_length\t$body_bytes_sent\t$request"
  relabel "host" { from = "host" }

  relabel "request_uri" {
    from = "request"
    split = 2
#    separator = " "

    match "^(.*)$" {
      replacement = "$1"
    }
  }

}

got metrics like this

nginx_http_upstream_time_seconds_hist_bucket{host="test.local",request_uri="",status="200",le="+Inf"} 587

problem:

request_uri=""

But when i add ',' or '\t' character at the end of log_format all work fine. example nginx:

log_format syslog'$host\t$status\t$upstream_addr\t$request_method\t$upstream_response_time\t$request_time\t$request_length\t$body_bytes_sent\t$request,';

nginxlog:

  format = "$host\t$status\t$upstream_addr\t$request_method\t$upstream_response_time\t$request_time\t$request_length\t$body_bytes_sent\t$request,"

result:

nginx_http_upstream_time_seconds_hist_count{host="test.local",request_uri="/v1/test/wesqwex?a=1",status="200"} 424