martin-helmich / prometheus-nginxlog-exporter

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

Relabel from path #388

Open andreymal opened 6 months ago

andreymal commented 6 months ago

I have a nginx configuration similar to:

server {
  # ...
  access_log /var/log/nginx/app1/access.log;
}

server {
  # ...
  access_log /var/log/nginx/app2/access.log;
}

It would be handy to be able to extract the application name from the log file path. Something like this:

namespace "nginx" {
  source = {
    files = [
      "/var/log/nginx/access.log",
      "/var/log/nginx/*/access.log",
    ]
  }

  relabel "app" {
    from = "log_path"

    match "^/var/log/nginx/(.+?)/access\\.log$" {
      replacement = "$1"
    }

    # ... and maybe a fallback value like "other" if no matches found
  }
}