Build on Linux:
git clone https://github.com/MaxZamaliev/nginx-log-exporter.git
cd nginx-log-exporter
export GOPATH=`pwd`
go get github.com/hpcloud/tail
go get github.com/prometheus/client_golang/prometheus
go get github.com/prometheus/client_golang/prometheus/promhttp
go build nginx-log-exporter.go
Prepare nginx:
Add to your nginx.conf file:
geoip_country /usr/share/GeoIP/GeoIP.dat;
log_format custom '$remote_addr ($geoip_country_code) - $remote_user [$time_local] "$host" "$request" '
'$status $body_bytes_sent $request_time "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log custom;
Install on CentOS 8:
1. Copy binary file nginx-log-exporter to /usr/local/bin/
2. Create user:
useradd -M -s /bin/false nginx_exporter
3. Create file /etc/systemd/system/nginx-log_exporter.service with text:
[Unit]
Description=Prometheus nginx log Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=nginx_exporter
Group=nginx_exporter
Type=simple
ExecStart=/usr/local/bin/nginx-log-exporter
[Install]
WantedBy=multi-user.target
4. Enable and start service:
systemctl enable --now nginx-log-exporter
5. Test service:
curl http://localhost:9113/metrics