栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > 服务器

shell脚本定时统计Nginx下access.log的PV并发送给API保存到数据库

服务器 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

shell脚本定时统计Nginx下access.log的PV并发送给API保存到数据库

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/count"
log_date=`date "+%d/%b/%Y"`
echo ${log_date}
total_visit=`cat ${log_path} | grep $log_date|wc -l`
curl -d "count=${total_visit}" ${domain}
echo $total_visit

4,服务器端接受并保存到数据库

@RequestMapping(value = "/count")
  public void count(String count){
  //业务代码 
}

总结

以上所述是小编给大家介绍的shell脚本定时统计Nginx下access.log的PV并发送给API保存到数据库,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/179471.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号