martin-helmich / prometheus-nginxlog-exporter

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

Unable to get prometheus-nginxlog-exporter 1.8.0 to work with error "status=2/INVALIDARGUMENT" #163

Closed maco1717 closed 3 years ago

maco1717 commented 3 years ago

Hi,

I am having issue getting prometheus-nginxlog-exporter to work.

I have tried searching for the solution to my issue but havent found anything.

Any assistance would be appreciated.

Describe the issue I installed prometheus-nginxlog-exporter using the DEB and RPM packages following the instructions on the README.adoc

Configuration file (remove section, if not applicable):

listen {
  port = 4040
  address = "0.0.0.0"
}

consul {
  enable = false
}

namespace "nginx_some.com" {
  source = {
    files = [
      "/var/log/nginx/some.access"
    ]
  }

  format = "$remote_addr $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$request_time\" \"$upstream_connect_time\" \"$geoip2_data_city_name\" \"$geoip2_data_country_name\""

  labels {
    app = "some"
  }
}

Example log file (remove section, if not applicable):

Nov 29 13:18:50 proxy systemd[1]: Started NGINX metrics exporter for Prometheus.
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: loading configuration file /etc/prometheus-nginxlog-exporter.hcl
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: using configuration {Listen:{Port:4040 Address:0.0.0.0 MetricsEndpoint:/metrics} Consul:{Enable:false Address: Datacenter: Scheme: Token: Service:{ID: Name: Address: Tags:[]}>
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: panic: descriptor Desc{fqName: "nginx_some.com_http_response_count_total", help: "Amount of processed HTTP requests", constLabels: {}, variableLabels: [app method sta>
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: goroutine 1 [running]:
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc000088ff0, 0xc0001459d0, 0x1, 0x1)
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]:         /home/runner/go/pkg/mod/github.com/prometheus/client_golang@v1.7.1/prometheus/registry.go:401 +0xad
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: main.NewNSMetrics(0xc000114b00, 0xc000114b00)
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]:         /home/runner/work/prometheus-nginxlog-exporter/prometheus-nginxlog-exporter/main.go:54 +0x12d
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]: main.main()
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83805]:         /home/runner/work/prometheus-nginxlog-exporter/prometheus-nginxlog-exporter/main.go:220 +0x98d
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Failed with result 'exit-code'.
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Scheduled restart job, restart counter is at 4.
Nov 29 13:18:50 proxy systemd[1]: Stopped NGINX metrics exporter for Prometheus.
Nov 29 13:18:50 proxy systemd[1]: Started NGINX metrics exporter for Prometheus.
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: loading configuration file /etc/prometheus-nginxlog-exporter.hcl
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: using configuration {Listen:{Port:4040 Address:0.0.0.0 MetricsEndpoint:/metrics} Consul:{Enable:false Address: Datacenter: Scheme: Token: Service:{ID: Name: Address: Tags:[]}>
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: panic: descriptor Desc{fqName: "nginx_some.com_http_response_count_total", help: "Amount of processed HTTP requests", constLabels: {}, variableLabels: [app method sta>
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: goroutine 1 [running]:
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc000088ff0, 0xc0001459d0, 0x1, 0x1)
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]:         /home/runner/go/pkg/mod/github.com/prometheus/client_golang@v1.7.1/prometheus/registry.go:401 +0xad
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: main.NewNSMetrics(0xc000112b00, 0xc000112b00)
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]:         /home/runner/work/prometheus-nginxlog-exporter/prometheus-nginxlog-exporter/main.go:54 +0x12d
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]: main.main()
Nov 29 13:18:50 proxy prometheus-nginxlog-exporter[83810]:         /home/runner/work/prometheus-nginxlog-exporter/prometheus-nginxlog-exporter/main.go:220 +0x98d
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Failed with result 'exit-code'.
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Scheduled restart job, restart counter is at 5.
Nov 29 13:18:50 proxy systemd[1]: Stopped NGINX metrics exporter for Prometheus.
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Start request repeated too quickly.
Nov 29 13:18:50 proxy systemd[1]: prometheus-nginxlog-exporter.service: Failed with result 'exit-code'.
Nov 29 13:18:50 proxy systemd[1]: Failed to start NGINX metrics exporter for Prometheus.

Environment:

martin-helmich commented 3 years ago

Duplicate of #11:

The "namespace" is used as a prefix for the Prometheus metric names. These need to match the regular expression ^[a-zA-Z_:][a-zA-Z0-9_:]*$ (compare https://github.com/prometheus/common/blob/ad540c5ab198ab0c5172f5c6b602a49ab911b5ef/model/metric.go#L25-L28), which is enforced by the Prometheus client library. For this reason, there is no way to have a namespace containing a dash (or any other character not matched by this regexp).