首页 > 系统服务 > 详细

服务器nginx 用shell 统计并发

时间:2016-05-21 00:06:34      阅读:267      评论:0      收藏:0      [点我收藏+]

# netstat -an| grep ‘:80‘ | awk ‘/tcp/{a[$NF]++}END{for (i in a) print i,a[i]}‘


# echo "当前并发数:`netstat -ant | grep :80 | awk ‘{print $5}‘ | awk -F":" ‘{print $1}‘| sort | uniq -c | sort -r -n | awk ‘BEGIN{total=0}{total+=$1}END{print total}‘`";

当前并发数:8


贴一下统计服务器并发数统计脚本,根据网上的信息加上自己的需求整理的,把IP换为自己的IP地址即可,统计的是80端口的访问并发适用于Linux平台。 去掉最后的awk段就可以统计当前每个IP的访问数


# echo "当前并发数:`netstat -nt | grep IP:80 | awk ‘{print $5}‘ | awk -F":" ‘{print $1}‘| sort | uniq -c | sort -r -n | awk ‘BEGIN{total=0}{total+=$1}END{print total}‘`";


#统计并发

# echo "当前并发数:`netstat -nt | grep :80  | awk ‘{print $5}‘ | awk -F":" ‘{print $1}‘| sort | uniq -c | sort -r -n | awk ‘BEGIN{total=0}{total+=$1}END{print total}‘`";



统计并发脚本:

# cat Concurrent.sh

#!/bin/bash

while :

do


echo "当前并发数:`netstat -nt | grep :80  | awk ‘{print $5}‘ | awk -F":" ‘{print $1}‘| sort | uniq -c | sort -r -n | awk ‘BEGIN{total=0}{total+=$1}END{print total}‘`" >> /opt/logs/Concurrent/logs/Concurrent.txt


sleep 1

done 

[root@~]# cat Concurrent_date.sh

#!/bin/bash

Date=`date +%F`

kill -9 ` ps -ef | grep Concurrent.sh  | grep -v grep | awk ‘{print $2}‘`

sleep 5


echo "==============$Date==============" >> /opt/logs/BF_SUM.txt


sort -r /opt/logs/Concurrent/logs/Concurrent.txt |head >> /opt/logs/BF_SUM.txt


echo "==============END==============" >> /opt/logs/BF_SUM.txt


mv /opt/logs/Concurrent/logs/Concurrent.txt /opt/logs/Concurrent/logs/Concurrent.${Date}.txt


nohup /opt/logs/Concurrent/Concurrent.sh & 


find /opt/logs/Concurrent/logs/ -type f -name "*.txt" -mtime +7 -exec rm -r {} \;





服务器nginx 用shell 统计并发

原文:http://wangqh.blog.51cto.com/5367393/1775510

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!