Article original Publié le : 21 novembre 2022 Mise à jour le : – |
Version de l’OS | Debian 11 |
Version d’InfluxDB | 2.5.0 |
Version de Grafana | 9.2.5 |
Version de Proxmox | 7.2.11 |
Pour ce poc, je spawn une vm sous Debian 11 pour y installer la stack Grafana/Influxdb
Idéalement il aurait fallu un Nginx en amont mais c’était l’occasion de jouer un peu avec les fichiers de conf implicitement
Pré-requis
- I. Préparation de l’environnement système
Influxdb
- II. Installation d’InfluxDB 2
- III. Ajout du certificat pour l’authentification web
- IV. Connexion à l’interface web
- V. La cli
Grafana
- VI. Installation de Grafana
- VII. Connexion à l’interface web
Proxmox
- VIII. Ajout profil Metric Server
- IX. Flux liaison Proxmox vers Influxdb
Conclusion
- X. Dashbord Proxmox sur Grafana
- XI. Query InfluxDB
- XII. Faq
- XIII. Liens
-
I. Préparation de l’environnement système
Mise à jour du système
1 |
$ sudo apt update;sudo apt upgrade |
Installation de paquet utiles ou nécessaires
1 |
$ sudo apt install mlocate gnupg vim software-properties-common netcat apt-transport-https wget lsb-release pwgen |
-
II. Installation d’InfluxDB 2
Installer le repo et lancer l’installation du binaire
1 |
$ wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null |
1 |
$ export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc) |
1 |
$ echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null |
1 |
$ sudo apt-get update;sudo apt-get install influxdb2 |
Démarrer le service, le rendre permanent et vérifier son status
1 |
$ sudo systemctl enable influxdb;sudo systemctl start influxdb;sudo systemctl status influxdb |
Tester la connexion
1 |
$ influx ping |
1 |
OK |
Vérifier la version
1 |
$ influx version |
1 |
Influx CLI 2.5.0 (git: 3285a03) build_date: 2022-11-01T16:32:06Z |
-
III. Ajout du certificat pour l’authentification web
Stopper le service
1 |
$ sudo systemctl stop influxdb |
Déposer le certificat et sa clé dans /etc/ssl puis affiner les droits
1 |
$ sudo chown influxdb:influxdb /etc/ssl/influxdb.crt /etc/ssl/influxdb.key |
1 |
$ sudo chmod 644 /etc/ssl/influxdb.crt;sudo chmod 400 /etc/ssl/influxdb.key |
Implémenter le fichier de configuration
1 |
$ sudo vim /etc/influxdb/config.toml |
1 2 3 |
tls-cert = "/etc/ssl/influxdb.crt" tls-key = "/etc/ssl/influxdb.key" http-bind-address = ":8086" |
Redémarrer le service et vérifier son status
1 |
$ sudo systemctl start influxdb;sudo systemctl status influxdb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
● influxdb.service - InfluxDB is an open-source, distributed, time series database Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2022-11-20 22:55:34 UTC; 33s ago Docs: https://docs.influxdata.com/influxdb/ Process: 11774 ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh (code=exited, status=0/SUCCESS) Main PID: 11775 (influxd) Tasks: 7 (limit: 1131) Memory: 48.7M CPU: 273ms CGroup: /system.slice/influxdb.service └─11775 /usr/bin/influxd Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11775]: ts=2022-11-20T22:55:34.260986Z lvl=info msg="Starting retention policy enforcement service" log_id=0eHouoPl000 service=retention check_interval=30m Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11775]: ts=2022-11-20T22:55:34.260994Z lvl=info msg="Starting precreation service" log_id=0eHouoPl000 service=shard-precreation check_interval=10m advance_period=30m Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11775]: ts=2022-11-20T22:55:34.261584Z lvl=info msg="Starting query controller" log_id=0eHouoPl000 service=storage-reads concurrency_quota=1024 initial_memory_bytes_quota_> Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11775]: ts=2022-11-20T22:55:34.264019Z lvl=info msg="Configuring InfluxQL statement executor (zeros indicate unlimited)." log_id=0eHouoPl000 max_select_point=0 max_select_> Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11775]: ts=2022-11-20T22:55:34.284401Z lvl=info msg=Listening log_id=0eHouoPl000 service=tcp-listener transport=https addr=:8086 port=8086 Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11775]: ts=2022-11-20T22:55:34.284791Z lvl=info msg=Starting log_id=0eHouoPl000 service=telemetry interval=8h Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11791]: Command "print-config" is deprecated, use the influx-cli command server-config to display the configuration values from the running server Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11774]: TLS cert and key found -- using https Nov 20 22:55:34 vm06-deb11 influxd-systemd-start.sh[11774]: InfluxDB started Nov 20 22:55:34 vm06-deb11 systemd[1]: Started InfluxDB is an open-source, distributed, time series database. . |
-
IV. Connexion à l’interface web
Il faut avoir défini une entrée DNS ou dans le hosts
Dans mon cas https://influxdb.izero.fr:8086/
Pour la première connexion créer un user et son mot de passe, ainsi que l’organisation et le bucket, attention sensible a la case
-
V. La cli
/!\ Pour éviter de s’authentifier à chaque commande, ajouter les identifiants requis pour la cli
https://docs.influxdata.com/influxdb/v2.1/reference/cli/influx/#provide-required-authentication-credentials
1 2 3 4 5 |
influx config create --config-name <config-name> \ --host-url http://localhost:8086 \ --org <your-org> \ --token <your-auth-token> \ --active |
ce qui renverra en exemple
1 2 |
Active Name URL Org * proxmox-cfg https://influxdb.izero.fr:8086 izero |
Quelques exemples de commandes
Lister les utilisateurs
1 |
$ influx user list |
1 2 |
ID Name 0a51d17cdc5fb000 bef |
Lister les membres d’une organisation
1 |
$ influx org members list |
1 2 |
ID Name User Type Status 0a51d17cdc5fb000 bef owner active |
Lister les buckets
1 |
$ influx bucket list |
1 2 3 4 |
ID Name Retention Shard group duration Organization ID Schema Type 24ff89127f5213df _monitoring 168h0m0s 24h0m0s 9be6b4bfa1fccf26 implicit 05b0b7a08a369567 _tasks 72h0m0s 24h0m0s 9be6b4bfa1fccf26 implicit f68da9229d13c515 proxmox infinite 168h0m0s 9be6b4bfa1fccf26 implicit |
Modification de la rétention de la bucket Proxmox
1 |
$ influx bucket update -i f68da9229d13c515 -r 168h0m0s |
1 2 |
ID Name Retention Shard group duration Organization ID Schema Type f68da9229d13c515 proxmox 168h0m0s 168h0m0s 9be6b4bfa1fccf26 implicit |
Changer le mot de passe d’un utilisateur
1 |
$ influx user password -n bef |
1 2 |
? Please type new password for "bef" ************** ? Please type new password for "bef" again ************** |
1 |
Successfully updated password for user "bef" |
-
VI. Installation de Grafana
Installer le repo et lancer l’installation du binaire
1 |
$ wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - |
1 |
$ echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list |
1 |
$ sudo apt-get update |
1 |
$ sudo apt-get install grafana |
Générer un mot de passe aléatoire avec pwgen
1 |
$ pwgen -N 1 -s 14 |
1 |
ZOM04KzwM85Kdb |
Créer le répertoire ssl et déposer le certificat et sa clé dans /etc/grafana/ssl puis affiner les droits
1 |
$ sudo mkdir /etc/grafana/ssl |
1 |
$ sudo chown grafana:grafana /etc/grafana/ssl/grafana.crt /etc/grafana/ssl/grafana.key |
1 |
$ sudo chmod 644 /etc/grafana/ssl/grafana.crt;sudo chmod 400 /etc/grafana/ssl/grafana.key |
Customiser le grafana.ini
1 |
$ sudo vim /etc/grafana/grafana.ini |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[paths] logs = /var/log/grafana plugins = /var/lib/grafana/plugins [server] protocol = https http_addr = grafana.izero.fr http_port = 3000 domain = izero.fr root_url = %(protocol)s://%(http_addr)s:%(http_port)s/ enable_gzip = true cert_file = /etc/grafana/ssl/grafana.crt cert_key = /etc/grafana/ssl/grafana.key router_logging = true [security] admin_user = admin admin_password = ZOM04KzwM85Kdb |
Démarrer le service, le rendre permanent et vérifier son status
1 |
$ sudo systemctl daemon-reload; sudo systemctl enable grafana-server; sudo systemctl start grafana-server; sudo systemctl status grafana-server |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
● grafana-server.service - Grafana instance Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2022-11-21 11:53:15 UTC; 4s ago Docs: http://docs.grafana.org Main PID: 14941 (grafana-server) Tasks: 7 (limit: 1131) Memory: 39.2M CPU: 320ms CGroup: /system.slice/grafana-server.service └─14941 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:d> Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=live.push_http t=2022-11-21T11:53:15.460980082Z level=info msg="Live Push Gateway initialization" Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=infra.usagestats.collector t=2022-11-21T11:53:15.568814278Z level=info msg="registering usage stat providers" usageStatsProvidersLen=2 Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=server t=2022-11-21T11:53:15.569155959Z level=info msg="Writing PID file" path=/run/grafana/grafana-server.pid pid=14941 Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=provisioning.alerting t=2022-11-21T11:53:15.56970415Z level=info msg="starting to provision alerting" Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=provisioning.alerting t=2022-11-21T11:53:15.569816198Z level=info msg="finished to provision alerting" Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=http.server t=2022-11-21T11:53:15.584537016Z level=info msg="HTTP Server Listen" address=192.168.50.136:3000 protocol=https subUrl= socket= Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=ngalert t=2022-11-21T11:53:15.585017879Z level=info msg="warming cache for startup" Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=ticker t=2022-11-21T11:53:15.585272446Z level=info msg=starting first_tick=2022-11-21T11:53:20Z Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=grafanaStorageLogger t=2022-11-21T11:53:15.58731066Z level=info msg="storage starting" Nov 21 11:53:15 vm06-deb11 grafana-server[14941]: logger=ngalert.multiorg.alertmanager t=2022-11-21T11:53:15.587880247Z level=info msg="starting MultiOrg Alertmanager" |
-
VII. Connexion à l’interface web
Il faut avoir défini une entrée DNS ou dans le hosts
Dans mon cas https://grafana.izero.fr:3000/
-
VIII Ajout profil Metric Server
Sur Proxmox, aller dans Datacenter > Metric Server et ajouter un profil pour relier a influxdb
On retrouve ces informations dans un fichier qui sera créer sous /etc/pve/status.cfg
-
IX. Flux liaison Proxmox vers Influxdb
Si le création du profil échoue, il y a des flux a vérifier (iptables/pfsense dans mon cas)
Il m’a fallu créer une NAT sur pFsense pour la machine qui héberge influxdb
Et ajouter une règle en OUTPUT sur l’iptables du serveur Proxmox (DROP par défaut)
1 |
$ sudo iptables -A OUTPUT -p tcp -m tcp --dport 8086 -j ACCEPT |
Relancer netcat et valider le profil
-
X. Dashbord Proxmox sur Grafana
Il existe de nombreux dashboards, le 15356 offre une bonne compatibilité
Sous Grafana, commencer par ajouter une une data source InfluxDB
Query Language: flux
URL: https://influxdb.izero.fr:8086
Auth : rien
Custom HTTP Headers: rien
InfluxDB Details : Organization – izero / Token – mon_token / Default Bucket – proxmox
Ajouter le dashboard Proxmox
Aller dashboards / import et ajouter l’id 15356
Laisser tourner quelques minutes pour avoir les premiers graphs
-
XI. Query InfluxDB
Plus habitué à InfluxDB 1.8, la version 2.x est assez différente à l’utilisation ..
En screenshots, une simple query pour remonter la mémoire total, libre et utilisé pendant 1h (assez linéaire pour le coup !)
-
XII. Faq
1 |
$ influx user list |
1 |
Error: failed to list users: Get "https://influxdb.izero.fr:8086/api/v2/users": x509: certificate signed by unknown authority |
Attention à bien avoir la chaine complète (ca, certificat, intermédiaire)
-
XIII. Liens
https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/
https://pve.proxmox.com/wiki/External_Metric_Server
https://grafana.com/grafana/dashboards/15356-proxmox-flux/