Skip to content

niedbalski/nginx-log-exporter

 
 

Repository files navigation

Export metrics from nginx access logs to Prometheus

main build status

A small utility for exporting metrics inferred from nginx access logs to Prometheus.

Metrics

The following metrics are currently supported:

  • Response counts, by HTTP response code
  • "Detailed" response counts, by HTTP response code, method, and path (only enabled for a configurable set of exact-match paths; see -monitored_paths)
  • Response time (i.e. request processing latency) distribution, by HTTP response code
  • Response size (i.e. bytes sent, headers inclusive) distribution, by HTTP response code

Building

go get github.com/niedbalski/nginx-log-exporter will fetch all required dependencies and build the nginx-log-exporter binary (which will be placed in your $GOPATH/bin).

If working from a local copy of this source tree, go build from the base directory should suffice (producing a binary reflecting any local changes you have made).

Log format

Two access log formats are supported:

  • JSON: A custom format described in more detail below (default).
  • Common Log Format: CLF is the basic default format for nginx (well, really an extension thereof). Note that response time metrics are not supported under CLF.

Which format is expected by the exporter is controlled by the -access_log_format flag (supported values being "CLF" and "JSON" with the latter being the default).

If using the JSON log line format, nginx should be configured to write access logs with at least the following fields present (additional fields are fine, and will be ignored):

# Example minimal log format
log_format json_combined escape=json '{ '
    '"time": "$time_iso8601", '
    '"request": "$request", '
    '"status": "$status", '
    '"bytes_sent": $bytes_sent, '
    '"request_time": $request_time }';
access_log /var/log/nginx/access.log json_combined;

Note: The escape parameter for log_format is only supported by nginx 1.11.8 and later.

Running on GCE

If running in a GCE VM instance, you can set the -use_metadata_service_labels flag to pull the instance name and zone from the Metadata service, which will in turn be added to your metrics (along with any additional key=value label pairs provided via the -custom_labels flag).

About

Export nginx access logs to Prometheus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 97.9%
  • Makefile 1.7%
  • Dockerfile 0.4%