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