Tuto : Installation de Prometheus / Grafana
Installation de Grafana
wget -q -O - https://packages.grafana.com/gpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
sudo systemctl status grafana-server
Liens
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-grafana-on-ubuntu-22-04
https://antoinelounis.com/informatique/supervision/installation-grafana-influxdb-telegraf-debian/
Installation de Prometheus
Création du compte de service
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Installation des sources
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest|grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
sudo mkdir /var/lib/prometheus
tar xvf prometheus*.tar.gz
cd prometheus*/
sudo mv prometheus promtool /usr/local/bin/
sudo mv consoles console_libraries prometheus.yml /etc/prometheus/
sudo chown -R prometheus:prometheus /var/lib/prometheus/
Création du service prometheus.service
sudo tee /etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.enable-lifecycle \
--web.enable-admin-api \
--log.level=info
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus
Liens
https://www.howtoforge.com/tutorial/monitor-ubuntu-server-with-prometheus/
https://www.fosstechnix.com/install-prometheus-and-grafana-on-ubuntu-22-04/
https://www.cherryservers.com/blog/install-prometheus-ubuntu
https://prometheus.io/docs/prometheus/latest/getting_started/
Installation de Influxdb
sudo tee /etc/apt/sources.list.d/influxdb.list<<EOF
deb [signed-by=/usr/share/keyrings/influxdb-keyring.gpg] https://repos.influxdata.com/ubuntu jammy stable
EOF
curl -fsSL https://repos.influxdata.com/influxdata-archive_compat.key|sudo gpg --dearmor -o /usr/share/keyrings/influxdb-keyring.gpg
sudo apt-get update && sudo apt-get install influxdb2
sudo systemctl start influxdb && sudo systemctl enable influxdb
influx config create --config-name influx01 \
--host-url http://localhost:8086 \
--org $ORG \
--token $API_TOKEN \
--active
Liens
https://docs.influxdata.com/influxdb/v2/install/?t=Linux
https://antoinelounis.com/informatique/supervision/installation-grafana-influxdb-telegraf-debian/
Installation de node_exporter
Création du compte de service
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Installation des sources
curl -s https://api.github.com/repos/prometheus/node_exporter/releases/latest| grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
tar -xvf node_exporter*.tar.gz
cd node_exporter*/
sudo cp node_exporter /usr/local/bin
Création du service node_exporter.service
sudo tee /etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=default.target
EOF
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
sudo systemctl status node_exporter
Ajout du monitoring dans Prometheus
sudo nano /etc/prometheus/prometheus.yml
scrape_configs:
....
....
- job_name: "node_exporter"
static_configs:
- targets: ["192.168.5.100:9100"]
sudo systemctl restart prometheus
sudo systemctl status prometheus
Installation de mysql_exporter
Création du compte de service
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Installation des sources
curl -s https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest| grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
tar xvfz mysqld_exporter-*.*-amd64.tar.gz
cd mysqld_exporter-*.*-amd64
sudo cp mysqld_exporter /usr/local/bin
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'enter_password_here' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
export DATA_SOURCE_NAME='exporter:enter_password_here@(mysql_hostname:3306)/'
Création du service mysqld_exporter.service
sudo tee /etc/systemd/system/mysqld_exporter.service<<EOF
[Unit]
Description=Mysqld Exporter
Wants=network-online.target
After=network-online.target
User=prometheus
Group=prometheus
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl start mysqld_exporter
sudo systemctl enable mysqld_exporter
sudo systemctl status mysqld_exporter
Ajout du monitoring dans Prometheus
sudo nano /etc/prometheus/prometheus.yml
- job_name: "Mysqld"
static_configs:
- targets: ["10.0.0.1:9104"]
sudo systemctl restart prometheus
sudo systemctl status prometheus
Liens
https://grafana.com/oss/prometheus/exporters/mysql-exporter/?tab=installation
https://prometheus.io/download/
Configuration du monitoring Haproxy
Création du compte de service
sudo groupadd prometheus
sudo useradd --system -s /sbin/nologin -g prometheus prometheus
Configuration de Haproxy
Les dernières versions Haproxy intègrent nativement un exporter vers Prometheus.
Il suffit donc de créer un frontend dans haproxy.cfg
sudo nano /etc/haproxy/haproxy.cfg
frontend prometheus
bind :8405
mode http
http-request use-service prometheus-exporter
no log
haproxy -f /etc/haproxy/haproxy.cfg -c
sudo systemctl restart haproxy
hatop -s /var/run/haproxy/admin.sock
Ajout du monitoring dans Prometheus
sudo nano /etc/prometheus/prometheus.yml
- job_name: "Haproxy Reverse"
static_configs:
- targets: ["10.0.0.1:8405"]
sudo systemctl restart prometheus
sudo systemctl status prometheus
Liens
Installation de apache_exporter
Création du compte de service
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Installation des sources
curl -s https://api.github.com/repos/Lusitaniae/apache_exporter/releases/latest|grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
tar xvf apache_exporter-*.linux-amd64.tar.gz
sudo cp apache_exporter-*.linux-amd64/apache_exporter /usr/local/bin
sudo chmod +x /usr/local/bin/apache_exporter
Création du service apache_exporter.service
sudo tee /etc/systemd/system/apache_exporter.service<<EOF
[Unit]
Description=Prometheus
Documentation=https://github.com/Lusitaniae/apache_exporter
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/apache_exporter \
--insecure \
--scrape_uri=http://localhost/server-status/?auto \
--telemetry.endpoint=/metrics
SyslogIdentifier=apache_exporter
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl start apache_exporter
sudo systemctl enable apache_exporter
sudo systemctl status apache_exporter
Ajout du monitoring dans Prometheus
sudo nano /etc/prometheus/prometheus.yml
- job_name: "Apache"
static_configs:
- targets: ["10.0.0.1:9117"]
sudo systemctl restart prometheus
sudo systemctl status prometheus
Liens
https://computingforgeeks.com/monitor-apache-web-server-prometheus-grafana/
https://grafana.com/docs/agent/latest/flow/reference/components/prometheus.exporter.apache/
https://github.com/Lusitaniae/apache_exporter/releases
https://techexpert.tips/prometheus/prometheus-monitoring-apache-ubuntu-linux/
Installation de blackbox_exporter
Création du compte de service
sudo useradd -rs /bin/false blackbox
Installation des sources
curl -s https://api.github.com/repos/prometheus/blackbox_exporter/releases/latest| grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
tar -xvf blackbox_exporter*.tar.gz
cd blackbox_exporter*/
sudo cp blackbox_exporter /usr/local/bin
sudo mkdir -p /etc/blackbox
sudo mv blackbox.yml /etc/blackbox
sudo chown blackbox:blackbox /usr/local/bin/blackbox_exporter
sudo chown -R blackbox:blackbox /etc/blackbox/*
Création du service blackbox_exporter.service
sudo tee /etc/systemd/system/blackbox_exporter.service <<EOF
[Unit]
Description=Blackbox Exporter Service
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=blackbox
Group=blackbox
ExecStart=/usr/local/bin/blackbox_exporter \
--config.file=/etc/blackbox/blackbox.yml \
--web.listen-address=":9115"
Restart=always
[Install]
WantedBy=default.target
EOF
sudo systemctl enable blackbox_exporter
sudo systemctl start blackbox_exporter
sudo systemctl status blackbox_exporter
Ajout du monitoring dans Prometheus
sudo nano /etc/prometheus/prometheus.yml
- job_name: "blackbox"
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://www.yakakliker.org # Target to probe with https.
- https://openproject.yakakliker.org
- https://passbolt.yakakliker.org
- https://zerotier.yakakliker.org
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9115 # The blackbox exporter's real hostname:port
sudo systemctl restart prometheus
sudo systemctl status prometheus
Liens
https://devconnected.com/how-to-install-and-configure-blackbox-exporter-for-prometheus/
https://github.com/prometheus/blackbox_exporter
Installation de loki & promtail
Création des comptes de service
useradd -s /bin/bash -d /opt/loki/ loki
useradd -s /bin/bash -d /opt/promtail/ promtail
usermod -a -G adm promtail
Installation des sources loki
mkdir /opt/loki && cd /opt/loki
curl -s https://api.github.com/repos/grafana/loki/releases/latest|grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
unzip loki-linux-amd64.zip
wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
chown -R loki: /opt/loki/
Création du service loki.service
sudo tee /etc/systemd/system/loki.service<<EOF
[Unit]
Description=Loki Grafana
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=loki
Group=loki
ExecStart=/opt/loki/loki-linux-amd64 -config.file=/opt/loki/loki-local-config.yaml
SyslogIdentifier=loki
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl enable loki.service
systemctl start loki.service
systemctl status loki.service
journalctl -f -u loki.service
Installation des sources promtail
mkdir /opt/promtail
cp promtail-linux-amd64.zip /opt/promtail
cd /opt/promtail
unzip promtail-linux-amd64.zip
wget https://raw.githubusercontent.com/grafana/loki/main/clients/cmd/promtail/promtail-local-config.yaml
chown -R promtail: /opt/promtail/
Création du service promtail.service
sudo tee /etc/systemd/system/promtail.service<<EOF
[Unit]
Description=Promtail Loki
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=promtail
Group=promtail
ExecStart=/opt/promtail/promtail-linux-amd64 -config.file /opt/promtail/promtail-local-config.yaml
SyslogIdentifier=promtail
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl enable promtail.service
systemctl start promtail.service
systemctl status promtail.service
journalctl -f -u promtail.service
Ajout du monitoring dans Prometheus
sudo nano /etc/prometheus/prometheus.yml
# Scrape Loki metrics
- job_name: "loki"
metrics_path: "/metrics" # Loki's metrics endpoint
static_configs:
- targets: ["localhost:3100"] # Replace with your Loki's address and port
# Scrape Promtail metrics
- job_name: "promtail"
metrics_path: "/metrics" # Promtail's metrics endpoint
static_configs:
- targets: ["localhost:9080"] # Replace with your Promtail's address and port
sudo systemctl restart prometheus
sudo systemctl status prometheus
Liens
https://www.aukfood.fr/collecter-et-afficher-les-logs-avec-grafana-loki/