全部博文(150)
分类: 系统运维
2017-04-07 15:16:59
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|awk '{c=$1+c}END{print c}'
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more
从大到小排序
lsof -n |awk '{ command[$1]=$1 ;cnt[$1]=cnt[$1]+1} END{for (i in command) print command[i],cnt[i]}' |sort -k 2 -nr
测试计算总数
[root@b11 ~]# lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|awk '{c=$1+c}END{print c}' 5734
脚本内容
向[作者]致敬
[root@b11 ~]# more /home/zabbix/nginx-connection.sh #!/bin/bash # Script to fetch nginx statuses for tribily monitoring systems # Author: krish@toonheart.com # License: GPLv2 # Set Variables HOST=`ip addr | grep bond0|sed -n '/inet /p'|grep /32 |awk '{print $2}' |awk -F/ '{print $1}'` PORT=80 ip_port=`echo $HOST:$PORT` #netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'$ip_port'")) c=c+1; a=a+1}} END{print a,c,a-c}' # Functions to return nginx stats function all { netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'$ip_port'")) c=c+1; a=a+1}} END{print a}' } function client { netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'$ip_port'")) c=c+1; a=a+1}} END{print c}' } function server { netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'$ip_port'")) c=c+1; a=a+1}} END{print a-c}' } function acs { netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'$ip_port'")) c=c+1; a=a+1}} END{print a,c,a-c}' } # Run the requested function $1
4.1zabbix ui上增加一个模板
模板增加三个项目分别为
nginx.all.connections nginx.client.connections nginx.server.connections
增加一个graph,添加上述三个项目的显示
4.2 为需要的host增加上述模板
4.3 添加一个screen,选择上述增加的graphic 4.4 添加自定义脚本到zabbix_agentd.conf
UserParameter=nginx.all.connections,/home/zabbix/nginx-connection.sh all UserParameter=nginx.client.connections,/home/zabbix/nginx-connection.sh client UserParameter=nginx.server.connections,/home/zabbix/nginx-connection.sh server
4.5 把3的脚本放到/home/zabbix/下面
4.6 重启zabbix_agentd