Miscellaneouss

Check level of traffic on website using command line with apache access log

web-traffic-level
mm
Written by Santosh Prasad

Hello Friend, In this post I am going to explain, how you can check the traffic level on your website using command line on your virtual and dedicated server. If you want to check what is going on your website and server,  Apache logs give you more information. Every visitor request which goes through Apache server. It logged into access log with detail of visitor activity.

If you are facing problem with load spike on your server you can check Apache access log. You can grep specific time range in your access log and check with the server load spike. I this post I am going explain how you can check traffic level from your Apache access log with command line.

Checking number of request by the time

The best method is quick overview of your website traffic is to check how frequently requests are coming on the server. In this post I will explain how you can check the number of request per minute,per hour and per day.

Login to server using ssh

#ssh -i  /root/key/my_ssh.key  [email protected]

After login go to your access log location. My Apache access log location is “/var/log/httpd/access.log”.

#cd /var/log/httpd/

Than run the following command to view the latest Apache access log.

# ls –larth

total 22M

drwxr-xr-x 2 root root 4.0K Nov 20 01:01 .

drwxr-xr-x 7 root root 4.0K Dec 21  2010 ..

-rw-rw-r– 1 root root    0 Oct  4  2015 ssl_error_log

-rw-rw-r– 1 root root    0 Dec 27  2015 ssl_access_log

-rw-rw-r– 1 root root 2.7M Nov 21 21:16 error_log

-rw-rw-r– 1 root root 5.9M Nov 21 21:16 access_log

Check request/hits per day

Run the below command to check the request per day with the help of Apache access log.

# awk ‘{print $4}’ access_log | cut -d: -f1 | uniq –c

You will get something like below:

     3 [07/Nov/2016

4024 [08/Nov/2016

3474 [09/Nov/2016

3654 [10/Nov/2016

2627 [11/Nov/2016

2172 [12/Nov/2016

1327 [13/Nov/2016

2808 [14/Nov/2016

4426 [15/Nov/2016

2033 [16/Nov/2016

1034 [17/Nov/2016

579 [18/Nov/2016

507 [19/Nov/2016

1267 [20/Nov/2016

2979 [21/Nov/2016

Here :

awk ‘{print $4}’ access_log :-  We are using awk command to print the 4th column form Apache access log which is time-stamp.

cut -d: -f1 | uniq –c :- We are using cut command with –d and -f to set the colon : and grep the field to show the first before delimiter.

Check request/hits  per hour

Run the below command to check the request per hour.

#grep “08/Nov” access_log | cut -d[ -f2 | cut -d] -f1 | awk -F: ‘{print $2″:00″}’ | sort -n | uniq –c

You will get something like below:

    34 00:00

1417 01:00

828 02:00

181 03:00

465 04:00

481 05:00

412 06:00

5 07:00

2 09:00

1 10:00

17 11:00

2 12:00

1 13:00

18 15:00

1 16:00

16 19:00

16 20:00

2 21:00

125 23:00

Please see the man page of grep,cut,awk and sort for more detail.

Check request/hits  per minute

Run the below command to check the request per hour.

#grep “08/Nov/2016:01″ access_log | cut -d[ -f2 | cut -d] -f1 | awk -F: ‘{print $2”:”$3}’ | sort -nk1 -nk2 | uniq -c | awk ‘{ if ($1 > 10) print $0}’

You will get something like below:

     17 01:01

14 01:10

13 01:12

28 01:14

52 01:15

11 01:16

14 01:21

25 01:23

14 01:24

89 01:26

52 01:27

70 01:28

79 01:29

40 01:30

13 01:31

77 01:32

34 01:33

36 01:34

98 01:35

21 01:36

26 01:37

13 01:38

12 01:39

13 01:40

12 01:41

13 01:42

12 01:43

15 01:44

89 01:45

46 01:46

19 01:48

13 01:49

16 01:50

22 01:51

41 01:52

17 01:53

14 01:54

14 01:55

30 01:56

67 01:57

61 01:58

15 01:59

Please see the man page of grep,cut,awk and sort for more detail.

Now you can see the traffic of level on your website per day, per hour and per minute with the help of Apache access log.

I hope this article will be helpful to you to find the level of traffic on your website. If you have any queries and problem please comment in comment section.

Thanks:)

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment