ansible部署zabbix监控系统

2019-05-30  本文已影响0人  请叫我飘哥

1、搭建zabbix服务,实现监控linux和windows的内存,cpu,磁盘,网络等基础指标

或者通过服务管理启动:


zabbix agent 启动管理

2、搭建zabbix服务,监控nginx status

location /nginx_status {
        # Turn on nginx stats        
        stub_status on;
        # I do not need logs for stats
        access_log   off;
        # Security: Only allow access from 192.168.1.100 IP #
        allow 127.0.0.1/8;
        deny all;
}
[root@node5 ~]# vim /usr/bin/nginx_status.sh
#!/bin/bash
#
host='127.0.0.1'
port='80'
statusurl='nginx_status'

active(){
        curl -s http://${host}:${port}/${statusurl} |awk '/^Active/{print $3}'
}

accepts(){
        curl -s http://${host}:${port}/${statusurl} |awk 'NR==3{print $1}'
}

handled(){
        curl -s http://${host}:${port}/${statusurl} |awk 'NR==3{print $2}'
}

requests(){
        curl -s http://${host}:${port}/${statusurl} |awk 'NR==3{print $3}'
}

reading(){
        curl -s http://${host}:${port}/${statusurl} |awk 'NR==4{print $2}'
}

writing(){
        curl -s http://${host}:${port}/${statusurl} |awk 'NR==4{print $4}'
}

waiting(){
        curl -s http://${host}:${port}/${statusurl} |awk 'NR==4{print $6}'
}

case "$1" in
active)
        active
;;
accepts)
        accepts
;;
handled)
        handled
;;
requests)
        requests
;;
reading)
        reading
;;
writing)
        writing
;;
waiting)
        waiting
;;
*)
        echo $"Usage: $0 {active|accepts|handled|requests|reading|writing|waiting}"
        exit 1
esac
[root@node5 ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.statu[*],/usr/bin/nginx_status.sh $1
重启zabbix-agent
[root@node5 ~]# systemctl  restart zabbix-agent
安装ab压测工具
[root@node5 ~]# yum -y install httpd-tools 
[root@node5 ~]# ab -n 5000 -c 20 http://127.0.0.1/nginx_status
告警触发
采集Nginx_requests数据
上一篇 下一篇

猜你喜欢

热点阅读