.. This file is part of GNU TALER. Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. TALER is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with TALER; see the file COPYING. If not, see @author Javier Sepulveda Nginx Prometheus Exporter ######################### .. contents:: Table of Contents :depth: 1 :local: Download nginx-prometheus-exporter ================================== * Download * Extract * Copy to /usr/local/bin * Set ownership and permissions .. code-block:: console # mkdir -p /tmp/nginx_exporter_tmp && cd /tmp/nginx_exporter_tmp # wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v1.2.0/nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz # tar axf nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz # cd nginx-prometheus-exporter # cp nginx-prometheus-exporter /usr/local/bin Create a system user ==================== .. code-block:: console # useradd --system --no-create-home --shell /bin/false nginx-exporter Systemd configuration ===================== Nginx-prometheus-exporter systemd service file ---------------------------------------------- .. code-block:: systemd # Path:/etc/systemd/system/nginx-exporter.service [Unit] Description=NGINX Prometheus Exporter Requires=nginx-exporter.socket [Service] User=nginx-exporter ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="http://127.0.0.1/metrics" --web.systemd-socket [Install] WantedBy=multi-user.target Nginx-prometheus-exporter systemd socket file --------------------------------------------- .. code-block:: systemd # Path: /etc/systemd/system/nginx-exporter.socket [Unit] Description=NGINX Prometheus Exporter [Socket] ListenStream=9113 [Install] WantedBy=sockets.target Modify the Prometheus configuration file ======================================== .. code-block:: yaml # Path: /etc/prometheus/prometheus.yml # Job, for nginx_exporter - job_name: 'nginx_exporter' static_configs: - targets: ['localhost:9113'] # choose port number Nginx configuration =================== .. code-block:: nginx server { listen localhost; root /var/www/html; index index.html; server_name _; location /metrics { stub_status on; access_log off; allow 127.0.0.1; deny all; } } .. code-block:: console ## Create the Nginx symbolic link to enable the virtualhost file # ln -s /etc/nginx/sites-available/nginx-exporter.conf /etc/nginx/sites-enabled/nginx-exporter.conf # nginx -t # systemctl reload nginx ## Check with curl # curl http://localhost/metrics Restart everything ================== .. code-block:: console # systemctl daemon-reload # Only necessary if modified # systemctl enable --now node-exporter.service # systemctl status node-exporter.service # systemctl restart prometheus.service Close the 9113 port with Nginx ============================== * Change the nginx-exporter.socket file .. code-block:: console # Path: /etc/systemd/system/nginx-exporter.socket [Unit] Description=NGINX Prometheus Exporter # Add here the loopback ip address [Socket] ListenStream=127.0.0.1:9113 [Install] WantedBy=sockets.target Add a new server block to Nginx =============================== .. code-block:: nginx server { listen 80; listen [::]:80; server_name ip_address | subdomain.ltd; location /nginx-exporter { proxy_pass http://localhost:9113; } } Create a new dashboard in Grafana ================================= You can now go to the `Grafana dashboards `_ and easily add the new dashboard for the Nginx Exporter program. Please make sure you choose the right Prometheus data source. * Dashboard Id: 11199 * Dashboard URL: https://grafana.com/grafana/dashboards/11199-nginx/