Projet

Général

Profil

Prometheus-grafana » Historique » Version 11

pizzacoca, 07/03/2020 07:35

1 1 pizzacoca
# Prometheus-grafana
2
3 3 pizzacoca
> Prometheus est une supervision client / serveur. 
4
> Le serveur est consultable sous localhost:9093
5
> Les clients produisent une page localhost:9100 que le serveur écoute
6 1 pizzacoca
**[Prometheus](https://prometheus.io/)** est sous licence **[Apache 2](https://www.apache.org/licenses/LICENSE-2.0)** . Les sources sont disponibles sous **[github](https://github.com/prometheus)** .
7
8
Prometheus existe aussi sous la forme de paquets pour debian10, ce que nous allons utiliser.
9
10 4 pizzacoca
## Installation de Prometheus
11 1 pizzacoca
12 4 pizzacoca
### Installation coté serveur
13 1 pizzacoca
14
15
16
### Configuration
17
18 4 pizzacoca
> Le travail d'écoute du serveur se découpe en nodes. Plusieurs machines peuvent être dans un node.
19
> Il sera intéressant de regrouper les machines dont nous voulons récupérer les mêmes informations dans un même node.
20
> Les machines tournant sous des OS différents devront probablement être placées sous des nodes différents pour permettre une exploitation avec  Grafana.
21
22 2 pizzacoca
La configuration se fait via un fichier yaml. Ici un exemple.
23 1 pizzacoca
**/etc/prometheus/prometheus.yml**
24 2 pizzacoca
```
25
# Sample config for Prometheus.
26 1 pizzacoca
27 2 pizzacoca
global:
28
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
29
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
30
  # scrape_timeout is set to the global default (10s).
31
32
  # Attach these labels to any time series or alerts when communicating with
33
  # external systems (federation, remote storage, Alertmanager).
34
  external_labels:
35
      monitor: 'example'
36
37
# Alertmanager configuration
38
alerting:
39
  alertmanagers:
40
  - static_configs:
41
    - targets: ['localhost:9093']
42
43
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
44
rule_files:
45
  # - "first_rules.yml"
46
  # - "second_rules.yml"
47
48
# A scrape configuration containing exactly one endpoint to scrape:
49
# Here it's Prometheus itself.
50
scrape_configs:
51
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
52
  - job_name: 'prometheus'
53
54
    # Override the global default and scrape targets from this job every 5 seconds.
55
    scrape_interval: 5s
56
    scrape_timeout: 5s
57
58
    # metrics_path defaults to '/metrics'
59
    # scheme defaults to 'http'.
60
61
    static_configs:
62
      - targets: ['localhost:9090']
63
64
  - job_name: Mes_machines_virtuelles
65
    static_configs:
66
      - targets: 
67
        - 'domaine.associe.ou.adresse.ip:9100'
68
        - 'XXX.XXX.XXX.XXX:9100'
69
70
71
  - job_name: noeud_pour_autres_machines
72
    # If prometheus-node-exporter is installed, grab stats about the local
73
    # machine by default.
74
    static_configs:
75
        # première syntaxe yaml
76
        #- targets: ['localhost:9100']
77
        # deuxième syntaxe yaml
78
      - targets: 
79
        - 'localhost:9100' # la machine qui s'écoute
80
        - 'XXX.XXX.XXX.XXX:9100'
81
        - 'YYY.YYY.YYY.YYY:9100'
82
```
83
84 1 pizzacoca
### Lancement
85
86
```
87
systemctl start grafana-server
88
```
89
Ou pour relancer
90
```
91
systemctl reload prometheus
92
```
93 4 pizzacoca
94 9 pizzacoca
Par défaut le serveur est consultable sous http://localhost:9090
95
96 4 pizzacoca
### Client Prometheus
97 5 pizzacoca
98
Ce client est un serveur qui exporte les métriques sous localhost:9100
99
```
100
apt install prometheus-node-exporter
101
```
102
103
# Grafana
104
105 8 pizzacoca
> Grafana est un outil de rendu graphique des métriques relevées par Prometheus.
106
https://grafana.com/docs/grafana/latest/installation/configuration/
107
108
**[Grafana](https://grafana.com/grafana/)** est sous licence **[Apache 2](https://www.apache.org/licenses/LICENSE-2.0)** (en ce qui concerne les sources) disponibles sur **[github](https://github.com/grafana/grafana)** .
109
110
## Installation
111
112
> Si on ne veut pas partir des sources il est nécessaire d'ajouter les dépots grafana 
113 7 pizzacoca
114
**/etc/apt/sources.list**
115
```
116
deb https://packages.grafana.com/enterprise/deb stable main
117
```
118
119
Il est nécessaire d'ajouter la clef gpg pour ce dépôt.
120
```
121
gpg --receive-key 8C8C34C524098CB6
122
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8C8C34C524098CB6
123
apt update
124 1 pizzacoca
apt install grafana-enterprise
125 7 pizzacoca
```
126 10 pizzacoca
127
### Lancement
128
129
```
130
systemctl start grafana-server
131
```
132
133
Le serveur est consultable sous localhost:3000
134 11 pizzacoca
Clui-ci est paramétré par défault pour aller chercher les métriques sous Prometheus
135
136
### Configuration
137
138
Au travers de l'interface web on peut se construire un tableau de bord ou partir d'un tableau de bord existant : https://grafana.com/grafana/dashboards
139
140
141
![](apercu_grafana.png)