Class: ApacheLogAnalyzer

Inherits:
LogAnalyzer show all
Defined in:
lib/ip-world-map/apache_log_analyzer.rb

Instance Attribute Summary

Attributes inherited from LogAnalyzer

#host_coordinates

Instance Method Summary collapse

Methods inherited from LogAnalyzer

#analyze, #calculate_oldest_time, #calculate_slot_start_time, #details_from_line, #group_by_time

Constructor Details

#initialize(*filenames) ⇒ ApacheLogAnalyzer

Returns a new instance of ApacheLogAnalyzer.



4
5
6
7
8
# File 'lib/ip-world-map/apache_log_analyzer.rb', line 4

def initialize *filenames
  super
  @@host_regex = /^([\w.-]+)/
  @@time_regex = /\[(\d{2})\/([a-zA-Z]{3})\/(\d{4}):(\d{2}):(\d{2}):(\d{2}) [+-](\d{2})(\d{2})\]/
end

Instance Method Details

#extract_host_from_line(line) ⇒ Object



10
11
12
13
# File 'lib/ip-world-map/apache_log_analyzer.rb', line 10

def extract_host_from_line line
  # IP: "123.1.2.3" or HOSTNAME: "hostname.domain"
  host = $1 if line =~ @@host_regex
end

#extract_time_from_line(line) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ip-world-map/apache_log_analyzer.rb', line 15

def extract_time_from_line line
  # CLF format: "[dd/MMM/yyyy:hh:mm:ss +-hhmm]"

  # TODO: add timezone information
  #dd, mmm, yyyy, hh, mm, ss, tz_hh, tz_mm = $1, $2, $3, $4, $5, $6, $7, $8 if line =~ @@time_regex
  #Time.utc(yyyy, mmm, dd, hh.to_i - tz_hh.to_i, mm, ss)
  dd, mmm, yyyy, hh, mm, ss = $1, $2, $3, $4, $5, $6 if line =~ @@time_regex
  Time.utc(yyyy, mmm, dd, hh, mm, ss)
end