1
zabbix-agentd.conf最下方添加 UserParameter=<key>,<shell command>

检测nginx进程是否存在

function ping {
/sbin/pidof nginx | wc -l
}

检测nginx性能

vi nginx.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
#!/bin/bash
DAY=`date -d yesterday +%Y%m%d`
IP=$(ip a | grep "10.96.6.*" |awk '{print $2}' | awk -F '/' '{print $1}')
活动连接数

function active {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk '/Active/{print $NF}'
}
读取到客户端的 Header 信息数

function reading {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk '/Reading/{print $2}'
}
返回给客户端 Header 信息数

function writing {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk '/Writing/{print $4}'
}
已经处理完正在等候下一次请求指令的驻留链接等于Active-(Reading+Writing)

function waiting {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk '/Waiting/{print $6}'
}
表示Nginx启动到现在共创建了X个连接

function accepts {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk 'NR==3{print $1}'
}
表示总共处理了X次请求
function handled {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk 'NR==3{print $2}'
}
function requests {
/usr/bin/curl "http://${IP}/nginx_status" 2>/dev/null| awk 'NR==3{print $3}'
}
获取nginx健康检查后端数值

function stat {
/usr/bin/curl "http://${IP}/status" 2>/dev/null| grep "<td>up</td>" |wc -l
}
监控keepalived进程存活

function kp {
ps -fe |grep -w "keepalived" | grep -v "grep"|wc -l
}
监控nginx日志一天的访问量,一个点击算一个pv
function pv {
awk -F '|' '{print $3}' /usr/local/nginx/logs/access_${DAY}.log |wc -l
}
监控nginx日志一天的用户量
function uv {
awk -F '|' '{print $1}' /usr/local/nginx/logs/access_${DAY}.log | sort | uniq -c |wc -l
}

执行function

$1

upload successful

systemctl restart zabbix-agent
在server端进行测试验证

upload successful

添加监控项

创建模板信息,批量介入

upload successful

upload successful

upload successful

upload successful

图形展示

upload successful