网站并发数,如何用zabbix成立自定义监察和控制项

By admin in 美高梅手机版4858 on 2019年4月17日

1、 nginx编写翻译参数

监察nginx,首要解说监察和控制并发数

--prefix=/usr/local/nginx --with-http_stub_status_module

zabbix编写翻译参数的查看:

/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module

监察nginx,首要教师监察和控制并发数:
一: nginx编写翻译参数:
–prefix=/usr/local/nginx –with-http_stub_status_module

背景:

Zabbix监控Nginx、PHP和Memcached状态

创建zabbix_agentd的子配置文件

在/etc/zabbix/zabbix_agentd.d/中创立关联nginx status和php-fpm
status的子配置文件,创制二个,只怕在已有个别某安插文件中追加也得以,小编那边分别为它们成立布局文件,文件名可自定义,只要确认保障此文件夹全部内容在zabbix_agentd.conf中包含(include)了。

zabbix-agent配置文件的自定义key:

  1. userparameter_nginx.conf
    [[email protected]
    ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
    #/usr/local/zabbix/bin/nginx_status.sh
    #UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx_status.sh
    $1
    #那种写法相比短小,参考zabbix
    三.2.四中自带的的userparameter_examples.conf
    UserParameter=nginx.version,/usr/sbin/nginx -v

#UserParameter=nginx.accepts,/etc/zabbix/scripts/check_nginx_status.sh
accepts
#UserParameter=nginx.handled,/etc/zabbix/scripts/check_nginx_status.sh
handled
#UserParameter=nginx.requests,/etc/zabbix/scripts/check_nginx_status.sh
requests
#UserParameter=nginx.connections.active,/etc/zabbix/scripts/check_nginx_status.sh
active
#UserParameter=nginx.connections.reading,/etc/zabbix/scripts/check_nginx_status.sh
reading
#UserParameter=nginx.connections.writing,/etc/zabbix/scripts/check_nginx_status.sh
writing
#UserParameter=nginx.connections.waiting,/etc/zabbix/scripts/check_nginx_status.sh
waiting

  1. userparameter_php-fpm.conf
    [[email protected]
    ~]# cat
    /etc/zabbix/zabbix_agentd.d/userparameter_php-fpm_status.conf
    #UserParameter=idle.processe,/etc/zabbix/scripts/php-fpm_status.sh
    idle
    #UserParameter=total.processes,/etc/zabbix/scripts/php-fpm_status.sh
    total
    #UserParameter=active.processes,/etc/zabbix/scripts/php-fpm_status.sh
    active
    #UserParameter=max.active.processes,/etc/zabbix/scripts/php-fpm_status.sh
    mactive
    #UserParameter=listen.queue.len,/etc/zabbix/scripts/php-fpm_网站并发数,如何用zabbix成立自定义监察和控制项。status.sh
    listenqueuelen
    #UserParameter=listen.queue,/etc/zabbix/scripts/php-fpm_status.sh
    listenqueue
    #UserParameter=start.since,/etc/zabbix/scripts/php-fpm_status.sh
    since
    #UserParameter=accepted.conn,/etc/zabbix/scripts/php-fpm_status.sh
    conn
    UserParameter=max.children.reached,/etc/zabbix/scripts/php-fpm_status.sh
    reached
    UserParameter=slow.requests[],/etc/zabbix/scripts/php-fpm_status.sh
    requests
    #/usr/local/zabbix/bin/php_fpm_status.sh
    UserParameter=php-fpm.status[
    ],/etc/zabbix/scripts/php-fpm_status.sh
    $1
    UserParameter=php-fpm.version,/usr/local/php56/sbin/php-fpm -v | awk
    ‘NR==1{print $0}’
    #得到php-fpm版本消息

  2. 确认子配置文件被zabbix_agentd配置文件包蕴
    确认在/usr/local/zabbix/etc/zabbix_agentd.conf中包含:Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/且并没有被疏解。

美高梅手机版4858 1
zabbix服务端的get数值
[[email protected]
~]# zabbix_get -s 192.168.198.131 -k ‘nginx.status[ping]’
1
美高梅手机版4858 2

zabbix页面:
nginx:
累加nginx status监察和控制模板
美高梅手机版4858 3
新建nginx status模板
美高梅手机版4858 4
定义nginx status模板
美高梅手机版4858 5
新建nginxApplication
美高梅手机版4858 6
概念nginx status items,那里笔者利用的是毫无作为临控
美高梅手机版4858 7
日增nginx status状态码映射
美高梅手机版4858 8
nginx trigger定义
美高梅手机版4858 9
概念nginx监察和控制视图

增加php-fpm status监控模板
php-fpm status的模板加多步骤和上述措施一样,此处不在赘述。
美高梅手机版4858 10

美高梅手机版4858 11

美高梅手机版4858 12

美高梅手机版4858 13

1、 选择相应的主机或主机组关联上相应的沙盘
美高梅手机版4858 14

  1. 其实监察和控制功效呈现(不知情为何笔者的latest data没多少出来)
    查看监察和控制效用能够透过查看Monitoring—->Latest
    data,过滤出相应的主机及利用名张开查看,最新收罗的各item的监督结果,凡是监察和控制到数量的item会展现数据,出现月光蓝的表示从未监督到多少,供给排查原因。如下所示:

nginx的监察和控制数据

也得以因此定义的Graphs查看监察和控制功用:
nginx status监察和控制视图
美高梅手机版4858 15
nginx request监察和控制视图
美高梅手机版4858 16

php的督察数据
美高梅手机版4858 17

美高梅手机版4858 18

memcached监察和控制数据
美高梅手机版4858 19

zabbix-agent配置增加memcached
在客户端到/usr/local/zabbix/conf/zabbix_agentd.conf里添加:
UserParameter=memcached_stats[*],(echo stats; sleep 1) | telnet
127.0.0.1 $1 2>&1 | awk ‘/STAT $2 / {print $NF}’
封存完成后重启memcached和nginx

memcached监察和控制模板能够到帮客之家能源站下载:

——————————————分割线——————————————

免费下载地址在

用户名与密码都以www.bkjia.com

现实下载目录在 /二零一八年龄资历料/八月/七日/Zabbix监察和控制Nginx、PHP和Memcached状态/

下载格局见

——————————————分割线——————————————

正文永远更新链接地址:

创建zabbix_agentd的子配置文件
在/etc/zabbix/zabbix_agentd.d/中成立关联nginx status和php-fpm
status的子配置文件,创造…

2、nginx配置新添

location /status {
                allow 127.0.0.1;
                deny all;
                stub_status on;
                access_log off;
        }
重启nginx:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

zabbix编写翻译参数的查阅:
/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red
Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: –prefix=/usr/local/nginx –with-http_ssl_module
–with-http_stub_status_module

zabbix本人提供了过多可选的监察项,能够满足绝大多数的监察和控制必要。有时候是因为工作须求,必要自定义监察和控制项。
下边以成立mysql自定义监察和控制项为例,分享怎么样创建zabbix自定义监察和控制项。

三、测试下看看能否获取nginx状态

curl 127.0.0.1/status

2: nginx配置新添

条件认证:

肆、写脚本获取nginx的场所

监控脚本(/usr/local/zabbix/check_nginx.sh):
#!/bin/sh
#nginx status
#Active connections: 1 
#server accepts handled requests

#Reading: 0 Writing: 1 Waiting: 0 
while getopts "o:" opt
do
        case $opt in
                o ) option=$OPTARG;;
                ? )
                echo 'parameter is wrong!'
                exit 1;;
        esac
done
if [ ! "${option}" ];then
        echo "parameter is null"        
        exit 1
fi

if [[ ${option} == "active" ]];then
        curl -s 127.0.0.1/status |grep '^Active connections' |awk '{print $NF}'
elif [[ ${option} == "accepts" ]];then
        curl -s 127.0.0.1/status |awk 'NR==3'|awk '{print $1}'
fi

location /status {
allow 127.0.0.1;
deny all;
stub_status on;
access_log off;
}
重启nginx:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

zabbix版本:三.0.3 操作系统:CentOS 7
mysql版本:5.7.1

五、zabbix配置(/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf)

UserParameter=nginx.status[*],sh /usr/local/zabbix/check_nginx.sh -o $1
重启zabbix agentd(pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd )

3: 测试下看看能或无法获得nginx状态
curl 127.0.0.1/status

得以实现步骤:

陆、zabbix网页配置

nginx.status[accepts] 整形(每秒差值)

监察fpm,主要讲明监察和控制动态并发数

4: 写脚本获取nginx的情景
监察脚本(/usr/local/zabbix/check_nginx.sh):

1、修改 zabbix_agentd.conf,添加zabbix_agent
配置目录,以下是自个儿本机的zabbix的配备: 将以下行的注释去掉

/usr/local/php/etc/php-fpm.conf fpm配置新增添

pm.status_path = /php_fpm_status
fpm需要重启。

#!/bin/sh
#20170603 nginx status
#Active connections: 1
#美高梅手机版4858,server accepts handled requests
#1035268066 1035268066 1035136592
#Reading: 0 Writing: 1 Waiting: 0
while getopts “o:” opt
do
case $opt in
o ) option=$OPTARG;;
? )
echo ‘parameter is wrong!’
exit 1;;
esac
done
if [ ! “${option}” ];then
echo “parameter is null”
exit 1
fi

if [[ ${option} == “active” ]];then
curl -s 127.0.0.1/status |grep ‘^Active connections’ |awk ‘{print
$NF}’
elif [[ ${option} == “accepts” ]];then
curl -s 127.0.0.1/status |awk ‘NR==3’|awk ‘{print $1}’
fi

#Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

nginx配置新增加

location /php_fpm_status
        {
                allow 127.0.0.1;
                deny all;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
nginx需要reload

5:
zabbix配置(/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf):
UserParameter=nginx.status[*],sh /usr/local/zabbix/check_nginx.sh -o
$1
重启zabbix agentd(pkill zabbix_agentd; sleep 3;
/usr/local/zabbix/sbin/zabbix_agentd )

变成:

测试看看能或不能够获得到fpm的事态

curl 127.0.0.1/php_fpm_status
pool:                 www
process manager:      static
start time:           02/Jun/2017:17:45:05 +0800
start since:          58677
accepted conn:        10753843
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       249
active processes:     1
total processes:      250
max active processes: 251
max children reached: 0
slow requests:        426

陆: zabbix网页配置:
nginx.status[accepts] ×××(每秒差值)

Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

写脚本获取fpm的动静

监控脚本(/usr/local/zabbix/check_fpm.sh):
#!/bin/sh
#20170603 fpm status
#curl 127.0.0.1/php_fpm_status
#pool:                 www
#process manager:      static
#start time:           02/Jun/2017:17:45:05 +0800
#start since:          59022
#accepted conn:        10768453
#listen queue:         0
#max listen queue:     0
#listen queue len:     0
#idle processes:       249
#active processes:     1
#total processes:      250
#max active processes: 251
#max children reached: 0
#slow requests:        426
while getopts "o:" opt
do
        case $opt in
                o ) option=$OPTARG;;
                ? )
                echo 'parameter is wrong!'
                exit 1;;
        esac
done
if [ ! "${option}" ];then
        echo "parameter is null"        
        exit 1
fi

if [[ ${option} == "conn" ]];then
curl -s 127.0.0.1/php_fpm_status |grep '^accepted conn'|awk '{print $NF}'
elif [[ ${option} == "idle" ]];then
curl -s 127.0.0.1/php_fpm_status |grep '^idle processes'|awk '{print $NF}'
elif [[ ${option} == "active" ]];then
curl -s 127.0.0.1/php_fpm_status |grep '^active processes'|awk '{print $NF}'
fi

监察和控制fpm,主要解说监察和控制动态并发数:
壹: /usr/local/php/etc/php-fpm.conf fpm配置新扩展:
pm.status_path = /php_fpm_status
fpm必要重启。

将此行注释去掉后,zabbix_agentd运行后会自动扫描/usr/local/etc/zabbix_agentd.conf.d/目录下具备的.conf文件,并加载。

zabbix配置(vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/fpm.conf)

UserParameter=fpm.status[*],sh /usr/local/zabbix/check_fpm.sh  -o $1
重启zabbix agent。pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd 

二: nginx配置新添:

二、编写监察和控制脚本/usr/local/zabbix/zabbix-script/get_mysql_status.sh,脚本如下(脚本存放目录能够自定义):

zabbix网页配置

fpm.status[conn]

 

location /php_fpm_status
{
allow 127.0.0.1;
deny all;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
nginx需要reload

#!/bin/sh

case $3 in
uptime)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $2}'
;;
threads)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $4}'
;;
question)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $6}'
;;
sq)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $9}'
;;
open)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $11}'
;;
ftable)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $14}'
;;
opent)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $17}'
;;
qps)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $22}'
;;
*)

叁: 测试看看能或不能够得到到fpm的场合
curl 127.0.0.1/php_fpm_status
pool: www
process manager: static
start time: 02/Jun/2017:17:45:05 +0800
start since: 58677
accepted conn: 10753843
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 249
active processes: 1
total processes: 250
max active processes: 251
max children reached: 0
slow requests: 426

本子表明,脚本须求输入多个参数分别是:mysql用户、mysql用户密码、mysql状态每一种指标如下:
uptime:运维时间长度单位s、 threads:开启的对话数、
question(questions):服务器运维以来客户的难点(查询)数目 sq(Slow
queries): 慢查询数量 open(opens):服务器已经开垦的数量库表的数量
ftable(Flush tables):服务器已经施行的flush
…、refresh和reload命令的数目 opent(open
tables):通过命令是用的数据库的表的数码,以服务器运维上马 qps(Queries
per second avg):select语句平均查询时间

四: 写脚本获取fpm的景况
监察脚本(/usr/local/zabbix/check_fpm.sh):

3、在/usr/local/etc/zabbix_agentd.conf.d/目录下增多监察和控制项配置文件get_mysql_status.conf,内容如下:

#!/bin/sh
#20170603 fpm status
#curl 127.0.0.1/php_fpm_status
#pool: www
#process manager: static
#start time: 02/Jun/2017:17:45:05 +0800
#start since: 59022
#accepted conn: 10768453
#listen queue: 0
#max listen queue: 0
#listen queue len: 0
#idle processes: 249
#active processes: 1
#total processes: 250
#max active processes: 251
#max children reached: 0
#slow requests: 426
while getopts “o:” opt
do
case $opt in
o ) option=$OPTARG;;
? )
echo ‘parameter is wrong!’
exit 1;;
esac
done
if [ ! “${option}” ];then
echo “parameter is null”
exit 1
fi

if [[ ${option} == “conn” ]];then
curl -s 127.0.0.1/php_fpm_status |grep ‘^accepted conn’|awk ‘{print
$NF}’
elif [[ ${option} == “idle” ]];then
curl -s 127.0.0.1/php_fpm_status |grep ‘^idle processes’|awk ‘{print
$NF}’
elif [[ ${option} == “active” ]];then
curl -s 127.0.0.1/php_fpm_status |grep ‘^active processes’|awk
‘{print $NF}’
fi

UserParameter=get_mysql_status[*],/usr/local/zabbix/zabbix-script/get_mysql_status.sh $1 $2 $3

5: zabbix配置(vim
/usr/local/zabbix/etc/zabbix_agentd.conf.d/fpm.conf):

4、重启zabbix_agent和zabbix_server,使用zabbix_get测试,如下:

UserParameter=fpm.status[*],sh /usr/local/zabbix/check_fpm.sh -o
$1
重启zabbix agent。pkill zabbix_agentd; sleep 3;
/usr/local/zabbix/sbin/zabbix_agentd

#zabbix_get -s 127.0.0.1 -k get_mysql_status[root,weiming,open]
   679

陆: zabbix网页配置:
fpm.status[conn]

伍、web端增多监察和控制项: 在主机上增添监察和控制项:
美高梅手机版4858 20

越多Zabbix相关学科集合: 

累加实现后能够看出新添监控项如下:

在Ubuntu
1陆.0四服务器上安装Zabbix 三.二 

CentOS 7LNMP环境搭建Zabbix3.0 

Ubuntu 1六.0肆装置配备监督种类Zabbix二.四 

Zabbix监控装置配备及警报配置 

Zabbix触发器表达式详解

Ubuntu 1陆.0四下安装配置Zabbix叁.0 

CentOS 7 下 Zabbix 三.0装置详解

Zabbix 3.2.6
通过Orabbix监控Oracle数据库 

Zabbix叁.四增加Web监测作用

Zabbix告警发送邮件时顺便品质图

Zabbix三.0编写翻译进级进度记录

Debian 9.2安装Zabbix 3.4.2

美高梅手机版4858 21

ZABBIX
的详实介绍
:请点那里
ZABBIX
的下载地址
:请点那里

增添图形:

Linux公社的RSS地址:

美高梅手机版4858 22

本文恒久更新链接地址

图片预览:

美高梅手机版4858 23

美高梅手机版4858 24

原著来自:

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有