dcav-stats/bandwidth.rb
Christoffer Müller Madsen 96e31c2479 add bandwidth to table
2017-05-23 00:09:10 +02:00

24 lines
554 B
Ruby

require 'server_log_parser'
require 'filesize'
require 'json'
load 'config.rb'
parser = ServerLogParser::Parser.new(ServerLogParser::COMBINED)
bw_sum = Hash.new(0)
log = `zcat /var/shots/logs/access.log.gz`
log.split("\n").each do |line|
parsed = parser.parse(line)
request = parsed['%r'].split(" ")[1]
bytes = parsed['%b'].to_i
status = parsed['%>s']
user = request[1]
bw_sum[user] += bytes unless user == nil or status != "200"
end
puts JSON.generate(bw_sum.map{|k,v| [NAMES_SHO[k],Filesize.from(v.to_s + 'B').pretty]}.to_h)