1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
adell [148]
3 years ago
12

Your program will be parsing and analyzing log files from an Apache web server. The first thing your program must do is retrieve

the log file across the network. It is available here: https://s3.amazonaws.com/tcmg476/http_access_logOnce you download the file, you will be parsing the file in order to answer several questions:How many total requests were made in the time period represented in the log?How many requests were made on each day? per week? per month?What percentage of the requests were not successful (any 4xx status code)?What percentage of the requests were redirected elsewhere (any 3xx codes)?What was the most-requested file?What was the least-requested file?You will need to output this data to the screen. The format you choose for this is up to you (human readable, machine readable, plain text, JSON, etc), but your decisions and the implementation should be logical and consistent.Finally, the logs should be broken into separate files by month. Your program should split the log file into 12 smaller files, where the data stored in each file are the log events for a single month. These should be written to disk in the same directory as your program file, in a logical and consistent manner.
Engineering
1 answer:
vova2212 [387]3 years ago
5 0

Answer:

#python script for parsing log

#following programme assumes that all the logs follow common log format of apache logs

#given below is example of a common format log

#127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326

import requests

url = "https://s3.amazonaws.com/tcmg476/http_access_log"

r = requests.get(file_url, stream = True)

with open("python.txt","wb") as textfile:

  for chunk in r.iter_content(chunk_size=1024):

  # writing one chunk at a time to pdf file

      if chunk:

          textfile.write(chunk)

result={

"total_requests":0,

"per_day_data":{},

"per_week_data":{},

"per_month_data":{},

"request_not_successful":0,

"requests_redirected_elsewhere":0,

"filewise_request_frequency":{},

"most_requested_file":[0,[]], #maximum request and list of all files with that number of request

"least_requested_file":[0,[]] #minimum request and list of all files with that number of request

}

file = open("python.txt")

date_day = None

days = 0

week = None

months_done = []

for line in file:

  if(len(line)>=56):

      result["total_requests"]+=1

      data=line.split()

      date = data[3][1::].split(':')

      if not (date_day == date[0]):

          date_day = date[0]

          days += 1

          if(days%7 == 0):

              week = date_day

      if date[0] in result["per_day_data"]:

          result["per_day_data"][date[0]]+=1

      else:

          result["per_day_data"][date[0]]=0

     

      if week in result["per_week_data"]:

          result["per_week_data"][week]+=1

      else:

          result["per_week_data"][week] = 0

      month = date[0][3::]

      if month not in months_done:

          file_name = month[:3:]+month[4::]

          if(len(file_name)) == 7:

              month_file = open(month[:3:]+month[4::]+".txt",'w')

              print(file_name)

          months_done.append(month)

      month_file.write(line)

      if month in result["per_month_data"]:

          result["per_month_data"][month]+=1

      else:

          result["per_month_data"][month]=0

      if data[-2][0]=="4":

          result["request_not_successful"]+=1

      if data[-2][0]=="3":

          result["requests_redirected_elsewhere"]+=1

      if data[6] in result["filewise_request_frequency"]:

          result["filewise_request_frequency"][data[6]]+=1

      else:

          result["filewise_request_frequency"][data[6]]=1

 

maxm=result["filewise_request_frequency"]["index.html"]

minm=result["filewise_request_frequency"]["index.html"]

maxlist=["index.html"]

minlist=["index.html"]

for i in result["filewise_request_frequency"]:

  if result["filewise_request_frequency"][i] > maxm:

      maxm = result["filewise_request_frequency"][i]

      maxlist=[i]

  if result["filewise_request_frequency"][i] < minm:

      minm = result["filewise_request_frequency"][i]

      minlist=[i]

 

  if result["filewise_request_frequency"][i] == maxm:

      maxlist.append(i)

 

  if result["filewise_request_frequency"][i] == minm:

      minlist.append(i)

result["most_requested_file"]=[maxm,maxlist]

result["least_requested_file"]=[minm,minlist]

print(result)

Explanation:

You might be interested in
Gold forms a substitutional solid solution with silver. Compute the number of gold atoms per cubic centimeter for a silver-gold
evablogger [386]

Answer:

Compute the number of gold atoms per cubic centimeter = 9.052 x 10^21 atoms/cm3

Explanation:

The step by step and appropriate substitution is as shown in the attachment.

From number of moles = Concentration x volume

number of moles = number of particles/ Avogadro's number

Volume = mass/density, the appropriate derivation to get the number of moles of atoms

5 0
3 years ago
Show that for a linearly separable dataset, the maximum likelihood solution for the logisitic regression model is obtained by fi
KATRIN_1 [288]

Answer:

Answer for the question:

"Show that for a linearly separable dataset, the maximum likelihood solution for the logisitic regression model is obtained by finding a weight vector w whose decision boundary wx. "

is explained in the attachment.

Explanation:

8 0
3 years ago
Handsaw teeth are very sharp: to avoid being cut by the teeth, keep hands and fingers well away from the
siniylev [52]
Handsaw teeth are very sharp: to avoid being cut by the teeth, keep hands and fingers well away from the
path of the blade
6 0
3 years ago
Read 2 more answers
What should you, the worker, be aware of with regard to evacuation procedures at your workplace
Alinara [238K]

Answer:

As a worker, it is important to follow the proper set of instructions or emergency plans during an emergent situation. Not carefully following the rules may result to a bigger problem such as further injury and damage to property.

Explanation:

Evacuation Procedure- This is a step-by-step procedure that people follow in order to safely vacate any building or place. This procedure is applicable to any situation, such as the workplace. This is now called the <em>Workplace Evacuation Procedure. </em>This is very important because there are so many unpredictable situations or events that are happening in the world right now, such as fire or earthquake. This procedure is being done through an evacuation plan.

The awareness of the workers regarding the proper way to evacuate during emergency situation is very important. It will be easier for them to know where to locate the nearest exit route. They will also learn to stop any form of device or equipment that could cause a hazzard during the situation. In case of the hospital, which is also a workplace, the employees will also learn how to assist the patients before themselves. They will also know where to assemble if there's a need to do so.

7 0
4 years ago
Read 2 more answers
Determine the maximum intensity ww of the uniform distributed load that can be applied to the beam without risk of causing the s
AnnyKZ [126]

Answer:

Please see attachment

Explanation:

Please see attachment

3 0
4 years ago
Other questions:
  • The popularity of orange juice, especially as a breakfast drink, makes it an important factor in the economy of orange-growing r
    14·1 answer
  • Assignment 1: Structural Design of Rectangular Reinforced Concrete Beams for Bending
    6·1 answer
  • R 134a enters a air to fluid heat exchanger at 700 kPa and 50 oC. Air is circulated into the heat exchanger to cool the R134a to
    6·1 answer
  • The creation of designer drugs is outpacing the ability of society to enact laws to prohibit them. Many of these substances have
    11·1 answer
  • Create a project named CarDealer that contains a Form for an automobile dealer. Include options for at least three car models. A
    14·1 answer
  • What causes decay in the amplitudes of vibration?
    11·1 answer
  • 4. An aluminum alloy fin of 12 mm thick, 10 mm width and 50 mm long protrudes from a wall, which is maintained at 120C. The amb
    6·1 answer
  • Recall the steps of the engineering design process. Compare and contrast the
    9·1 answer
  • A type of adjustable square that can be used to set, test, and transfer angles is called a
    5·1 answer
  • How does data mining help interactive marketing for a business?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!