# 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 {} \;