diff --git a/bandwidth.rb b/bandwidth.rb
new file mode 100644
index 0000000..c935281
--- /dev/null
+++ b/bandwidth.rb
@@ -0,0 +1,23 @@
+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)
diff --git a/dcav-index.erb b/dcav-index.erb
index c35126d..ddbf207 100644
--- a/dcav-index.erb
+++ b/dcav-index.erb
@@ -5,6 +5,7 @@
>
+
Screenshot statistics for dcav.pw
@@ -16,10 +17,11 @@
Count |
Size |
Average size |
+ Bandwidth |
<% order = 0
users.sort.each do |user|
- order += 1
+ order += 1
%>
<%= %Q{
@@ -28,6 +30,7 @@
#{user.count} |
#{Filesize.from(user.size.to_s + "B").pretty} |
#{Filesize.from(user.avgsize.to_s + "B").pretty} |
+ #{user.bandwidth.to_s} |
}
%>
<% end %>
diff --git a/gen_index.rb b/gen_index.rb
index 9d806a1..a4f685b 100644
--- a/gen_index.rb
+++ b/gen_index.rb
@@ -1,5 +1,6 @@
require 'erb'
require 'filesize'
+require 'json'
load 'config.rb'
@@ -8,8 +9,10 @@ shot_dir = SHOT_DIR
erb_file = ERB_FILE
html_file = HTML_FILE
+bw = JSON.parse(`ruby bandwidth.rb`)
+
class User
- attr_accessor :name, :count, :size, :avgsize
+ attr_accessor :name, :count, :size, :avgsize, :bandwidth
def <=> other
other.count <=> count
end
@@ -26,8 +29,9 @@ usernames.each do |username|
.delete("\n")
.to_i
user.avgsize = user.size / user.count
-
- users << user
+ user.bandwidth = bw[username]
+
+ users << user
end
File.open(html_file, 'w') do |f|