Skip to content

Commit b5c52a9

Browse files
committed
2019-07-06
1 parent a1dac80 commit b5c52a9

File tree

3 files changed

+215
-16
lines changed

3 files changed

+215
-16
lines changed

markdown-file/Grafana-Install-And-Settings.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
- 官网:<https://hub.docker.com/r/grafana/grafana/>
1212

1313
```
14-
docker run -d --name grafana -p 3000:3000 -v /Users/gitnavi/docker_data/grafana/data grafana/grafana
14+
mkdir -p /data/docker/grafana/data
15+
chmod 777 -R /data/docker/grafana/data
16+
17+
docker run -d --name grafana -p 3000:3000 -v /data/docker/grafana/data:/var/lib/grafana grafana/grafana
1518
1619
docker exec -it grafana /bin/bash
1720
1821
容器中默认的配置文件位置:/etc/grafana/grafana.ini
19-
2022
复制出配置文件到宿主机:docker cp grafana:/etc/grafana/grafana.ini /Users/gitnavi/
2123
```
2224

markdown-file/Prometheus-Install-And-Settings.md

Lines changed: 202 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Prometheus 安装和配置
22

3+
- 特别说明:一般这类环境要尽可能保证所有服务器时间一致
4+
35
## Prometheus Docker 安装
46

57
- 官网:<https://prometheus.io/>
68
- 这里以 Spring Boot Metrics 为收集信息
7-
- 创建配置文件:/Users/gitnavi/docker_data/prometheus/config/prometheus.yml
9+
- 创建配置文件:`vim /data/docker/prometheus/config/prometheus.yml`
810
- 在 scrape_configs 位置下增加我们自己应用的路径信息
911

1012
```
@@ -39,7 +41,7 @@ scrape_configs:
3941

4042
```
4143
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 \
4345
prom/prometheus
4446
```
4547

@@ -50,18 +52,212 @@ prom/prometheus
5052

5153
## 配置
5254

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+
53241

54242
### 微服务下的多服务收集
55243

56244
- <https://blog.csdn.net/zhuyu19911016520/article/details/88411371>
57245

246+
----------------------------------------------------------------------------------------------
247+
58248

59249
### 告警
60250

61251
- <https://blog.csdn.net/zhuyu19911016520/article/details/88627004>
62252
- <https://www.jianshu.com/p/e59cfd15612e>
63253

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/)
65261

66262

67263

@@ -70,8 +266,9 @@ prom/prometheus
70266

71267
## 其他资料
72268

73-
- <>
74-
- <>
269+
- <https://www.aneasystone.com/archives/2018/11/prometheus-in-action.html>
270+
- 写得非常非常非常好
271+
- <https://www.hi-linux.com/posts/27014.html>
75272
- <>
76273
- <>
77274
- <>

markdown-file/wrk-Install-And-Settings.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ sudo cp wrk /usr/local/bin
2626

2727
## 使用
2828

29-
- 启用 10 个线程,每个线程发起 100 个连接,持续 15 秒:`wrk -t10 -c100 -d15s http://www.baidu.com`
29+
- 启用 10 个线程,每个线程发起 100 个连接,持续 15 秒:`wrk -t5 -c5 -d30s http://www.baidu.com`
3030
- 最终报告:
3131

3232
```
33-
Running 15s test @ http://www.baidu.com
34-
10 threads and 100 connections
33+
Running 30s test @ http://www.baidu.com
34+
5 threads and 5 connections
3535
Thread Stats Avg Stdev Max +/- Stdev
36-
Latency 208.39ms 324.00ms 1.91s 87.70%
37-
Req/Sec 82.68 64.81 414.00 70.60%
38-
11345 requests in 15.02s, 166.51MB read
39-
Socket errors: connect 0, read 20, write 0, timeout 59
40-
Requests/sec: 755.26
41-
Transfer/sec: 11.08MB
36+
Latency 44.59ms 17.41ms 331.91ms 95.66%
37+
Req/Sec 23.11 5.77 30.00 57.04%
38+
3439 requests in 30.03s, 50.47MB read
39+
Socket errors: connect 0, read 10, write 0, timeout 0
40+
Requests/sec: 114.52
41+
Transfer/sec: 1.68MB
4242
```
4343

4444
#### 使用 lua 脚本(发送一个 post 请求)

0 commit comments

Comments
 (0)