nginx-log-exporter

command module
v0.0.0-...-750d6ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2023 License: BSD-2-Clause Imports: 12 Imported by: 0

README

Export metrics from nginx access logs to Prometheus

build-and-test status

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

Metrics

The following metrics are currently supported:

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

Building

go get github.com/swfrench/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).

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
file/mock_tailer
Package mock_tailer is a generated GoMock package.
Package mock_tailer is a generated GoMock package.
metrics/mock_metrics
Package mock_metrics is a generated GoMock package.
Package mock_metrics is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL