Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize shell Statistics pv and uv Independent ip

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to achieve shell statistics pv and uv independent ip", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to achieve shell statistics pv and uv independent ip"!

The access log file output by Nngix is as follows:

Log file code

The code is as follows:

192.168.1.166-119272312 [05/Nov/2011:16:06:59 + 0800] "GET / index.html HTTP/1.1" 200370 "http://192.168.1.201/"" Chrome/15.0.874.106 ""-"

192.168.1.166-119272312 [05/Nov/2011:16:06:59 + 0800] "GET / poweredby.png HTTP/1.1" 3034 "http://192.168.1.201/"" Chrome/15.0.874.106 ""-"

192.168.1.177-1007071650 [05/Nov/2011:16:06:59 + 0800] "GET / favicon.ico HTTP/1.1" 404 3650 "-" Chrome/15.0.874.106 ""-"

192.168.1.178-- 58565468 [05/Nov/2011:16:17:40 + 0800] "GET / HTTP/1.1" 3700 "-" Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) ""-"

192.168.1.166-119272312 [05/Nov/2011:16:17:40 + 0800] "GET / nginx-logo.png HTTP/1.1" 200370 "http://192.168.1.201/"" Chrome/15.0.874.106 ""-"

PV is very simple. It roughly counts the number of visits to a URL, such as the number of visits to / index.html.

The code is as follows:

Grep "/ index.html" / var/log/nginx/access.log-c

As for UV, according to the user ID (the fourth column), we first need to intercept the string, use the cut command, split it with a space symbol,-d "", and then take the fourth column-f 4, and then we need to arrange weights here, and we need to use the uniq tool. Uniq is very fast, but based on the nearest weight, the former and the latter can also be weighed, and if the spacing is not the same, it won't work. It is necessary to use the sort tool to sort the identifiers, and then use the uniq tool to achieve the goal. We use pipe symbolic links between them, and finally use wc-l to output statistics.

For example, we counted the uv of / index.html which is also on the page:

The code is as follows:

Grep "/ index.html" / var/log/nginx/access.log | cut-d ""-f 4 | sort | uniq | wc-l

Stand-alone IP:

Suppose we want to count the independent IP of the whole site, then we don't need to use grep to match specific pages, we just need to use cat output:

The code is as follows:

Cat / var/log/nginx/access.log | cut-d ""-f 1 | sort | uniq | wc-l

At this point, I believe you have a deeper understanding of "how to achieve shell statistics pv and uv independent ip". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report