zoukankan      html  css  js  c++  java
  • 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){
        //业务代码  
    }
  • 相关阅读:
    day25:接口类和抽象类
    vue1
    How the weather influences your mood?
    机器学习实验方法与原理
    How human activities damage the environment
    Slow food
    Brief Introduction to Esports
    Massive open online course (MOOC)
    Online learning in higher education
    Tensorflow Dataset API
  • 原文地址:https://www.cnblogs.com/i-tao/p/9668113.html
Copyright © 2011-2022 走看看