nginx-exporter

一个元 nginx 导出器,结合了两个不同的导出器。「A meta nginx exporter that combines two different exporters」

Github星跟踪图

nginx-exporter

Docker Repository
license
GitHub release

A meta nginx exporter that combines two different exporters

Development Status nginx-exporter is in an early development phase.
Expect breaking changes any time.

References

Available Metrics

From mtail

All metrics provide these labels: vhost, method, code, content_type.

  • nginx_requests_total – Counter of processed requests.
  • nginx_request_duration_milliseconds – Histogram of all response times.
  • nginx_response_size_bytes_sum – Sum of all response body sizes.

The nginx_request_duration_milliseconds histogram currently defines these buckets:
100ms, 200ms, 300ms, 500ms, 800ms, 1300ms, 2100ms, 3400ms, 5500ms, +Inf

From status page

  • nginx_connections_current – Number of connections currently processed by nginx (labels: state)
  • nginx_connections_processed_total – Number of connections processed by nginx (labels: stage)

Also there is up and nginx_exporter_scrape_failures_total.

Configuration

Nginx

Access Logs

The exporter needs a particular access logs format, since the default format
doesn't include response times. This needs to be specified in the http
section:

log_format mtail '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent $request_time '
                 '"$http_referer" "$http_user_agent" "$content_type" "$upstream_cache_status"';

The access logs needs to be enabled in each server section:

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

Status Page

The status page is disabled by default. We suggest to listen on a separate port, so the path does not clash with any existing resource:

server {
    listen 8888;
    location /nginx_status {
      stub_status on;
      access_log  off;
      allow       127.0.0.1;
      deny        all;
    }
}

You can also keep the port private and do deny external traffic to the port.

Exporter

This exporter is configured via environment variables:

  • NGINX_ACCESS_LOGS -- Path to the nginx access logs (eg
    /var/log/nginx/mtail/access.log in the example above).
  • NGINX_STATUS_URI -- URI to the nginx status page (eg
    http://localhost:8888/nginx_status in the example above).

Prometheus

The exporter provides three metric endpoints:

  • 3093 -- mtail exporter
  • 9113 -- status page exporter
  • 9397 -- merged metrics from mtail and status page exporter

Kubernetes

The exporter is supposed to run as a sidecar. Here is an example config:

apiVersion: extensions/v1beta1
kind: Deployment

metadata:
  name: my-nginx
  labels:
    app: my-nginx

spec:
  selector:
    matchLabels:
      app: my-nginx

  template:
    metadata:
      name: my-nginx
      labels:
        app: my-nginx
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9397"

    spec:
      containers:
      - name: "nginx"
        image: "my-nginx" # nginx image with modified config file

        volumeMounts:
        - name: mtail
          mountPath: /var/log/nginx/mtail

      - name: exporter
        image: quay.io/rebuy/nginx-exporter:v1.1.0

        ports:
        - containerPort: 9397

        env:
        - name: NGINX_ACCESS_LOGS
          value: /var/log/nginx/mtail/access.log
        - name: NGINX_STATUS_URI
          value: http://localhost:8888/nginx_status

        volumeMounts:
        - name: mtail
          mountPath: /var/log/nginx/mtail

      volumes:
      - name: mtail
        emptyDir: {}

概览

名称与所有者rebuy-de/nginx-exporter
主编程语言Dockerfile
编程语言Dockerfile (语言数: 1)
平台
许可证MIT License
发布数3
最新版本名称v1.1.0 (发布于 )
第一版名称v1.0.0 (发布于 )
创建于2018-02-06 07:47:50
推送于2022-12-09 10:09:14
最后一次提交
星数11
关注者数24
派生数6
提交数39
已启用问题?
问题数2
打开的问题数0
拉请求数14
打开的拉请求数0
关闭的拉请求数1
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?
去到顶部