Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Results are one convenient table now

  • Loading branch information...
commit cbd3edc899543e5b9b2c82c23dd8f33b1869eaa0 1 parent 8a7ab4d
Daniel Vartanov authored
View
49 README.textile
@@ -24,31 +24,30 @@ h3. Example of unreadable log:
h3. Example of isp-logs-parser output:
-<pre>+---------+--------------------------+-------------------------+
-| | internal | world |
-+---------+--------------------------+-------------------------+
-| daily | 81.20.21.134 [1.94GB] | 86.40.182.30 [54.3MB] |
-| | 217.29.28.102 [294MB] | 212.47.219.83 [358kB] |
-| | 217.29.21.21 [10.7MB] | 65.54.167.92 [282kB] |
-| | 91.205.50.59 [10.6MB] | 212.47.219.86 [260kB] |
-| | 85.113.0.25 [3.83MB] | 207.46.26.185 [220kB] |
-| | 212.2.228.113 [1.84MB] | 194.67.52.35 [116kB] |
-| | 81.20.16.4 [433kB] | 78.146.85.59 [102kB] |
-| | 212.42.103.178 [325kB] | 65.54.172.189 [99.9kB] |
-| | 89.237.225.252 [295kB] | 65.54.172.75 [86.6kB] |
-| | 77.95.58.175 [231kB] | 207.46.112.75 [56.9kB] |
-+---------+--------------------------+-------------------------+
-| nightly | 212.112.103.210 [35.3GB] | 86.40.182.30 [101MB] |
-| | 91.207.97.23 [464MB] | 87.248.210.200 [36.1MB] |
-| | 217.29.28.102 [337MB] | 87.248.209.186 [33.4MB] |
-| | 195.38.161.22 [334MB] | 82.99.19.11 [4.03MB] |
-| | 77.95.63.107 [228MB] | 92.122.213.202 [1.59MB] |
-| | 212.42.120.60 [193MB] | 195.27.30.8 [1.44MB] |
-| | 89.237.225.37 [130MB] | 207.46.112.47 [1.32MB] |
-| | 217.29.20.18 [101MB] | 207.46.112.45 [1.03MB] |
-| | 85.115.205.44 [90.4MB] | 207.46.112.71 [952kB] |
-| | 212.112.98.122 [82.2MB] | 65.54.167.92 [738kB] |
-+---------+--------------------------+-------------------------+</pre>
+<pre>+-----------------+---------+-----------+----------+
+| host | traffic | day/night | location |
++-----------------+---------+-----------+----------+
+| 212.112.103.210 | 35.3GB | nightly | internal |
+| 81.20.21.134 | 1.94GB | daily | internal |
+| 91.207.97.23 | 464MB | nightly | internal |
+| 217.29.28.102 | 337MB | nightly | internal |
+| 195.38.161.22 | 334MB | nightly | internal |
+| 217.29.28.102 | 294MB | daily | internal |
+| 77.95.63.107 | 228MB | nightly | internal |
+| 86.40.182.30 | 101MB | nightly | world |
+| 86.40.182.30 | 54.3MB | daily | world |
+| 87.248.210.200 | 36.1MB | nightly | world |
+| 87.248.209.186 | 33.4MB | nightly | world |
+| 217.29.21.21 | 10.7MB | daily | internal |
+| 91.205.50.59 | 10.6MB | daily | internal |
+| 82.99.19.11 | 4.03MB | nightly | world |
+| 85.113.0.25 | 3.83MB | daily | internal |
+| 92.122.213.202 | 1.59MB | nightly | world |
+| 212.47.219.83 | 358kB | daily | world |
+| 65.54.167.92 | 282kB | daily | world |
+| 212.47.219.86 | 260kB | daily | world |
+| 207.46.26.185 | 220kB | daily | world |
++-----------------+---------+-----------+----------+</pre>
h2. Installation
View
8 lib/host.rb
@@ -6,4 +6,12 @@ def amount_of_traffic
end
summ
end
+
+ def daily?
+ records.first.daily?
+ end
+
+ def internal?
+ records.first.internal?
+ end
end
View
4 lib/traffic.rb
@@ -10,8 +10,8 @@ def local_address
@local_address ||= find_local_address
end
- def highest_ten_hosts
- highest_hosts(10)
+ def highest_five_hosts
+ highest_hosts(5)
end
def hosts
View
15 lib/traffic_splitter.rb
@@ -1,15 +1,10 @@
class TrafficSplitter
def self.split_traffic!(traffic)
- {
- :internal => {
- :daily => traffic.daily.internal.highest_ten_hosts,
- :nightly => traffic.nightly.internal.highest_ten_hosts,
- },
+ hosts = traffic.daily.internal.highest_five_hosts +
+ traffic.nightly.internal.highest_five_hosts +
+ traffic.daily.world.highest_five_hosts +
+ traffic.nightly.world.highest_five_hosts
- :world => {
- :daily => traffic.daily.world.highest_ten_hosts,
- :nightly => traffic.nightly.world.highest_ten_hosts,
- }
- }
+ hosts.sort { |left, right| right.amount_of_traffic <=> left.amount_of_traffic }
end
end
View
34 parse!.rb
@@ -2,44 +2,36 @@
require File.join(File.dirname(__FILE__), 'init')
-def pretty_host(host)
- "#{host.address} [#{nice_bytes(host.amount_of_traffic)}]"
-end
-
-def result_string(split_traffic)
+def result_string(hosts)
require File.join(File.dirname(__FILE__), 'vendor', 'terminal-table', 'lib', 'terminal-table')
require 'terminal-table/import'
- t = table ['', 'internal', 'world']
-
- t << ['daily', pretty_host(split_traffic[:internal][:daily].first), pretty_host(split_traffic[:world][:daily].first)]
- 1.upto(9).each do |index|
- t << ['', pretty_host(split_traffic[:internal][:daily][index]), pretty_host(split_traffic[:world][:daily][index])]
- end
-
- t.add_separator
+ results_table = table ['host', 'traffic', 'day/night', 'location']
- t << ['nightly', pretty_host(split_traffic[:internal][:nightly].first), pretty_host(split_traffic[:world][:nightly].first)]
-
- 1.upto(9).each do |index|
- t << ['', pretty_host(split_traffic[:internal][:nightly][index]), pretty_host(split_traffic[:world][:nightly][index])]
+ hosts.each do |host|
+ results_table << [host.address,
+ nice_bytes(host.amount_of_traffic),
+ host.daily? ? 'daily' : 'nightly',
+ host.internal? ? 'internal' : 'world'
+ ]
end
- t
+ results_table
end
-puts ARGV.inspect
-
if ARGV.size < 1
puts "usage: parse\\!.rb log-file"
exit 1
end
log_file_name = ARGV[0]
+puts "Parsing #{log_file_name}..."
parser = Parser.new
records = parser.parse_file!(log_file_name)
-puts "#{records.size} records read from #{log_file_name}\n\n"
+puts "#{records.size} records read"
+
+puts "Calculating...\n\n"
traffic = Traffic.new records
split_traffic = TrafficSplitter.split_traffic!(traffic)
Please sign in to comment.
Something went wrong with that request. Please try again.