In [42]:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [8]:
with open("fake_access_log_dist.log") as logfile:
    lines = logfile.readlines()

In [10]:
print(lines[:5])
print(lines[0].split())


['206.195.175.205 - Galvin [30/Dec/2016:14:25:20 -0700] "GET /list HTTP/2.0" 200 6894\n', '89.110.214.223 - Galvin [30/Dec/2016:14:25:22 -0700] "POST /doc/readme.txt HTTP/2.0" 200 7144\n', '93.134.171.142 - Chapman [30/Dec/2016:14:25:24 -0700] "GET /doc/charge.txt HTTP/2.0" 301 4026\n', '51.80.20.151 - Bud [30/Dec/2016:14:25:26 -0700] "DELETE /app/main HTTP/2.0" 301 6266\n', '160.150.239.21 - Alden [30/Dec/2016:14:25:28 -0700] "GET /doc/readme.txt HTTP/2.0" 200 9955\n']
['206.195.175.205', '-', 'Galvin', '[30/Dec/2016:14:25:20', '-0700]', '"GET', '/list', 'HTTP/2.0"', '200', '6894']

In [36]:
methods = {}

for line in lines:
    method = line.split()[5]
    method = method.strip("'")
    method = method.strip('"')
    if method not in methods:
        methods[method] = 1
    else:
        methods[method] += 1
        
print(methods)


{'PUT': 9, 'DELETE': 15, 'POST': 25, 'GET': 74}

In [51]:
x = [i for i in range(len(methods))]
y = list(methods.values())
y_sum = sum(y)
y = [float(i/y_sum) for i in y]
    

print(x)
print(y)

plt.xticks(x, list(methods.keys()))
plt.title('Methods Distribution')
plt.bar(x, y, align='center', alpha=0.5)


[0, 1, 2, 3]
[0.07317073170731707, 0.12195121951219512, 0.2032520325203252, 0.6016260162601627]
Out[51]:
<Container object of 4 artists>