自定义图像

grafana 安装grafana 安装zabbix插件,启动插件 数据源–zabbix数据源 导入模板

划分应用集

查看负载图

自带的饼图乱码,并且很丑

乱码原因:/usr/share/zabbix/assets/fonts/graphfont.ttf 文件默认不支持中文

解决方法:

1.从C:\Windows\Fonts 中复制喜欢的字体到桌面,然后丢到上面目录

2.改名 #mv STKAITI.TTF graphfont.ttf

效果:

自定义图

正常(线图)、层积(柱状图)、pie(饼图)、爆发

grafana自定义图形

安装

到清华源中下载

wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-6.7.3-1.x86_64.rpm

rpm -ivh grafana-6.7.3-1.x86_64.rpm

启动

systemctl start grafana-server.service

systemctl enable grafana-server.service

查看、访问端口(3000)

netstat -lntup

官方地址:https://grafana.com/

默认账号密码都是:admin

安装zabbix插件

查找zabbix插件

grafana-cli plugins list-remote | grep zabbix

安装插件

grafana-cli plugins install alexanderzobnin-zabbix-app(也可以下zip丢进去解压)

重启grafana-server

systemctl restart grafana-server.service

在web上看到

启用

添加数据源

URL可以搜索本地接口找出

账号Admin

密码zabbix

导入数据

下载饼图

查询饼图

grafana-cli plugins list-remote |grep -i pie

下载饼图

grafana-cli plugins install grafana-piechart-panel

压力测试

ab -n 次数 -c 并发 http://192.168.1.10/zabbix/index.php

添加数据源

密码:可以查看 /etc/zabbix/web/zabbix.conf.php 配置文件

自定义模板

利用模板可以快速添加监控项: 模板可以分享

Zabbix中,模板就是主机

创建模板

7层架构

pass

自定义模板

更新应用集

添加触发器

添加图形

模板的导出/导入以及共享入口

导出

导入

共享模板入口

主机链接模板

复制命令

scp -rp tcp.conf

[root@192.168.1.91:pwd

重启agnet并刷新页面

设置恢复时间

重启server端服务

监控 nginx 模板

开启监控页面

在nginx在添加

1
2
3
location /nginx-status {
stub_status ;
}

重启nginx并访问http://ip/nginx-status/

编写状态脚本

1
2
mkdir /etc/zabbix/scripts
vim /etc/zabbix/scripts/nginx_status.sh

内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
BKUP_DATE=`/bin/date +%Y%m%d`
#LOG="/data/log/zabbix/webstatus.log"
HOST=127.0.0.1
PORT=80

ARGS=1
if [ $# -ne "$ARGS" ];then
echo "Please input one arguement:"
fi

case $1 in
exist)
result=`/sbin/pidof nginx | wc -l`
echo $result
;;
active)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Active' | awk '{print $NF}'`
echo $result
;;
reading)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Reading' | awk '{print $2}'`
echo $result
;;
writing)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Writing' | awk '{print $4}'`
echo $result
;;
waiting)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'`
echo $result
;;
accepts)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $1}'`
echo $result
;;
handled)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $2}'`
echo $result
;;
requests)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $3}' `
echo $result
;;
*)
echo "Usage:$0(active|reading|writing|waiting|accepts|handled|requests)"
;;
esac

测试脚本

/etc/zabbix/scripts/nginx_status.sh

添加键值

UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx_status.sh \$1

重启zabbix—agent

手动取值测试

zabbix_get -s 172.16.180.11 -k nginx.status[active]

创建模板

触发器值填写exist

链接模板

监控 php-fpm 模板

开启监控页面

编写php-fpm配置文件

1
2
vim /etc/php-fpm.d/www.conf
pm.status_path = /php_status

编写nginx配置文件(通过nginx访问)

vim nginx.conf

1
2
3
4
5
6
7
location \~ /php_status {
root /usr/local/nginx/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html\$fastcgi_script_name;
include fastcgi_params;
}

导入配置文件

1
2
fpm.conf
UserParameter=php-fpm[*], /bin/bash /etc/zabbix/scripts/php-fpm.sh $1

Php-fpm.Sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
pool(){
curl -s http://127.0.0.1:8080/php_status|awk '/pool/ {print $NF}'
}
process_manager() {
curl -s http://127.0.0.1:8080/php_status|awk '/process manager/ {print $NF}'
}

start_since(){
curl -s http://127.0.0.1:8080/php_status|awk '/^start since:/ {print $NF}'
}
accepted_conn(){
curl -s http://127.0.0.1:8080/php_status|awk '/^accepted conn:/ {print $NF}'
}
listen_queue(){
curl -s http://127.0.0.1:8080/php_status|awk '/^listen queue:/ {print $NF}'
}
max_listen_queue(){
curl -s http://127.0.0.1:8080/php_status|awk '/^max listen queue:/ {print $NF}'
}
listen_queue_len(){
curl -s http://127.0.0.1:8080/php_status|awk '/^listen queue len:/ {print $NF}'
}
idle_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^idle processes:/ {print $NF}'
}
active_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^active processes:/ {print $NF}'
}
total_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^total processes:/ {print $NF}'
}
max_active_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^max active processes:/ {print $NF}'
}
max_children_reached(){
curl -s http://127.0.0.1:8080/php_status|awk '/^max children reached:/ {print $NF}'
}
case "$1" in
pool)
pool
;;
process_manager)
process_manager
;;
start_since)
start_since
;;
accepted_conn)
accepted_conn
;;
listen_queue)
listen_queue
;;
max_listen_queue)
max_listen_queue
;;
listen_queue_len)
listen_queue_len
;;
idle_processes)
idle_processes
;;
active_processes)
active_processes
;;
total_processes)
total_processes
;;
max_active_processes)
max_active_processes
;;
max_children_reached)
max_children_reached
;;
*)
echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}"
esac

测试取值

zabbix_get -s 127.0.0.1 -k php-fpm[total_processes]

导入模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.0</version>
<date>2017-10-02T12:57:53Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template App For XSJ Web Php-fpm</template>
<name>Template App For XSJ Web Php-fpm</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<items>
<item>
<name>php-fpm.$1(qps)</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[accepted_conn]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[active_processes]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[idle_processes]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[listen_queue]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[listen_queue_len]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[max_active_processes]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[max_children_reached]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[max_listen_queue]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[pool]</key>
<delay>120</delay>
<history>7</history>
<trends>0</trends>
<status>0</status>
<value_type>4</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[process_manager]</key>
<delay>120</delay>
<history>7</history>
<trends>0</trends>
<status>0</status>
<value_type>4</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[start_since]</key>
<delay>120</delay>
<history>7</history>
<trends>0</trends>
<status>0</status>
<value_type>4</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>php-fpm[total_processes]</key>
<delay>120</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
</items>
<discovery_rules/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{Template App For XSJ Web Php-fpm:php-fpm[total_processes].last(0)}&lt;1</expression>
<name>{HOST.NAME}的Php-fpm进程已宕掉,请检查!</name>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
</triggers>
<graphs>
<graph>
<name>Web Php-fpm status</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>5</drawtype>
<color>00C800</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[active_processes]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>5</drawtype>
<color>0000C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[idle_processes]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>5</drawtype>
<color>C8C800</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[max_active_processes]</key>
</item>
</graph_item>
<graph_item>
<sortorder>3</sortorder>
<drawtype>5</drawtype>
<color>009600</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[total_processes]</key>
</item>
</graph_item>
<graph_item>
<sortorder>4</sortorder>
<drawtype>5</drawtype>
<color>C800C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[listen_queue]</key>
</item>
</graph_item>
<graph_item>
<sortorder>5</sortorder>
<drawtype>5</drawtype>
<color>960000</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[max_listen_queue]</key>
</item>
</graph_item>
<graph_item>
<sortorder>6</sortorder>
<drawtype>5</drawtype>
<color>00C8C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[listen_queue_len]</key>
</item>
</graph_item>
<graph_item>
<sortorder>7</sortorder>
<drawtype>5</drawtype>
<color>C8C8C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[max_children_reached]</key>
</item>
</graph_item>
<graph_item>
<sortorder>8</sortorder>
<drawtype>5</drawtype>
<color>C80000</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App For XSJ Web Php-fpm</host>
<key>php-fpm[accepted_conn]</key>
</item>
</graph_item>
</graph_items>
</graph>
</graphs>
</zabbix_export>

模板变量

用宏传入

更新间隔

更新间隔不能太快,容易造成高负载

监控 redis 模板

配置文件和脚本

配置文件

1
2
3
4
监控redis状态,我们可以根据这个参数对应的监控项创建redis状态触发器。
redis monitor
userParameter=redis.status,/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 -a aosatech ping |grep -c PONG
userParameter=redis_info[*],/etc/zabbix/scripts/redis_zbx.sh $1 $2

注意:REDISPATH=”/usr/bin/redis-cli”根据redis-cli命令的位置进行调整!

which redis-cli

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
REDISPATH="/usr/local/bin/redis-cli"
HOST="127.0.0.1"
PORT="6379"
PASSWORD="aosatech"
REDIS_INFO="$REDISPATH -h $HOST -p $PORT -a $PASSWORD info"
if [[ $# == 1 ]];then
case $1 in
cluster)
result=$($REDIS_INFO|/bin/grep cluster|awk -F":" '{print $NF}')
echo "$result"
;;
uptime_in_seconds)
result=$($REDIS_INFO|/bin/grep uptime_in_seconds|awk -F":" '{print $NF}')
echo "$result"
;;
connected_clients)
result=$($REDIS_INFO|/bin/grep connected_clients|awk -F":" '{print $NF}')
echo "$result"
;;
client_longest_output_list)
result=$($REDIS_INFO|/bin/grep client_longest_output_list|awk -F":" '{print $NF}')
echo "$result"
;;
client_biggest_input_buf)
result=$($REDIS_INFO|/bin/grep client_biggest_input_buf|awk -F":" '{print $NF}')
echo "$result"
;;
blocked_clients)
result=$($REDIS_INFO|/bin/grep blocked_clients|awk -F":" '{print $NF}')
echo "$result"
;;

#内存
used_memory)
result=$($REDIS_INFO|/bin/grep used_memory|awk -F":" '{print $NF}'|awk 'NR==1')
echo "$result"
;;
used_memory_human)
result=$($REDIS_INFO|/bin/grep used_memory_human|awk -F":" '{print $NF}')
echo "$result"
;;
used_memory_rss)
result=$($REDIS_INFO|/bin/grep used_memory_rss|awk -F":" '{print $NF}' | awk 'NR==1')
echo "$result"
;;
used_memory_rss_human)
result=$($REDIS_INFO|/bin/grep used_memory_rss_human |awk -F":" '{print $NF}')
echo "$result"
;;

used_memory_peak)
result=$($REDIS_INFO|/bin/grep used_memory_peak|awk -F":" '{print $NF}'|awk 'NR==1')
echo "$result"
;;
used_memory_peak_human)
result=$($REDIS_INFO|/bin/grep used_memory_peak_human|awk -F":" '{print $NF}')
echo "$result"
;;
used_memory_lua)
result=$($REDIS_INFO|/bin/grep used_memory_lua|awk -F":" '{print $NF}'|awk 'NR==1')
echo "$result"
;;
used_memory_lua_human)
result=$($REDIS_INFO|/bin/grep used_memory_luai_human|awk -F":" '{print $NF}')
echo "$result"
;;

mem_fragmentation_ratio)
result=$($REDIS_INFO|/bin/grep mem_fragmentation_ratio|awk -F":" '{print $NF}')
echo "$result"
;;
#rdb
rdb_changes_since_last_save)
result=$($REDIS_INFO|/bin/grep rdb_changes_since_last_save|awk -F":" '{print $NF}')
echo "$result"
;;
rdb_bgsave_in_progress)
result=$($REDIS_INFO|/bin/grep rdb_bgsave_in_progress|awk -F":" '{print $NF}')
echo "$result"
;;
rdb_last_save_time)
result=$($REDIS_INFO|/bin/grep rdb_last_save_time|awk -F":" '{print $NF}')
echo "$result"
;;
rdb_last_bgsave_status)
result=$($REDIS_INFO|/bin/grep -w "rdb_last_bgsave_status" | awk -F':' '{print $2}' | /bin/grep -c ok)
echo "$result"
;;
rdb_current_bgsave_time_sec)
result=$($REDIS_INFO|/bin/grep -w "rdb_current_bgsave_time_sec" | awk -F':' '{print $2}')
echo "$result"
;;
#rdbinfo
aof_enabled)
result=$($REDIS_INFO|/bin/grep -w "aof_enabled" | awk -F':' '{print $2}')
echo "$result"
;;
aof_rewrite_scheduled)
result=$($REDIS_INFO|/bin/grep -w "aof_rewrite_scheduled" | awk -F':' '{print $2}')
echo "$result"
;;
aof_last_rewrite_time_sec)
result=$($REDIS_INFO|/bin/grep -w "aof_last_rewrite_time_sec" | awk -F':' '{print $2}')
echo "$result"
;;
aof_current_rewrite_time_sec)
result=$($REDIS_INFO|/bin/grep -w "aof_current_rewrite_time_sec" | awk -F':' '{print $2}')
echo "$result"
;;
aof_last_bgrewrite_status)
result=$($REDIS_INFO|/bin/grep -w "aof_last_bgrewrite_status" | awk -F':' '{print $2}' | /bin/grep -c ok)
echo "$result"
;;
#aofinfo
aof_current_size)
result=$($REDIS_INFO|/bin/grep -w "aof_current_size" | awk -F':' '{print $2}')
echo "$result"
;;
aof_base_size)
result=$($REDIS_INFO|/bin/grep -w "aof_base_size" | awk -F':' '{print $2}')
echo "$result"
;;
aof_pending_rewrite)
result=$($REDIS_INFO|/bin/grep -w "aof_pending_rewrite" | awk -F':' '{print $2}')
echo "$result"
;;
aof_buffer_length)
result=$($REDIS_INFO|/bin/grep -w "aof_buffer_length" | awk -F':' '{print $2}')
echo "$result"
;;
aof_rewrite_buffer_length)
result=$($REDIS_INFO|/bin/grep -w "aof_rewrite_buffer_length" | awk -F':' '{print $2}')
echo "$result"
;;
aof_pending_bio_fsync)
result=$($REDIS_INFO|/bin/grep -w "aof_pending_bio_fsync" | awk -F':' '{print $2}')
echo "$result"
;;
aof_delayed_fsync)
result=$($REDIS_INFO|/bin/grep -w "aof_delayed_fsync" | awk -F':' '{print $2}')
echo "$result"
;;
#stats
total_connections_received)
result=$($REDIS_INFO|/bin/grep -w "total_connections_received" | awk -F':' '{print $2}')
echo "$result"
;;
total_commands_processed)
result=$($REDIS_INFO|/bin/grep -w "total_commands_processed" | awk -F':' '{print $2}')
echo "$result"
;;
instantaneous_ops_per_sec)
result=$($REDIS_INFO|/bin/grep -w "instantaneous_ops_per_sec" | awk -F':' '{print $2}')
echo "$result"
;;
rejected_connections)
result=$($REDIS_INFO|/bin/grep -w "rejected_connections" | awk -F':' '{print $2}')
echo "$result"
;;
expired_keys)
result=$($REDIS_INFO|/bin/grep -w "expired_keys" | awk -F':' '{print $2}')
echo "$result"
;;
evicted_keys)
result=$($REDIS_INFO|/bin/grep -w "evicted_keys" | awk -F':' '{print $2}')
echo "$result"
;;
keyspace_hits)
result=$($REDIS_INFO|/bin/grep -w "keyspace_hits" | awk -F':' '{print $2}')
echo "$result"
;;
keyspace_misses)
result=$($REDIS_INFO|/bin/grep -w "keyspace_misses" | awk -F':' '{print $2}')
echo "$result"
;;
pubsub_channels)
result=$($REDIS_INFO|/bin/grep -w "pubsub_channels" | awk -F':' '{print $2}')
echo "$result"
;;
pubsub_channels)
result=$($REDIS_INFO|/bin/grep -w "pubsub_channels" | awk -F':' '{print $2}')
echo "$result"
;;
pubsub_patterns)
result=$($REDIS_INFO|/bin/grep -w "pubsub_patterns" | awk -F':' '{print $2}')
echo "$result"
;;
latest_fork_usec)
result=$($REDIS_INFO|/bin/grep -w "latest_fork_usec" | awk -F':' '{print $2}')
echo "$result"
;;
connected_slaves)
result=$($REDIS_INFO|/bin/grep -w "connected_slaves" | awk -F':' '{print $2}')
echo "$result"
;;
master_link_status)
result=$($REDIS_INFO|/bin/grep -w "master_link_status"|awk -F':' '{print $2}'|/bin/grep -c up)
echo "$result"
;;
master_last_io_seconds_ago)
result=$($REDIS_INFO|/bin/grep -w "master_last_io_seconds_ago"|awk -F':' '{print $2}')
echo "$result"
;;
master_sync_in_progress)
result=$($REDIS_INFO|/bin/grep -w "master_sync_in_progress"|awk -F':' '{print $2}')
echo "$result"
;;
slave_priority)
result=$($REDIS_INFO|/bin/grep -w "slave_priority"|awk -F':' '{print $2}')
echo "$result"
;;
#cpu
used_cpu_sys)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_sys"|awk -F':' '{print $2}')
echo "$result"
;;
used_cpu_user)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_user"|awk -F':' '{print $2}')
echo "$result"
;;
used_cpu_sys_children)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_sys_children"|awk -F':' '{print $2}')
echo "$result"
;;
used_cpu_user_children)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_user_children"|awk -F':' '{print $2}')
echo "$result"
;;
*)
echo "argu error"
;;
esac
#db0:key
elif [[ $# == 2 ]];then
case $2 in
keys)
result=$($REDIS_INFO| /bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "keys" | awk -F'=|,' '{print $2}')
echo "$result"
;;
expires)
result=$($REDIS_INFO| /bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "expires" | awk -F'=|,' '{print $4}')
echo "$result"
;;
avg_ttl)
result=$($REDIS_INFO|/bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "avg_ttl" | awk -F'=|,' '{print $6}')
echo "$result"
;;
*)
echo "argu error" ;;
esac
fi

手动取值

zabbix_get -s 192.168.1.91 -k redis_info[blocked_clients]

建立/导入模板

Pass

加速

Redis可以用来加速网页访问,但是需要下在php-redis进行连接配置