mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
track bandwidth usage
This commit is contained in:
parent
ee9ad3f759
commit
caa702c964
2 changed files with 62 additions and 0 deletions
31
app/admin.rb
31
app/admin.rb
|
@ -15,6 +15,37 @@ post '/admin/reports' do
|
|||
|
||||
end
|
||||
|
||||
get '/admin/usage' do
|
||||
require_admin
|
||||
today = Date.today
|
||||
current_month = Date.new today.year, today.month, 1
|
||||
|
||||
@monthly_stats = []
|
||||
|
||||
month = current_month
|
||||
|
||||
until month.year == 2015 && month.month == 1 do
|
||||
stats = DB[
|
||||
'select sum(views) as views, sum(hits) as hits, sum(bandwidth) as bandwidth from stats where created_at >= ? and created_at < ?',
|
||||
month,
|
||||
month.next_month].first
|
||||
|
||||
stats.keys.each do |key|
|
||||
stats[key] ||= 0
|
||||
end
|
||||
|
||||
stats.collect {|s| s == 0}.uniq
|
||||
|
||||
unless stats.select {|k,v| v == 0}.length == stats.keys.length
|
||||
@monthly_stats.push stats.merge(date: month)
|
||||
end
|
||||
|
||||
month = month.prev_month
|
||||
end
|
||||
|
||||
erb :'admin/usage'
|
||||
end
|
||||
|
||||
get '/admin/email' do
|
||||
require_admin
|
||||
erb :'admin/email'
|
||||
|
|
31
views/admin/usage.erb
Normal file
31
views/admin/usage.erb
Normal file
|
@ -0,0 +1,31 @@
|
|||
<div class="header-Outro">
|
||||
<div class="row content single-Col">
|
||||
<h1>Bandwidth Stats</h1>
|
||||
<h2 class="subtitle">John James Cowperthwaite cares that I care about this</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content misc-page single-Col txt-Center" style="padding-top: 20px;">
|
||||
<div class="row">
|
||||
<div class="col col-100">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Views</th>
|
||||
<th>Hits</th>
|
||||
<th>Bandwidth</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
|
||||
<% @monthly_stats.each do |monthly_stat| %>
|
||||
<tr>
|
||||
<td><%= monthly_stat[:views].to_comma_separated %></td>
|
||||
<td><%= monthly_stat[:hits].to_comma_separated %></td>
|
||||
<td><%= monthly_stat[:bandwidth].to_bytes_pretty %></td>
|
||||
<td><%= monthly_stat[:date].strftime('%Y %B') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
Loading…
Add table
Reference in a new issue