Projet

Général

Profil

Prometheus-grafana » Historique » Version 17

pizzacoca, 18/04/2020 02:52

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