nginx-prometheus-exporter.rst (4520B)
1 .. 2 This file is part of GNU TALER. 3 Copyright (C) 2014-2023 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 2.1, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 16 @author Javier Sepulveda 17 18 19 Nginx Prometheus Exporter 20 ######################### 21 22 .. contents:: Table of Contents 23 :depth: 1 24 :local: 25 26 Download nginx-prometheus-exporter 27 ================================== 28 29 * Download 30 * Extract 31 * Copy to /usr/local/bin 32 * Set ownership and permissions 33 34 .. code-block:: console 35 36 # mkdir -p /tmp/nginx_exporter_tmp && cd /tmp/nginx_exporter_tmp 37 # wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v1.2.0/nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz 38 # tar axf nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz 39 # cd nginx-prometheus-exporter 40 # cp nginx-prometheus-exporter /usr/local/bin 41 42 43 Create a system user 44 ==================== 45 46 .. code-block:: console 47 48 # useradd --system --no-create-home --shell /bin/false nginx-exporter 49 50 51 Systemd configuration 52 ===================== 53 54 Nginx-prometheus-exporter systemd service file 55 ---------------------------------------------- 56 57 .. code-block:: systemd 58 59 # Path:/etc/systemd/system/nginx-exporter.service 60 61 [Unit] 62 Description=NGINX Prometheus Exporter 63 Requires=nginx-exporter.socket 64 65 [Service] 66 User=nginx-exporter 67 ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="http://127.0.0.1/metrics" --web.systemd-socket 68 69 [Install] 70 WantedBy=multi-user.target 71 72 73 Nginx-prometheus-exporter systemd socket file 74 --------------------------------------------- 75 76 .. code-block:: systemd 77 78 # Path: /etc/systemd/system/nginx-exporter.socket 79 80 [Unit] 81 Description=NGINX Prometheus Exporter 82 83 [Socket] 84 ListenStream=9113 85 86 [Install] 87 WantedBy=sockets.target 88 89 Modify the Prometheus configuration file 90 ======================================== 91 92 .. code-block:: yaml 93 94 # Path: /etc/prometheus/prometheus.yml 95 96 # Job, for nginx_exporter 97 - job_name: 'nginx_exporter' 98 static_configs: 99 - targets: ['localhost:9113'] # choose port number 100 101 102 Nginx configuration 103 =================== 104 105 .. code-block:: nginx 106 107 server { 108 listen localhost; 109 root /var/www/html; 110 index index.html; 111 server_name _; 112 113 location /metrics { 114 stub_status on; 115 access_log off; 116 allow 127.0.0.1; 117 deny all; 118 } 119 120 } 121 122 123 .. code-block:: console 124 125 ## Create the Nginx symbolic link to enable the virtualhost file 126 # ln -s /etc/nginx/sites-available/nginx-exporter.conf /etc/nginx/sites-enabled/nginx-exporter.conf 127 # nginx -t 128 # systemctl reload nginx 129 ## Check with curl 130 # curl http://localhost/metrics 131 132 Restart everything 133 ================== 134 135 .. code-block:: console 136 137 # systemctl daemon-reload # Only necessary if modified 138 # systemctl enable --now node-exporter.service 139 # systemctl status node-exporter.service 140 # systemctl restart prometheus.service 141 142 143 Close the 9113 port with Nginx 144 ============================== 145 146 * Change the nginx-exporter.socket file 147 148 .. code-block:: console 149 150 # Path: /etc/systemd/system/nginx-exporter.socket 151 152 [Unit] 153 Description=NGINX Prometheus Exporter 154 155 # Add here the loopback ip address 156 [Socket] 157 ListenStream=127.0.0.1:9113 158 159 [Install] 160 WantedBy=sockets.target 161 162 163 Add a new server block to Nginx 164 =============================== 165 166 .. code-block:: nginx 167 168 server { 169 listen 80; 170 listen [::]:80; 171 172 server_name ip_address | subdomain.ltd; 173 location /nginx-exporter { 174 proxy_pass http://localhost:9113; 175 } 176 177 } 178 179 Create a new dashboard in Grafana 180 ================================= 181 182 You can now go to the `Grafana dashboards <a href="https://grafana.taler.net/dashboards">`_ and easily 183 add the new dashboard for the Nginx Exporter program. Please make sure you choose the right Prometheus data source. 184 185 * Dashboard Id: 11199 186 * Dashboard URL: https://grafana.com/grafana/dashboards/11199-nginx/