In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how the shell script realizes the timed statistics of the PV of access.log under Nginx and sends it to API to save to the database. The article is very detailed and has certain reference value. Interested friends must read it!
1. Statistics of PV and IP
Count the PV (Page View) of the day
Cat access.log | sed-n / `date "+% d\ /% b\ /% Y" `/ p | wc-l
Count the PV of a certain day
Cat access.log | sed-n'/ 20\ / Sep\ / 2018Unip'| wc-l
View the top 10 most visited IP in the log
Cat access.log.1 | cut-d ''- f 1 | sort | uniq-c | sort-nr | awk'{print $0}'| head-n 10
View the top 10 IP with more than 1000 visits in the log
Cat access.log.1 | cut-d'- f 1 | sort | uniq-c | sort-nr | awk'{if ($1 > 1000) print $0}'| head-n 10
2the data is sent by dint curl.
Send a GET request using curl
Curl http://127.0.0.1:8080/login?admin&passwd=12345678
Send a POST request using curl
Curl-d "user=admin&passwd=12345678" http://127.0.0.1:8080/login
Use curl to send JSON data for POST
Curl-H "Content-Type:application/json"-X POST-d'{"user": "admin", "passwd": "12345678"} 'http://127.0.0.1:8000/login
Send a dynamic parameter POST request using curl
Curl-I-X POST-H "'Content-type':'application/json'"-d' {"ATime": "'$atime'", "BTime": "'$btime'"}'$urlcurl-I-X POST-H "'Content-type':'application/json'"-d' {"ATime": "'${atime}'", "BTime": "'{$btime}'"}'${url}
3Jing shell script statistics and send
#! / bin/bashlog_path=/var/log/nginx/access.logdomain= "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. The server accepts it and saves it to the database
@ RequestMapping (value = "/ count") public void count (String count) {/ / Business Code} these are all the contents of the article "how to regularly count the PV of access.log under Nginx and send it to API to save in the database". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.