本届主要介绍添加监控项和修改中文乱码,监控mysql,nginx服务
在配置文件中添加:
UserParameter=lsq_userd,free -m | grep Mem | awk '{ print $3 }'
服务器内存使用量
UserParameter=du,df -Th | awk '/\/$/{print $6}' | awk -F% '{print $1}'
磁盘使用量

重启agent服务

zabbix_get -s 192.168.2.4 -p 10050 -k lsq_userd
zabbix_get -s 192.168.2.4 -p 10050 -k du
UserParameter=memory userd,free -m lgrep Mem |awk '[print $3)
语法: UserParameter=key,shell command
监控key 值: memory_userd,key 值可以随意编写,但是一会需要在 web 页面创建监控项时指定 key 值;
Shell 命令或脚本: free -mlgrep Memlawk print $3y
注:在 zabbix server 端可以使用 zabbix get -s agent 端 ip 地址 -p 10050 -k key 名通过此命令可以查看 agent 端 key 的监控值;


















以上可看到图形中的中文有问题。

在该路径下/usr/share/fonts/dejavu:找到该文件





cp /usr/share/doc/zabbix-agent-5.0.37/userparameter_mysql.conf .



1.添加对应模板到群组中

2.更改宏为agent地址





nginx -V

在nginx配置文件中service字段中输入:
- location /status { #定义运行状态页面名称,页面为status
- stub_status on; #开启模块
- access_log off; #不开启访问日志记录
- allow 127.0.0.1; #运行127.0.0.1地址访问此网页
- allow 192.168.2.0/24; #只运行192.168.2.0网段的主机访问此网页
- deny all; #其余网段主机不允许访问
- }


在/zabbix目录下编写
- #!/bin/bash
- #定义Nginx status页面
- ngx_status="http://127.0.0.1/status"
- #判断status页面是否存活
- ngx_status_code() {
- http_code=`curl -o /dev/null -s -w %{http_code} ${ngx_status}`
- if [ ${http_code} == "200" ];then
- return 1
- else
- echo "Nginx status is not running."
- fi
- }
-
- #获取当前活动的客户端连接数
- active() {
- ngx_status_code || curl -s ${ngx_status} | grep "Active" | awk '{print $NF}'
- }
-
- #获取接收客户端连接的总数量
- accepts() {
- ngx_status_code || curl -s ${ngx_status} | awk NR==3 | awk '{print $1}'
- }
-
- #获取已处理的连接总数量
- handled() {
- ngx_status_code || curl -s ${ngx_status} | awk NR==3 | awk '{print $2}'
- }
-
- #获取客户端请求总数量
- requests() {
- ngx_status_code || curl -s ${ngx_status} | awk NR==3 | awk '{print $3}'
- }
-
- #获取正在读取请求标头的当前连接数量
- reading() {
- ngx_status_code || curl -s ${ngx_status} | grep "Reading" | awk '{print $2}'
- }
-
- #获取正在将响应写回到客户端的当前连接数量
- writing() {
- ngx_status_code || curl -s ${ngx_status} | grep "Writing" | awk '{print $2}'
- }
-
- #获取当前正在等待响应的客户端连接数量
- waiting() {
- ngx_status_code || curl -s ${ngx_status} | grep "Waiting" | awk '{print $2}'
- }
-
- #使用位置变量控制脚本输出
- case $1 in
- active)
- active;;
- accepts)
- accepts;;
- handled)
- handled;;
- requests)
- requests;;
- reading)
- reading;;
- writing)
- writing;;
- waiting)
- waiting;;
- *)
- echo "Unknown options"
- esac

| 参考以下内容进行修改: |
[root@nginx ~]# grep -v "^#" /etc/zabbix/zabbix_agentd.conf | grep -v "^$"(查看到如下状态则修改完成)

vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
添加以下内容
UserParameter=nginx.active,bash /etc/zabbix/ngx_status.sh active
UserParameter=nginx.accepts,bash /etc/zabbix/ngx_status.sh accepts
UserParameter=nginx.handled,bash /etc/zabbix/ngx_status.sh handled
UserParameter=nginx.requests,bash /etc/zabbix/ngx_status.sh requests
UserParameter=nginx.reading,bash /etc/zabbix/ngx_status.sh reading
UserParameter=nginx.writing,bash /etc/zabbix/ngx_status.sh writing
UserParameter=nginx.waiting,bash /etc/zabbix/ngx_status.sh waiting

重启服务。






