1
1
# Prometheus 安装和配置
2
2
3
+ - 特别说明:一般这类环境要尽可能保证所有服务器时间一致
4
+
3
5
## Prometheus Docker 安装
4
6
5
7
- 官网:< https://prometheus.io/ >
6
8
- 这里以 Spring Boot Metrics 为收集信息
7
- - 创建配置文件:/Users/gitnavi/docker_data/ prometheus/config/prometheus.yml
9
+ - 创建配置文件:` vim /data/docker/ prometheus/config/prometheus.yml`
8
10
- 在 scrape_configs 位置下增加我们自己应用的路径信息
9
11
10
12
```
@@ -39,7 +41,7 @@ scrape_configs:
39
41
40
42
```
41
43
docker run -d --name prometheus -p 9091:9090 \
42
- -v /Users/gitnavi/docker_data /prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml \
44
+ -v /data/docker /prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml \
43
45
prom/prometheus
44
46
```
45
47
@@ -50,18 +52,212 @@ prom/prometheus
50
52
51
53
## 配置
52
54
55
+ - 官网 exporter 列表:< https://prometheus.io/docs/instrumenting/exporters/ >
56
+ - 官网 exporter 暴露的端口列表:< https://github.com/prometheus/prometheus/wiki/Default-port-allocations >
57
+
58
+
59
+ ### CentOS7 服务器
60
+
61
+ - 当前最新版本:node_exporter 0.18.1(201907)
62
+
63
+ ```
64
+ mkdir -p /usr/local/prometheus/node_exporter
65
+
66
+ cd /usr/local/prometheus/node_exporter
67
+
68
+ wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
69
+
70
+ tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz
71
+
72
+ ```
73
+
74
+
75
+ ```
76
+ 创建Systemd服务
77
+ vim /etc/systemd/system/node_exporter.service
78
+
79
+
80
+
81
+ [Unit]
82
+ Description=node_exporter
83
+ After=network.target
84
+
85
+ [Service]
86
+ Type=simple
87
+ User=root
88
+ ExecStart=/usr/local/prometheus/node_exporter/node_exporter-0.18.1.linux-amd64/node_exporter
89
+ Restart=on-failure
90
+
91
+ [Install]
92
+ WantedBy=multi-user.target
93
+ ```
94
+
95
+ - 关于 ExecStart 参数,可以再附带一些启动监控的参数,官网介绍:< https://github.com/prometheus/node_exporter/blob/master/README.md#enabled-by-default >
96
+ - 格式:` ExecStart=/usr/local/prometheus/node_exporter/node_exporter-0.18.1.linux-amd64/node_exporter --collectors.enabled meminfo,hwmon,entropy `
97
+
98
+
99
+ ```
100
+ 启动 Node exporter
101
+ systemctl start node_exporter
102
+
103
+ systemctl daemon-reload
104
+
105
+ systemctl status node_exporter
106
+
107
+ ```
108
+
109
+
110
+ ```
111
+ 修改prometheus.yml,加入下面的监控目标:
112
+
113
+ vim /usr/local/prometheus/prometheus.yml
114
+
115
+ scrape_configs:
116
+ - job_name: 'centos7'
117
+ static_configs:
118
+ - targets: ['127.0.0.1:9100']
119
+ labels:
120
+ instance: centos7_node1
121
+
122
+ ```
123
+
124
+ - 重启 prometheus:` docker restart prometheus `
125
+ - Grafana 有现成的 dashboard:
126
+ - < https://grafana.com/dashboards/405 >
127
+ - < https://grafana.com/dashboards/8919 >
128
+
129
+ ----------------------------------------------------------------------------------------------
130
+
131
+
132
+ ### Nginx 指标
133
+
134
+ - 这里使用 Nginx VTS exporter:< https://github.com/hnlq715/nginx-vts-exporter >
135
+
136
+ - 安装 nginx 模块:
137
+
138
+ ```
139
+ git clone --depth=1 https://github.com/vozlt/nginx-module-vts.git
140
+
141
+
142
+ 编译 nginx 的时候加上:
143
+ ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/opt/nginx-module-vts
144
+
145
+ make(已经安装过了,就不要再 make install)
146
+
147
+ ```
148
+
149
+ ```
150
+ 修改Nginx配置
151
+
152
+
153
+ http {
154
+ vhost_traffic_status_zone;
155
+ vhost_traffic_status_filter_by_host on;
156
+
157
+ ...
158
+
159
+ server {
160
+
161
+ ...
162
+
163
+ location /status {
164
+ vhost_traffic_status_display;
165
+ vhost_traffic_status_display_format html;
166
+ }
167
+ }
168
+ }
169
+
170
+
171
+ 验证nginx-module-vts模块:http://IP/status
172
+
173
+ ```
174
+
175
+ ```
176
+ 如果不想统计流量的server,可以禁用vhost_traffic_status,配置示例:
177
+ server {
178
+ ...
179
+ vhost_traffic_status off;
180
+ ...
181
+ }
182
+ ```
183
+
184
+
185
+ - 安装 nginx-vts-exporter
186
+
187
+ ```
188
+ wget -O nginx-vts-exporter-0.5.zip https://github.com/hnlq715/nginx-vts-exporter/archive/v0.5.zip
189
+ unzip nginx-vts-exporter-0.5.zip
190
+ mv nginx-vts-exporter-0.5 /usr/local/prometheus/nginx-vts-exporter
191
+ chmod +x /usr/local/prometheus/nginx-vts-exporter/bin/nginx-vts-exporter
192
+
193
+ ```
194
+
195
+ ```
196
+ 创建Systemd服务
197
+ vim /etc/systemd/system/nginx_vts_exporter.service
198
+
199
+
200
+ [Unit]
201
+ Description=nginx_exporter
202
+ After=network.target
203
+
204
+ [Service]
205
+ Type=simple
206
+ User=root
207
+ ExecStart=/usr/local/prometheus/nginx-vts-exporter/bin/nginx-vts-exporter -nginx.scrape_uri=http://localhost/status/format/json
208
+ Restart=on-failure
209
+
210
+ [Install]
211
+ WantedBy=multi-user.target
212
+ ```
213
+
214
+
215
+ ```
216
+ 启动nginx-vts-exporter
217
+ systemctl start nginx_vts_exporter.service
218
+ systemctl status nginx_vts_exporter.service
219
+ ```
220
+
221
+
222
+ ```
223
+ 修改prometheus.yml,加入下面的监控目标:
224
+
225
+ - job_name: nginx
226
+ static_configs:
227
+ - targets: ['127.0.0.1:9913']
228
+ labels:
229
+ instance: web1
230
+
231
+ ```
232
+
233
+ - 重启 prometheus:` docker restart prometheus `
234
+ - Grafana 有现成的 dashboard:
235
+ - < https://grafana.com/dashboards/2949 >
236
+ - < https://grafana.com/dashboards/2984 >
237
+
238
+ ----------------------------------------------------------------------------------------------
239
+
240
+
53
241
54
242
### 微服务下的多服务收集
55
243
56
244
- < https://blog.csdn.net/zhuyu19911016520/article/details/88411371 >
57
245
246
+ ----------------------------------------------------------------------------------------------
247
+
58
248
59
249
### 告警
60
250
61
251
- < https://blog.csdn.net/zhuyu19911016520/article/details/88627004 >
62
252
- < https://www.jianshu.com/p/e59cfd15612e >
63
253
64
- ----------------------------------------------------------------------------------------------
254
+ - 告警配置
255
+
256
+ - 告警检测
257
+
258
+ - [ Grafana+Prometheus系统监控之邮件报警功能] ( https://blog.52itstyle.vip/archives/2014/ )
259
+ - [ Grafana+Prometheus系统监控之钉钉报警功能] ( https://blog.52itstyle.vip/archives/2029/ )
260
+ - [ Grafana+Prometheus系统监控之webhook] ( https://blog.52itstyle.vip/archives/2068/ )
65
261
66
262
67
263
@@ -70,8 +266,9 @@ prom/prometheus
70
266
71
267
## 其他资料
72
268
73
- - <>
74
- - <>
269
+ - < https://www.aneasystone.com/archives/2018/11/prometheus-in-action.html >
270
+ - 写得非常非常非常好
271
+ - < https://www.hi-linux.com/posts/27014.html >
75
272
- <>
76
273
- <>
77
274
- <>
0 commit comments