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'] next if request == nil 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)