Tomcat log file Access IP statistics

Source: Internet
Author: User

Tomcat? localhost_access_log.2018-09-19.txt log file Access IP statistics

172.16.8.11--[19/sep/2018:12:35:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.1--[19/sep/2018:12:43:08 +0800] "get/images/loading.gif http/1.1" 200 404
172.16.8.1--[19/sep/2018:12:43:08 +0800] "Post/init http/1.1" 200 207
172.16.8.1--[19/sep/2018:12:43:12 +0800] "Post/init http/1.1" 200 207
172.16.8.1--[19/sep/2018:12:43:16 +0800] "get/http/1.1" 200 7612
172.16.8.1--[19/sep/2018:12:43:16 +0800] "get/css/default-init.css?1537325099834 http/1.1" 304-
172.16.8.1--[19/sep/2018:12:43:16 +0800] "Get/js/lib/jquery/jquery.min.js http/1.1" 304-
172.16.8.1--[19/sep/2018:12:43:16 +0800] "Get/images/logo.png http/1.1" 304-
172.16.8.11--[19/sep/2018:12:45:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:12:55:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:13:05:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:13:15:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:25:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:35:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:45:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:55:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:05:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:15:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:25:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:35:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:45:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613

Shell Script

[[email protected] logs]# awk ' {aaa[$1]++;} End{for (i in AAA) {printf ("%s\t%s\n", Aaa[i], i);}} ' Localhost_access_log.2018-09-19.txt | Sort-bn
2?? ? 127.0.0.1
24?? ? 172.16.8.1
26?? ? 172.16.8.11
[[email protected] logs]# grep-i-o-e-r-e "([0-9]{1,3}.) {3} [0-9] {1,3} "Localhost_access_log.2018-09-19.txt | Sort-n | uniq-c | Sort-n
? ? ? 2 127.0.0.1
???? 24 172.16.8.1
???? 26 172.16.8.11
[[email protected] logs]# awk ' {print $} ' localhost_access_log.2018-09-19.txt | Grep-e "([0-9]{1,3}.) {3} [0-9] {1,3} "| Sort | uniq-c | Sort-g
? ? ? 2 127.0.0.1
???? 24 172.16.8.1
???? 26 172.16.8.11
Python script

Cat log.py?
Import re
Mydict = {}
With open (' Localhost_access_log.2018-09-19.txt ') as F:
? ? ? ? For line in F:
? ? ? ? ? ? ? ? Match = Re.match (R ' ([0-9]{1,3}.) {3} [0-9] {1,3} ', line)
? ? ? ? ? ? ? ? If match:
? ? ? ? ? ? ? ? ? ? ? ? ip = Match.group ()
? ? ? ? ? ? ? ? ? ? ? ? If IP in Mydict.keys ():
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MYDICT[IP] + = 1
? ? ? ? ? ? ? ? ? ? ? ? Else
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MYDICT[IP] = 1

Print Mydict

Execution results
[email protected] logs]# python log.py?
{' 172.16.8.1 ': 24, ' 172.16.8.11 ': 27, ' 127.0.0.1 ': 2}

Tomcat log file Access IP statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.