« Prometheus » : différence entre les versions

De Le Wiki de Lug
Aller à la navigation Aller à la recherche
Ligne 131 : Ligne 131 :
== AlerManager ==
== AlerManager ==
[https://prometheus.io/docs/alerting/latest/configuration/ Source] [https://medium.com/devops-dudes/prometheus-alerting-with-alertmanager-e1bbba8e6a8e Autre Source] [https://itnext.io/prometheus-alertmanager-web-ui-alerts-silence-2d34fbf2d252 Autre Source] [https://devconnected.com/alertmanager-and-prometheus-complete-setup-on-linux/ Encore une]
[https://prometheus.io/docs/alerting/latest/configuration/ Source] [https://medium.com/devops-dudes/prometheus-alerting-with-alertmanager-e1bbba8e6a8e Autre Source] [https://itnext.io/prometheus-alertmanager-web-ui-alerts-silence-2d34fbf2d252 Autre Source] [https://devconnected.com/alertmanager-and-prometheus-complete-setup-on-linux/ Encore une]
=== Installation ===
# apk add alertmanager


==Grafana ==
==Grafana ==

Version du 25 avril 2021 à 15:13

Serveur

36 % partie serveur Prometheus terminé

   

LXC Alpine Prometheus

Installation serveur de base

# apk update && apk upgrade
# apk add prometheus
# rc-update add prometheus default
# service prometheus start

On test en se rendant sur l'adresse http://IP_PROMETHEUS:9090 :

Le serveur fonctionne!

Facile!

(Optionnel) Securisation serveur

source autre source

On installe un proxy local pour sécuriser le flux :

# apk add nginx
# rc-update add nginx default
# service nginx start

On crée un .htpasswd pour l'utilsateur "admin" et son mot de passe :

# apk add apache2-utils
# htpasswd -c /etc/nginx/.htpasswd admin
New password:

On prépare le cryptage (self signed) :

# apk add openssl
# mkdir -p /root/certs/prometheus/ && cd /root/certs/prometheus
# openssl req \
    -x509 \
    -newkey rsa:4096 \
    -nodes \
    -keyout prometheus.key \
    -out prometheus.crt

On configure le vhost :

# vi /etc/nginx/conf.d/prometheus.conf
server {
        listen              9191 ssl;
        ssl_certificate     /root/certs/prometheus/prometheus.crt;
        ssl_certificate_key /root/certs/prometheus/prometheus.key;

        location / {
        auth_basic           "Prometheus";
        auth_basic_user_file /etc/nginx/.htpasswd;

        proxy_pass http://localhost:9090/;

       }
   }
# service nginx restart

On configure prometheus en rajoutant ces trois lignes :

# vi /etc/init.d/prometheus
...
command_args="--config.file=$prometheus_config_file \
       --web.listen-address="127.0.0.1:9090" \
       --web.external-url=https://127.0.0.1:9191 \
       --web.route-prefix="/" \
       --storage.tsdb.path=$prometheus_storage_path \
...
# service prometheus restart
* Caching service dependencies ... [ ok ]
* Starting prometheus ... [ ok ]

(Optionnel) Rétention de données

Source

Par défaut Prometheus conserve les données 15 jours, il est possible de modifier cela de plusieurs façons :

  • --storage.tsdb.retention.size [EXPERIMENTAL] : Limiter la taille maximal conservée (B, KB, MB, GB, TB, PB, EB).
  • --storage.tsdb.retention.time : Limiter le temps de rétention maximal.

Si vous indiquez plusieurs valeurs la première limitation atteinte fera autorité.

Dans cette exemple nous allons modifier la rétention pour stocker jusqu'a 5Gb de données :

# vi /etc/init.d/prometheus

On remplace la ligne --storage.tsdb.retention.time=$prometheus_retention_time"

...
        --storage.tsdb.path=$prometheus_storage_path \                                                                                                                                                                                                                                                                                              
        --storage.tsdb.retention.size="5GB""                                                                                                                                                                                                                                                                                                          
command_user="prometheus:prometheus"
...

AlerManager

Source Autre Source Autre Source Encore une

Installation

# apk add alertmanager

Grafana

Importation Serveur Prometheus Distant (self signed)

Pag d'importation

Export

ProxMox

Prometheus Node Exporter

ProxMox

ProxMox:~# apt install prometheus-node-exporter

On crée un fichier de configuration avec l'adresse et port d'écoute :

ProxMox:~# echo 'ARGS=--web.listen-address=12.34.56.789:9100' > /etc/prometheus.conf

On active le fichier de configuration en modifiant le script :

ProxMox:~# vi /lib/systemd/system/prometheus-node-exporter.service
EnvironmentFile=/etc/prometheus.conf
ProxMox:~# systemctl daemon-reload
ProxMox:~# service prometheus-node-exporter restart

Import Serveur Prometheus

Prometheus:~# vi /etc/prometheus/prometheus.yml
...
  - job_name: node
    static_configs:
    - targets: [12.34.56.789:9100]
Prometheus:~# service prometheus restart

On vérifie que l'exporter est "up" en se rendant sur son serveur Prometheus dans "Status" -> "Targets"

Menu "targets"

Prometheus PVE Exporter

source en français de qualitay

ProxMox

On crée un groupe et un utilisateur avec les droits d'accès au monitoring :

ProxMox:~# pveum groupadd monitoring -comment 'Monitoring group'
ProxMox:~# pveum aclmod / -group monitoring -role PVEAuditor
ProxMox:~# pveum useradd pve_exporter@pve
ProxMox:~# pveum usermod pve_exporter@pve -group monitoring
ProxMox:~# pveum passwd pve_exporter@pve

On installe l'exporter :

ProxMox:~# apt-get install python3-pip
ProxMox:~# pip3 install prometheus-pve-exporter

On va ensuite créer un fichier de configuration :

ProxMox:~# mkdir -p /usr/share/pve_exporter/
ProxMox:~# vi /usr/share/pve_exporter/pve_exporter.yml
default:
    user: pve_exporter@pve
    password: MOTDEPASSE
    verify_ssl: false

On créé le fichier pour systemd :

ProxMox:~# vi /etc/systemd/system/pve_exporter.service
[Unit]
Description=Proxmox VE Prometheus Exporter
After=network.target
Wants=network.target

[Service]
Restart=on-failure
WorkingDirectory=/usr/share/pve_exporter
ExecStart=/usr/local/bin/pve_exporter /usr/share/pve_exporter/pve_exporter.yml 9221 12.34.56.789

[Install]
WantedBy=multi-user.target
ProxMox:~# systemctl daemon-reload
ProxMox:~# systemctl enable pve_exporter
ProxMox:~# systemctl start pve_exporter

Prometheus

Prometheus:~# vi /etc/prometheus/prometheus.yml
  - job_name: 'pve'
    static_configs:
      - targets:
        - 12.34.56.789:9221  # Proxmox VE node with PVE exporter.
        - 12.34.45.790:9221  # Proxmox VE node with PVE exporter.
    metrics_path: /pve
    params:
      module: [default]
Prometheus:~# service prometheus restart

On vérifie que l'exporter est "up" en se rendant sur son serveur Prometheus dans "Status" -> "Targets"

Menu "targets"

Export Nvidia

docker run --name NVexport -p IP_EXPOSE:9445:9445 -d --restart=always -e LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 --volume /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1:/usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 --privileged mindprince/nvidia_gpu_prometheus_exporter:0.1