监控tcp连接数
1.安装agent
2.编写tcp连接数的脚本
root@zhaohuakang:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/tcp_status.sh
!/bin/bash
Author:Zhang ShiJie
tcp_conn_status(){
TCP_STAT=1]} END {for(k in s) print k,s[k]}' > /tmp/tcp_conn.txt
TCP_NUM=TCP_STAT" /tmp/tcp_conn.txt | cut -d ' ' -f2)
if [ -z TCP_NUM
}
main(){
case 2;
;;
esac
}
main 2
chmod a+x /etc/zabbix/zabbix_agent2.d/tcp_status.sh
3.添加监控数据
root@zhaohuakang:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/tcp.conf
UserParameter=linux_status[*],/etc/zabbix/zabbix_agent2.d/tcp_status.sh "2"
root@zhaohuakang:zabbix_agent2.d# systemctl restart zabbix-agent2.service
4.zabbix server测试数据是否可行
zabbix_get -s 172.31.7.106 -p 10050 -k "linux_status["tcp_status","TIME-WAIT"]"
root@zhaohuakang:~# zabbix_get -s 172.31.7.106 -p 10050 -k "linux_status["tcp_status","TIME-WAIT"]"
39
5.导入模板
添加模板
因为这个模板是主动式模板,更改agent[root@zhao ~]# vim /etc/zabbix/zabbix_agent2.conf
ServerActive=10.0.0.100 #zabbix服务端地址
[root@zhao ~]#systemctl restart zabbix-agent2.service
6.查看监控数据
数据监控项怎么写的
监控memcache
apt-get install memcached nmap
apt install ncat -y
vim /etc/memcached.conf
-l 0.0.0.0
1.安装agent
2.编写脚本
查看memched的各种数据
root@zhaohuakang:~# telnet 172.31.7.106 11211
Trying 172.31.7.106...
Connected to 172.31.7.106.
Escape character is '^]'.
stats
root@zhaohuakang:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/memcache_monitor.sh
!/bin/bash
Author:Zhang ShiJie
memcached_status(){
M_PORT=2
echo -e "stats\nquit" | ncat 127.0.0.1 "M_COMMAND" | awk '{print 1 in
memcached_status)
memcached_status 3
;;
esac
}
main 2 $3
root@zhaohuakang:zabbix_agent2.d# chmod a+x /etc/zabbix/zabbix_agent2.d/memcache_monitor.sh
3.编写监控项
root@zhaohuakang:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/memcache.conf
UserParameter=memcache_status[*],/etc/zabbix/zabbix_agent2.d/memcache_monitor.sh "2" "$3"
root@zhaohuakang:zabbix_agent2.d# systemctl restart zabbix-agent2.service
3.zabbix server测试
root@zhaohuakang:~# zabbix_get -s 172.31.7.106 -p 10050 -k "memcache_status["memcached_status","11211","curr_connections"]"
1
4.添加模板
自己做监控项
最大连接数
请求工作线程的总数量
监控redis
apt install redis -y
vim /etc/redis/redis.conf
bind 0.0.0.0
bind 0.0.0.0
root@web1:zabbix_agent2.d# systemctl restart redis.service
1.安装agent
2.监控脚本
root@web1:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/redis_monitor.sh
!/bin/bash
Author:Zhang ShiJie
redis_status(){
R_PORT=2
(echo -en "INFO \r\n";) | ncat 127.0.0.1 "R_PORT".tmp
REDIS_STAT_VALUE=R_COMMAND":" /tmp/redis_"REDIS_STAT_VALUE
}
help(){
echo "${0} + redis_status + PORT + COMMAND"
}
main(){
case 2 1 3
root@web1:zabbix_agent2.d# chmod a+x /etc/zabbix/zabbix_agent2.d/redis_monitor.sh
root@web1:zabbix_agent2.d# bash redis_monitor.sh redis_status 6379 used_memory
859160
chown zabbix.zabbix /tmp/redis_6379.tmp
查看数据
root@web1:zabbix_agent2.d# redis-cli
127.0.0.1:6379> info
3.添加自定义监控项
root@web1:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/redis.conf
UserParameter=redis_status[*],/etc/zabbix/zabbix_agent2.d/redis_monitor.sh "2" "$3"
root@zhaohuakang:zabbix_agent2.d# systemctl restart zabbix-agent2.service
4.zabbix server测试
root@zhaohuakang:~# zabbix_get -s 172.31.7.106 -p 10050 -k "redis_status["redis_status","6379","used_memory"]"
参考https://blog.51cto.com/shone/5321694
redis的当前连接数
键值
redis_status["redis_status","6379","connected_clients"]
Redis 分配器分配的内存总量
键值
redis_status["redis_status","6379","used_memory"]
监控nginx
安装nginx
root@web1:zabbix_agent2.d# bash install_nginx.sh
root@web1:zabbix_agent2.d# vim /apps/nginx/conf/nginx.conf
location /nginx_status {
stub_status;
allow 172.31.0.0/16;
allow 127.0.0.1;
deny all;
}
root@web1:zabbix_agent2.d# systemctl restart nginx
访问测试
http://172.31.7.106/nginx_status
1.安装agent
2.监控脚本
root@web1:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/nginx_monitor.sh
!/bin/bash
Date:2016/11/11
Author: Zhangshijie
nginx_status_fun(){ #函数内容
NGINX_PORT=2 #命令,函数的第二个参数是脚本的第三个参数,即脚本的第三个参数是命令
nginx_active(){ #获取nginx_active数量,以下相同,这是开启了nginx状态但是只能从本机看到
/usr/bin/curl "http://127.0.0.1:"NF}'
}
nginx_reading(){ #获取nginx_reading状态的数量
/usr/bin/curl "http://127.0.0.1:"2}'
}
nginx_writing(){
/usr/bin/curl "http://127.0.0.1:"4}'
}
nginx_waiting(){
/usr/bin/curl "http://127.0.0.1:"6}'
}
nginx_accepts(){
/usr/bin/curl "http://127.0.0.1:"1}'
}
nginx_handled(){
/usr/bin/curl "http://127.0.0.1:"2}'
}
nginx_requests(){
/usr/bin/curl "http://127.0.0.1:"3}'
}
case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
esac
}
main(){ #主函数内容
case 2 "Usage: $0 {nginx_status key}"
esac #分支结束符
}
main 2 $3
root@web1:zabbix_agent2.d# chmod a+x /etc/zabbix/zabbix_agent2.d/nginx_monitor.sh
root@web1:zabbix_agent2.d# bash nginx_monitor.sh nginx_status 80 active
1
3.自定义监控项
root@web1:zabbix_agent2.d# cat /etc/zabbix/zabbix_agent2.d/nginx.conf
UserParameter=nginx.status[*],/etc/zabbix/zabbix_agent2.d/nginx_monitor.sh "2" "$3"
root@web1:zabbix_agent2.d# systemctl restart zabbix-agent2.service
4.zabbix测试
root@zabbix-server:~# zabbix_get -s 172.31.7.106 -p 10050 -k "nginx.status["nginx_status",80,"active"]"
1
.5导入模板
6.主机添加模板