Bootstrap

zabbix用户参数

目录

Zabbix用户参数-带参数的监控项

Zabbix用户参数-监控php-fpm服务(zabbix-agent)

Zabbix用户参数-基于脚本的php状态监控(zabbix-agent)


Zabbix用户参数-带参数的监控项

1.查看内存信息

cat /proc/meminfo

2.查询指定的内存信息

cat /proc/meminfo | awk '/^DirectMap4k/{print $2}'

awk命令,按行读取文本,将文本按分隔符分割,正则匹配表达式用//包裹,print函数指定要打印的列数

3.在zabbix agent上,添加用户配置监控项

vi /etc/zabbix/zabbix_agent2.d/memory_stats.conf

UserParameter=memory.stats[*],cat /proc/meminfo | awk '/^$1/{print $$2}'

awk中第一个$1表示用户传入的参数,$$2表示awk的参数,并非用户传入的第二个参数

 4.重启agent服务

systemctl restart zabbix-agent2

5.在zabbix server上使用zabbix get命令查看监控项

zabbix_get -s '192.168.60.132' -p 10050 -k 'memory.stats[MemTotal]'

5.配置→模板,创建模板

6.创建监控项

7.自定义监控项倍数

当前监控项显示为Kb,将其转化为Mb,在监控项页面选择进程,添加预定步骤,选择自定义倍数,参数定为0.001

9.将该模板链接到主机上

10.检测→最新数据,查看新添加的监控项的值

11.在配置→total momory模板,点击克隆

12.再克隆一个监控项,点击添加

13.在监测菜单查看主机监控数据和图形

Zabbix用户参数-监控php-fpm服务(zabbix-agent)


1.安装php-fpm

yum -y install php-fpm

2.修改php-fpm配置

vi /etc/php-fpm.d/www.conf

user = nginx        //修改

group = nginx        //修改

listen = 127.0.0.1:9001        //修改

pm.status_path = /status        //去注释

ping.path = /ping        //去注释

ping.response = pong        //去注释

3.添加nginx用户

useradd nginx

4.启动php

setenforce 0

systemctl start php-fpm

5.安装nginx

yum install nginx -y

6.修改nginx配置,设置代理php

vi /etc/nginx/nginx.conf

修改监听端口号为88

    server {

        listen       88;

        listen       [::]:88;

 

增加php配置,与上边server对齐

location ~ \.php$ {        

                fastcgi_pass    127.0.0.1:9001;

                fastcgi_index   index.php;

                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

                include         fastcgi_params;

        }

        location ~* /(status|ping) {

                fastcgi_pass    127.0.0.1:9001;

                fastcgi_index   index.php;

                fastcgi_param   SCRIPT_FILENAME $fastcgi_script_name;

                include         fastcgi_params;

                allow           127.0.0.1;

                deny            all;

                access_log      off;

        }

7.将状态页面拷贝到网站根目录

cp /usr/share/fpm/status.html /usr/share/nginx/html/

8.启动nginx服务

systemctl start nginx

9.查看php状态

curl 127.0.0.1:88/status

10.编辑php自定义配置项,监控项配置命令是:

curl -s 127.0.0.1:88/status | awk '/^$1/{print $$NF}'

Zabbix用户参数-基于脚本的php状态监控(zabbix-agent)


1.在zabbix agent机器上创建脚本目录

mkdir /etc/zabbix/zabbix_agent2.d/script

2.编写php状态监控脚本

vi /etc/zabbix/zabbix_agent2.d/script/php-fpm-status.sh

#!/bin/sh

#php-fpm status

case $1 in

ping)

/sbin/pidof php-fpm | wc -l

;;

start_since)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==4{print $3}'

;;

conn)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==5{print $3}'

;;

listen_queue)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==6{print $3}'

;;

max_listen_queue)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==7{print $4}'

;;

queue_len)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==8{print $4}'

;;

idle_process)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==9{print $3}'

;;

active_process)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==10{print $3}'

;;

total_process)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==11{print $3}'

;;

max_active_process)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==12{print $4}'

;;

max_children_process)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==13{print $4}'

;;

slow_requests)

/usr/bin/curl 127.0.0.1:88/status 2>/dev/null | awk 'NR==10{print $3}'

;;

esac

3.为脚本赋可执行权限

chmod +x /etc/zabbix/zabbix_agent2.d/script/php-fpm-status.sh

4.进入脚本所在目录,测试脚本是否可执行

cd /etc/zabbix/zabbix_agent2.d/script/
./php-fpm-status.sh queue_len

5.编辑php监控项conf文件

vi /etc/zabbix/zabbix_agent2.d/php_status.conf

添加新的监控项

UserParameter=php.status.script[*],/bin/sh /etc/zabbix/zabbix_agent2.d/script/php-fpm-status.sh $1

6.重启zabbix agent

systemctl restart zabbix-agent2

7.在server节点测试查看新的监控项

zabbix_get -s '192.168.10.132' -p 10050 -k 'php.status.script[conn]'
;