相关统计AWK收藏

当前访问ip数量:

ss -an | awk '{split($NF,A,":");a[A[1]]++}END{for (i in a)print i,a[i]}'|grep '^[0-9]'|sort -nr -k2,2

连接状态检查:

ss -ant|awk '{name[$1]++}END{for (n in name)print n,name[n]}'

综合性能分析命令:

yum install dstat -y

dstat -cydrmlns --fs --tcp -f
dstat -tlvsn --top -io-adv
dstat -tlvsn --tcp --top-io-adv
dstat --top-bio --top-cpu --top-cputime --top-io --top-mem --top-oom
IO检查:
iostat 安装的是sysstat:
yum install sysstat
iostat -d -k 1 2 |sed '/Device\Linux\|^$/d'
 iostat -d -k 1 9 |sed '/Device\Linux\|^$/d'

ssh安全:

 cat /var/log/secure |awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{printf "%-18s=%s\n",$2,$1}' 登录失败

 cat /var/log/secure |awk '/Accepted/{print $(NF-3)}'|sort|uniq -c|awk '{printf "%-18s=%s\n",$2,$1}' 登录成功

任务计划检查:

for i in $(awk -F ':' '{print $1}' /etc/passwd);do echo -e "$i" && crontab -u $i -l 2>/dev/null;done

###访问量监测

##haproxy总访问量

wc -l /var/www/logs/haproxy/haproxy_access_2018_08_02.log

##错误号:

awk '{a[$11]++}END{for(i in a)print i""a[i]}'  /var/www/logs/haproxy/haproxy_access_2018_08_02.log

##503错误时间段

awk '$11=="503"{split($7,a,":");time[a[2]":"a[3]]++}END {for (t in time)printf "TIME:%-15s NUM:%s\n",t,time[t]}' /var/www/logs/haproxy/haproxy_access_2018_08_02.log  sort -t: -nr -k2

###NGINX错误日志

tailf /var/www/logs/nginx_error.log

##nginx 错误日志---时间段统计

awk '/2016\/09\/21/ {split($2,t,":");time[t[1]]++}END{for (tt in time)print "时间段:"tt" ""错误率:"time[tt]}'  /var/www/logs/nginx_error.log |sort -t: -n -k2

用AWK有以下几种方法去调用变量:

1. awk '{print a,b}' a=111 b=222 yourfile

注意,变量位置要在file名之前,否则就不能调用。

还有,于BEGIN{} 中是不能调用这些的varible.要用之后所讲的第二种方法才可解决。

2. awk '{print " ' "$LOGNAME" ' "}' yourfile

第三种方法,为什么要加两个双引号和一个单引号?

$str = Hello

awk 'BEGIN{print "$a"}'

$a

$awk 'BEGIN{print " '$str' "}'

看上去是双引号套单引号,其实真正的原因为:

这是shell的功能,shell对单引号和双引号,从左到右的顺序成对匹配。

awk命令用单引号引起来,就是防止shell对其中内容进行解释

awk '{print " '$str' "}'  file

在最后 感谢伟哥的资源共享,走在成长的路上。记录一下

猜你喜欢

转载自blog.csdn.net/qq_32485197/article/details/81365705