diff --git a/.goreleaser.yml b/.goreleaser.yml index 873e226..399cb76 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -34,3 +34,20 @@ dockers: - prometheus-nginxlog-exporter goos: linux goarch: amd64 +nfpms: + - vendor: Martin Helmich + homepage: https://github.com/martin-helmich/prometheus-nginxlog-exporter + description: Export Prometheus metrics from NGINX (or compatible) log files + license: Apache 2.0 + formats: + - deb + - rpm + dependencies: + - systemd + bindir: /usr/sbin + files: + res/package/prometheus-nginxlog-exporter.service: /lib/systemd/system/prometheus-nginxlog-exporter.service + config_files: + res/package/default-config.hcl: /etc/prometheus-nginxlog-exporter.hcl + scripts: + postinstall: res/package/scripts/postinstall.sh \ No newline at end of file diff --git a/README.adoc b/README.adoc index fb519ae..ea29fc4 100644 --- a/README.adoc +++ b/README.adoc @@ -12,6 +12,7 @@ image:https://img.shields.io/github/workflow/status/martin-helmich/prometheus-ng image:https://quay.io/repository/martinhelmich/prometheus-nginxlog-exporter/status[link="https://quay.io/repository/martinhelmich/prometheus-nginxlog-exporter",Docker Repository on Quay] image:https://goreportcard.com/badge/github.com/martin-helmich/prometheus-nginxlog-exporter[link="https://goreportcard.com/report/github.com/martin-helmich/prometheus-nginxlog-exporter", Go Report Card] image:https://img.shields.io/github/license/martin-helmich/prometheus-nginxlog-exporter[GitHub] +image:https://img.shields.io/badge/donate-PayPal-yellow[link="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SEARYHPVS9U5N&source=url", Donate] Helper tool that continuously reads an NGINX log file and exports metrics to https://prometheus.io/[Prometheus]. @@ -289,18 +290,36 @@ relabel "request_uri" { } ---- -Running the collector ---------------------- +Installing & running the collector +---------------------------------- + +### DEB/RPM packages + +In the https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases[releases section], +you can find both DEB and RPM packages for download. These come with a dependency on systemd and +configure the exporter to be running automatically: + + $ wget https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases/download/v1.5.0/prometheus-nginxlog-exporter_v1.5.0_linux_amd64.deb + $ apt install ./prometheus-nginxlog-exporter_v1.5.0_linux_amd64.deb + +The packages drop a configuration file to `/etc/prometheus-nginxlog-exporter.hcl` which you can +adjust to your own needs. -### Systemd +### Manual installation, with systemd -You can find an example unit file for this service https://github.com/martin-helmich/prometheus-nginxlog-exporter/blob/master/systemd/prometheus-nginxlog-exporter.service[in this repository]. Simply copy the unit file to `/etc/systemd/system`: +If you do not want to use one of the pre-built packages, you can download the binary itself and +manually configure systemd to start it. You can find an example unit file for this service +https://github.com/martin-helmich/prometheus-nginxlog-exporter/blob/master/res/package/prometheus-nginxlog-exporter.service[in this repository]. +Simply copy the unit file to `/etc/systemd/system`: - $ wget -O /etc/systemd/system/prometheus-nginxlog-exporter.service https://raw.githubusercontent.com/martin-helmich/prometheus-nginxlog-exporter/master/systemd/prometheus-nginxlog-exporter.service + $ wget -O /etc/systemd/system/prometheus-nginxlog-exporter.service https://raw.githubusercontent.com/martin-helmich/prometheus-nginxlog-exporter/master/res/package/prometheus-nginxlog-exporter.service $ systemctl enable prometheus-nginxlog-exporter $ systemctl start prometheus-nginxlog-exporter -The shipped unit file expects the binary to be located in `/usr/local/bin/prometheus-nginxlog-exporter` and the configuration file in `/etc/prometheus-nginxlog-exporter.hcl`. Adjust to your own needs. +The shipped unit file expects the binary to be located in `/usr/sbin/prometheus-nginxlog-exporter` +(if you sideload the exporter without using your package manager, you might want to put it to +`/usr/local`, instead) and the configuration file in `/etc/prometheus-nginxlog-exporter.hcl`. Adjust +to your own needs. ### Docker diff --git a/res/package/default-config.hcl b/res/package/default-config.hcl new file mode 100644 index 0000000..e7e6da5 --- /dev/null +++ b/res/package/default-config.hcl @@ -0,0 +1,17 @@ +listen { + port = 4040 +} + +namespace "nginx" { + source = { + files = [ + "/var/log/nginx/access.log" + ] + } + + format = "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\"" + + labels { + app = "default" + } +} diff --git a/systemd/prometheus-nginxlog-exporter.service b/res/package/prometheus-nginxlog-exporter.service similarity index 64% rename from systemd/prometheus-nginxlog-exporter.service rename to res/package/prometheus-nginxlog-exporter.service index 3c41b8f..9e38073 100644 --- a/systemd/prometheus-nginxlog-exporter.service +++ b/res/package/prometheus-nginxlog-exporter.service @@ -3,7 +3,7 @@ Description=NGINX metrics exporter for Prometheus After=network-online.target [Service] -ExecStart=/usr/local/bin/prometheus-nginxlog-exporter -config-file /etc/prometheus-nginxlog-exporter.hcl +ExecStart=/usr/sbin/prometheus-nginxlog-exporter -config-file /etc/prometheus-nginxlog-exporter.hcl Restart=always ProtectSystem=full CapabilityBoundingSet= diff --git a/res/package/scripts/postinstall.sh b/res/package/scripts/postinstall.sh new file mode 100644 index 0000000..226a34e --- /dev/null +++ b/res/package/scripts/postinstall.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +systemctl daemon-reload +systemctl enable prometheus-nginxlog-exporter \ No newline at end of file