prometheus.rst (6491B)
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 Installation of Prometheus 19 ########################## 20 21 Download Prometheus 22 =================== 23 24 * Download 25 * Extract 26 * Copy files to /usr/local/bin 27 * Set ownership and permissions 28 29 .. code-block:: console 30 31 $ wget https://github.com/prometheus/prometheus/releases/download/v2.52.0/prometheus-2.52.0.linux-amd64.tar.gz -O /tmp/prometheus.tar.gz 32 $ cd /tmp 33 $ tar -xvzf prometheus.tar.gz 34 $ mkdir /etc/prometheus 35 $ mkdir /var/lib/prometheus 36 37 .. code-block:: console 38 39 $ chown prometheus:prometheus /etc/prometheus 40 $ chown prometheus:prometheus /var/lib/prometheus/ 41 $ cp prometheus promtool /usr/local/bin/ 42 $ chown prometheus:prometheus /usr/local/bin/prometheus 43 $ chown prometheus:prometheus /usr/local/bin/promtool 44 $ cp -R consoles console_libraries /etc/prometheus/ 45 $ chown -R prometheus:prometheus /etc/prometheus/consoles 46 $ chown -R prometheus:prometheus /etc/prometheus/console_libraries 47 $ chown prometheus:prometheus /etc/prometheus/prometheus.yml 48 49 50 Create a system user 51 ==================== 52 53 .. code-block:: console 54 55 $ useradd --no-create-home --shell /bin/false prometheus 56 57 58 Configuring Prometheus 59 ====================== 60 61 The main configuration file of Prometheus is in the YAML format, and it is located 62 on /etc/prometheus/prometheus.yml. Please be aware YAML, is a very sensitive format, 63 where white spaces matter. 64 65 .. note:: 66 If you find that your prometheus service is not working properly, 67 please always check the prometheus.yml configuration file, or the systemd prometheus.service file, 68 as in most of occasions, these are the main source of errors. 69 70 71 Prometheus main configuration file 72 ---------------------------------- 73 74 .. code-block:: yaml 75 76 # Path: /etc/prometheus/prometheus.yml 77 78 global: 79 scrape_interval: 15s 80 evaluation_interval: 15s 81 82 scrape_configs: 83 - job_name: prometheus 84 static_configs: 85 - targets: ['localhost:9090'] 86 87 Prometheus Systemd service file 88 =============================== 89 90 .. code-block:: systemd 91 92 # Path: /etc/systemd/system/prometheus.service 93 94 [Unit] 95 Description=Prometheus 96 Wants=network-online.target 97 After=network-online.target 98 99 [Service] 100 User=prometheus 101 Group=prometheus 102 Type=simple 103 ExecStart=/usr/local/bin/prometheus \ 104 --config.file /etc/prometheus/prometheus.yml \ 105 --storage.tsdb.path /var/lib/prometheus/ \ 106 --web.console.templates=/etc/prometheus/consoles \ 107 --web.console.libraries=/etc/prometheus/console_libraries 108 109 [Install] 110 WantedBy=multi-user.target 111 112 113 Refresh systemd file and restart Prometheus 114 ------------------------------------------- 115 116 .. code-block:: console 117 118 # systemctl daemon-reload 119 # systemctl start prometheus 120 # systemctl status prometheus 121 # systemctl enable prometheus.service 122 123 124 Check 125 ------ 126 127 The prometheus service should be listening on the 9090 port, check this with your Internet browser, 128 by typing http://ip:9090. 129 130 .. note:: 131 132 If you find any problem to start the prometheus service, use the "journalctl -u prometheus" command 133 to find any errors. Always check twice the prometheus.yml and the prometheus.service files. 134 135 136 Close the 9090 port with Nginx 137 ============================== 138 139 .. note:: 140 141 This is optional, but increases security, by closing your server 9090 listening port. 142 143 In order to reverse proxy the Prometheus default port (9090) to loopback with NGINX, 144 you need to undertake 3 actions: 145 146 - Modify the current systemd service file 147 - Create a new Nginx virtualhost file to loopback port 9090 to prometheus 148 - Restart the Prometheus systemd service file 149 150 151 Modify the Prometheus systemd service file 152 ------------------------------------------ 153 154 .. code-block:: systemd 155 156 ExecStart=/usr/local/bin/prometheus \ 157 --config.file=/etc/prometheus/prometheus.yml \ 158 --storage.tsdb.path=/var/lib/prometheus \ 159 --web.console.templates=/etc/prometheus/consoles \ 160 --web.console.libraries=/etc/prometheus/console_libraries \ 161 --web.listen-address=127.0.0.1:9090 \ # Add this line **** 162 --web.external-url=/prometheus/ # Add this line **** 163 164 165 Nginx configuration 166 ------------------- 167 168 .. code-block:: nginx 169 170 # Path: /etc/nginx/sites-available/prometheus.conf 171 172 server { 173 listen 80; 174 listen [::]:80; 175 server_name name.domain.tld; 176 root /dev/null; 177 178 location /prometheus/ { 179 proxy_pass http://localhost:9090; 180 } 181 } 182 183 .. code-block:: console 184 185 ## Create the Nginx symbolic link to enable the virtualhost file 186 # ln -s /etc/nginx/sites-available/prometheus.conf /etc/nginx/sites-enabled/prometheus 187 # nginx -t 188 # systemctl reload nginx 189 190 191 Restart the Prometheus service 192 ------------------------------ 193 194 .. code-block:: console 195 196 # systemctl daemon-reload 197 # systemctl restart prometheus 198 199 Check 200 ----- 201 202 If you have done all steps explained above you won't be able to reach Prometheus 203 anymore from your web browser (http://ip:9090). 204 To reach the prometheus program from your web browser you will have to access through 205 the subdomain or domain name, that you specified on the nginx virtualhost file. 206 207 208 Grafana control panel (GUI) 209 =========================== 210 211 To add the server prometheus connector or datasource, to the `Taler grafana server <https://grafana.taler.net>`_ 212 go to "Connections->Add new connection" and search for "Prometheus" in the search text field. Once you have found and selected the Prometheus connection type, just press the blue button "Add new data source".The main 2 fields required to specify are the name of the connector, and the URL. Then just press "Save and test", and you are done. 213 214 .. note:: 215 216 Please find the main official documentation in `Prometheus official documentation <https://prometheus.io/>`_ 217 218