{"id":963,"date":"2017-02-24T13:01:32","date_gmt":"2017-02-24T13:01:32","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=963"},"modified":"2017-02-24T13:03:00","modified_gmt":"2017-02-24T13:03:00","slug":"count-number-ips-given-time-period-apache-log","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2017\/02\/24\/count-number-ips-given-time-period-apache-log\/","title":{"rendered":"Count number of IP&#8217;s over a given time period in Apache Log"},"content":{"rendered":"<p>So, a customer had an outage, and wasn&#8217;t sure what caused it. It looked like some IP&#8217;s were hammering the site, so I wrote this quite one liner just to sort the IP&#8217;s numerically, so that uniq -c can count the duplicate requests, this way we can count exactly how many times a given IP makes a request in any given minute or hour:<\/p>\n<p><strong> Any given minute <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# grep '24\/Feb\/2017:10:03' \/var\/www\/html\/website.com\/access.log | awk '{print $1}' | sort -k2nr | uniq -c\r\n<\/pre>\n<p><strong> Any given hour <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# grep '24\/Feb\/2017:10:' \/var\/www\/html\/website.com\/access.log | awk '{print $1}' | sort -k2nr | uniq -c\r\n<\/pre>\n<p><strong> Any Given day <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# grep '24\/Feb\/2017:' \/var\/www\/html\/website.com\/access.log | awk '{print $1}' | sort -k2nr | uniq -c\r\n<\/pre>\n<p><strong> Any Given Month <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# grep '\/Feb\/2017:' \/var\/www\/html\/website.com\/access.log | awk '{print $1}' | sort -k2nr | uniq -c\r\n<\/pre>\n<p><strong> Any Given Year <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# grep '\/2017:' \/var\/www\/html\/website.com\/access.log | awk '{print $1}' | sort -k2nr | uniq -c\r\n<\/pre>\n<p>Any given year might cause dupes though, and I&#8217;m sure there is a better way of doing that which is more specific<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, a customer had an outage, and wasn&#8217;t sure what caused it. It looked like some IP&#8217;s were hammering the site, so I wrote this quite one liner just to sort the IP&#8217;s numerically, so that uniq -c can count &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2017\/02\/24\/count-number-ips-given-time-period-apache-log\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,58,63,73,74,7,29,61],"tags":[],"class_list":["post-963","post","type-post","status-publish","format-standard","hentry","category-apache","category-benchmarking","category-disk-tools","category-log-analysis","category-logging","category-management-tools","category-monitoring","category-rackspace"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=963"}],"version-history":[{"count":2,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/963\/revisions"}],"predecessor-version":[{"id":965,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/963\/revisions\/965"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}