nginx-prometheus-exporter.rst (4465B)
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 Download nginx-prometheus-exporter 23 ================================== 24 25 * Download 26 * Extract 27 * Copy to /usr/local/bin 28 * Set ownership and permissions 29 30 .. code-block:: console 31 32 # mkdir -p /tmp/nginx_exporter_tmp && cd /tmp/nginx_exporter_tmp 33 # wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v1.2.0/nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz 34 # tar axf nginx-prometheus-exporter_1.2.0_linux_amd64.tar.gz 35 # cd nginx-prometheus-exporter 36 # cp nginx-prometheus-exporter /usr/local/bin 37 38 39 Create a system user 40 ==================== 41 42 .. code-block:: console 43 44 # useradd --system --no-create-home --shell /bin/false nginx-exporter 45 46 47 Systemd configuration 48 ===================== 49 50 Nginx-prometheus-exporter systemd service file 51 ---------------------------------------------- 52 53 .. code-block:: systemd 54 55 # Path:/etc/systemd/system/nginx-exporter.service 56 57 [Unit] 58 Description=NGINX Prometheus Exporter 59 Requires=nginx-exporter.socket 60 61 [Service] 62 User=nginx-exporter 63 ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="http://127.0.0.1/metrics" --web.systemd-socket 64 65 [Install] 66 WantedBy=multi-user.target 67 68 69 Nginx-prometheus-exporter systemd socket file 70 --------------------------------------------- 71 72 .. code-block:: systemd 73 74 # Path: /etc/systemd/system/nginx-exporter.socket 75 76 [Unit] 77 Description=NGINX Prometheus Exporter 78 79 [Socket] 80 ListenStream=9113 81 82 [Install] 83 WantedBy=sockets.target 84 85 Modify the Prometheus configuration file 86 ======================================== 87 88 .. code-block:: yaml 89 90 # Path: /etc/prometheus/prometheus.yml 91 92 # Job, for nginx_exporter 93 - job_name: 'nginx_exporter' 94 static_configs: 95 - targets: ['localhost:9113'] # choose port number 96 97 98 Nginx configuration 99 =================== 100 101 .. code-block:: nginx 102 103 server { 104 listen localhost; 105 root /var/www/html; 106 index index.html; 107 server_name _; 108 109 location /metrics { 110 stub_status on; 111 access_log off; 112 allow 127.0.0.1; 113 deny all; 114 } 115 116 } 117 118 119 .. code-block:: console 120 121 ## Create the Nginx symbolic link to enable the virtualhost file 122 # ln -s /etc/nginx/sites-available/nginx-exporter.conf /etc/nginx/sites-enabled/nginx-exporter.conf 123 # nginx -t 124 # systemctl reload nginx 125 ## Check with curl 126 # curl http://localhost/metrics 127 128 Restart everything 129 ================== 130 131 .. code-block:: console 132 133 # systemctl daemon-reload # Only necessary if modified 134 # systemctl enable --now node-exporter.service 135 # systemctl status node-exporter.service 136 # systemctl restart prometheus.service 137 138 139 Close the 9113 port with Nginx 140 ============================== 141 142 * Change the nginx-exporter.socket file 143 144 .. code-block:: console 145 146 # Path: /etc/systemd/system/nginx-exporter.socket 147 148 [Unit] 149 Description=NGINX Prometheus Exporter 150 151 # Add here the loopback ip address 152 [Socket] 153 ListenStream=127.0.0.1:9113 154 155 [Install] 156 WantedBy=sockets.target 157 158 159 Add a new server block to Nginx 160 =============================== 161 162 .. code-block:: nginx 163 164 server { 165 listen 80; 166 listen [::]:80; 167 168 server_name ip_address | subdomain.ltd; 169 location /nginx-exporter { 170 proxy_pass http://localhost:9113; 171 } 172 173 } 174 175 Create a new dashboard in Grafana 176 ================================= 177 178 You can now go to the `Grafana dashboards <a href="https://grafana.taler.net/dashboards">`_ and easily 179 add the new dashboard for the Nginx Exporter program. Please make sure you choose the right Prometheus data source. 180 181 * Dashboard Id: 11199 182 * Dashboard URL: https://grafana.com/grafana/dashboards/11199-nginx/