Learn Log Analysis with Matplotlib

graphic

What is Matplotlib

Matplotlib is a great Python library where you can output any line, histogram, bar, phase, circular, and more graphic formats on data with just a few lines of code. You can easily use information from nufus distributions in the country, from the graph of a mathematical equation, from any subject you can think of such as the speed of distribution of harmful software. He will respond to your business and needs in every subject that the statistics go into the business. In daily life, the subject can be applied on many issues by saying Let’s make girizgahına.
As mentioned above, access belongs to a website in this article.any access in the script we will write with the help of matplotlib using certain information in the log file.we will export the log file so that we can export the most requested IP addresses and request values to the graph. Let’s go!

How to Install Matplotlib

First of all, set up our library with the following command.

Let’s start incorporating our libraries into our code.

The most requested n. we get our n argument value and log file name from outside as we will list it up to the record.

access.log each line of our file is listed as a list element.

Sonrasında log dosyamızdaki yalnızca ip sutununu alacak şekilde parse edelim ve ip değerlerimizi bir ip listesine atayalım.

we reduce the repeat IP addresses in our log file to one.(To prevent it from happening again))

Now, let’s find the total number of requests from each IP. So the frequency.

In a list, we sort the IP and IP numbers in 2-element bundles according to the number of requests from size to size.

Now, let’s determine our axis points to draw on the plota.

the number of frequencies in our y_axis variable, and the number of IP addresses in our x_label variable.

Lets test, let’s look at the top 10 IP that makes the most requests.

graphic
graphic

Read our cases summaries at www.lawteacher.net