Apache Log Visualization with Matplotlib : Learn Data Science
This post discusses Apache log visualization with Matplotlib library. First, download the data file used in this example from here.
We will require numpy and matplotlib
In [1]:
import numpy as np
import matplotlib.pyplot as plt
numpy.loadtext() can directly load a text file in an array requests-idevji.txt contains only hour on which request was made, this is achieved by pre-prcoessing the Apache log.
In [2]:
data = np.loadtxt (‘requests-idevji.txt’)
We need 24 bins because we have 24 hours’ data. For other attributes of hist() see references.
In [3]:
plt.hist(data, bins=24)
plt.title(“Requests @ iDevji”)
plt.xlabel(“Hours”)
plt.ylabel(“# Requests”)
Out[3]:
Text(0,0.5,’# Requests’)
In [4]:
plt.show()
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY4AAAEWCAYAAABxMXBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz AAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo dHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAGYZJREFUeJzt3XnUHXWd5/H3h80FZQ8IAYwiake7 RTsNatPTKLIIjjA2IkprRBxaD/bRcQWPR7TVaTxti9rdOoIgAUVk3KDdMI2KOi4QEFmlyWAYiBGC YXcj8J0/6he4hjzJrZD7rO/XOc95qn5Vt+p76zy5n/x+tdxUFZIkDWujiS5AkjS1GBySpF4MDklS LwaHJKkXg0OS1IvBIUnqxeCQpoEkRyb51jjt66+SXDswf1WSfcZj35oc4n0cmqySLAF2AO4D7ga+ Cbyhqu6eyLrG0j48P1NVOz+MbTwaeAPwMuAJwD3A94APVdVPe2yngN8ABfweuAw4uao+v761SavY 49Bk91+r6jHAHsAzgeMnuJ6RSfI44EfAE4HXAI8D/gT4EvCZJEf13OQz2rF7CnA68K9JTthwFWum Mjg0JVTVr4Dz6QIEgCSPSPKhJP8vyc1J/leSRw0sf1uSZUl+meQ1SSrJk9qy7yZ57cC6r07yg4H5 pyZZmGRFkmuTHD6w7KAkVye5K8nSJG9Nsjnw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0X8TBseD fKwJkGTzJI9dNQ3sD1y59ldNe+cB89v0fODcCaxlwqz6oGz+GzPg7yJJgFOBa6rqwwOLZvTfhHeO D2iXF36EBx9r8oEJLmncJXkiXS8DukfSnDWTjkOSzwH70D06+2bgBOArwDnArsANwOFVNa1PHI9x HPahG6YqYAnwdwPj/NNSkr2B7wNXAPe35nfSneeYUX8TgwwOSVIvDlVJknoxOCRJvRgckqReDA5J Ui8GhySpF4NDWk9J7l5t/tVJ/nWi6pHGi8EhTTJJpsRXOmvmMjikEUgyJ8m32wMBL0iya2s/Pclh A+vd3X7vk+T7Sc4Drm538H8tyc+SXJnkZRP0VqSH8H820vp7VJLLBua34cHH1PwLsKCqFiR5DfAx 1v3o7WcBT6+qXyT5G+CXVXUwQJItN3Dt0nqzxyGtv98OfKnRHsC7B5Y9BzirTZ8J7D3E9i6qql+0 6SuA/ZJ8MMlfVdUdG65s6eExOKTxtZL27y7JRsBmA8vuWTVRVf9J1wO5Anh/ksFQkiaUwSGNxg/p nrAMcCTdg/Kgezjgn7fpFwObrunFSXYCflNVnwH+iS5EpEnBcxzSaPw98OkkbwOWA0e19lOAc5P8 DPgmA72M1fwp8E9J7gfuBV4/4nqlofl0XElSLw5VSZJ6MTgkSb0YHJKkXgwOSVIvBockqReDQ5LU i8EhSerl/wNIVKauyJc3VgAAAABJRU5ErkJggg==)
References:
Apache Log Visualization with Matplotlib : Learn Data Science
http://idevji.com/apache-log-visualization-with-matplotlib.html