martin-helmich / prometheus-nginxlog-exporter

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

Missing metrics #361

Closed Last-Icarus closed 1 year ago

Last-Icarus commented 1 year ago

Hello, I configured a nginx-exporter Docker image, but it doesn`t export any metrics I'm also using nginx image that shares a log volume with the exporter

Docker command

docker run -d \
    --name nginx-exporter \
    -v /var/project/nginx/logs:/mnt/nginxlogs \
    -v /var/project/nginx/config.hcl:/etc/prometheus-nginxlog-exporter.hcl \
    -v /var/project/nginx/metrics:/var \
    -p 8040:4040 \
    ghcr.io/martin-helmich/prometheus-nginxlog-exporter/exporter:v1.11.0-amd64 \
    -config-file /etc/prometheus-nginxlog-exporter.hcl

The simpliest config.hcl

listen {
  port = 4040
  metrics_endpoint = "/metrics"
}

namespace "app" {
  format = "$request"
  print_log = true
  source_files = ["/mnt/nginxlogs/access.log"]
}

nginx.conf

    ...
    log_format main '$request';

    access_log  /var/log/nginx/access.log main;
    ...

nginx-exporter container logs

info    prometheus-nginxlog-exporter/main.go:162        loading configuration file /etc/prometheus-nginxlog-exporter.hcl
warn   config/struct_namespace.go:98   No globs for /mnt/nginxlogs/access.log
info    prometheus-nginxlog-exporter/main.go:139        starting listener for namespace app
info    prometheus-nginxlog-exporter/main.go:148        running HTTP server on address 0.0.0.0:4040, serving metrics at /metrics
GET /home_page/ HTTP/1.1
GET /home_page/ HTTP/1.1
GET /home_page/ HTTP/1.1
GET /home_page/ HTTP/1.1

Because print_log is set to true the exporter duplicates the nginx logs

http also doesn't work

$ curl localhost:8040
404 page not found

I assume that there has to be another message after the HTTP server starts. At least "Waiting for /mnt/nginxlogs/access.log to appear..." but nothing happens

I've also tried image with :latest tag and got the following logs:

loading configuration file /etc/prometheus-nginxlog-exporter.hcl
No globs for /mnt/nginxlogs/access.log
using configuration {Listen:{Port:4040 Address:0.0.0.0 MetricsEndpoint:/metrics} Consul:{Enable:false Address: Datacenter: Scheme: Token: Service:{ID: Name: Address: Tags:[]}} Namespaces:[{Name:app NamespaceLabelName: NamespaceLabels:map[] MetricsOverride:<nil> NamespacePrefix: SourceFiles:[/mnt/nginxlogs/access.log] SourceData:{Files:[/mnt/nginxlogs/access.log] Syslog:<nil>} Parser: Format:$request Labels:map[] RelabelConfigs:[] HistogramBuckets:[] PrintLog:true OrderedLabelNames:[] OrderedLabelValues:[]}] EnableExperimentalFeatures:false EnableExperimentalFeaturesOld:false}
starting listener for namespace app
running HTTP server on address 0.0.0.0:4040, serving metrics at /metrics
Seeked /mnt/nginxlogs/access.log - &{Offset:0 Whence:2}

And curl localhost:8040 still returns 404

The same issue when trying RPM package instead of Docker. What should I do?

Environment: