shell脚本定时统计Nginx下access.log的PV并发送给API保存到数据库
发布日期:2022-03-28 14:54 | 文章来源:站长之家
1,统计PV和IP
统计当天的PV(Page View)
cat access.log | sed -n /`date "+%d\/%b\/%Y"`/p |wc -l
统计某一天的PV
cat access.log | sed -n '/20\/Sep\/2018/p' | wc -l
查看日志中访问次数最多的前10个IP
cat access.log.1 |cut -d ' ' -f 1 | sort |uniq -c | sort -nr | awk '{print $0 }' | head -n 10
查看日志中访问次数超过1000次的前10个IP
cat access.log.1 |cut -d ' ' -f 1 | sort |uniq -c | sort -nr | awk '{if($1>1000) print $0 }' | head -n 10
2,curl发送数据
使用curl发送GET请求
curl http://127.0.0.1:8080/login?admin&passwd=12345678
使用curl发送POST请求
curl -d "user=admin&passwd=12345678" http://127.0.0.1:8080/login
使用curl发送POST的JSON数据
curl -H "Content-Type:application/json" -X POST -d '{"user": "admin", "passwd":"12345678"}' http://127.0.0.1:8000/login
使用curl发送动态参数POST请求
curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'$atime'","BTime":"'$btime'"}' $url curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'${atime}'","BTime":"'{$btime}'"}' ${url}
3,shell脚本统计并发送
#!/bin/bash log_path=/var/log/nginx/access.log domain="http://127.0.0.1:8080/data/cou
4,服务器端接受并保存到数据库
@RequestMapping(value = "/cou
总结
以上所述是小编给大家介绍的shell脚本定时统计Nginx下access.log的PV并发送给API保存到数据库,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对本站网站的支持!
版权声明:本站文章来源标注为YINGSOO的内容版权均为本站所有,欢迎引用、转载,请保持原文完整并注明来源及原文链接。禁止复制或仿造本网站,禁止在非www.yingsoo.com所属的服务器上建立镜像,否则将依法追究法律责任。本站部分内容来源于网友推荐、互联网收集整理而来,仅供学习参考,不代表本站立场,如有内容涉嫌侵权,请联系alex-e#qq.com处理。
相关文章