diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb
index 678b1f9..3152c22 100644
--- a/app/controllers/admin/base_controller.rb
+++ b/app/controllers/admin/base_controller.rb
@@ -1,31 +1,32 @@
class Admin::BaseController < ApplicationController
before_action :require_admin, except: [:login]
# GET /admin
# POST /admin
def index
@client_ids = Client.pluck(:ClientId)
get_charts
+ @global_stats = GlobalStats.new.stats
render 'admin/index'
end
# GET /admin/login
def login
render 'admin/login'
end
protected
def get_charts
days_ago = params.fetch(:days_back, 7).to_i rescue 7
@job_status = ChartGenerator.job_statuses(@client_ids, days_ago)
@job_stats = ChartGenerator.job_stats(@client_ids, days_ago - 1)
end
def require_admin
return if current_user.try(:admin?)
flash[:alert] = 'You need to log in first'
redirect_to admin_login_path
end
end
diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb
index b6ad4f1..b1f74d3 100644
--- a/app/views/admin/index.html.erb
+++ b/app/views/admin/index.html.erb
@@ -1,3 +1,12 @@
-
Archiving
+
+
+ <%= bootstrap_form_tag(url: admin_path, method: :post, layout: :inline) do |f| %>
+ <%= f.select(:days_back, [['1 week', 7], ['2 weeks', 14], ['1 month', 30]], selected: params[:days_back]) %>
+ <%= f.submit 'See Stats', class: "btn btn-primary" %>
+ <% end %>
+
+
+
+
<%= render partial: 'clients/client_graphs', locals: { path: admin_path } %>
diff --git a/app/views/clients/_client_graphs.html.erb b/app/views/clients/_client_graphs.html.erb
index 1d9fda8..c5be351 100644
--- a/app/views/clients/_client_graphs.html.erb
+++ b/app/views/clients/_client_graphs.html.erb
@@ -1,18 +1,32 @@
-
+ <% if @global_stats.present? %>
+
+
+
+
Global Stats
+
+
+
+
+ <% @global_stats.each do |name, value| %>
+
+ <%= name.to_s.titleize %> |
+ <%= value %> |
+
+ <% end %>
+
+
+
+
+ <% end %>
+
-
- <%= bootstrap_form_tag(url: path, method: :post, layout: :inline) do |f| %>
- <%= f.select(:days_back, [['1 week', 7], ['2 weeks', 14], ['1 month', 30]], selected: params[:days_back]) %>
- <%= f.submit 'See Stats', class: "btn btn-primary" %>
- <% end %>
-
<%= archiving_chart('jobs_status', @job_status) %>
<%= archiving_chart('jobs_stats', @job_stats) %>
diff --git a/lib/global_stats.rb b/lib/global_stats.rb
new file mode 100644
index 0000000..b20efcd
--- /dev/null
+++ b/lib/global_stats.rb
@@ -0,0 +1,31 @@
+class GlobalStats
+ include ActionView::Helpers::NumberHelper
+
+ def stats
+ {
+ Clients: Client.count,
+ Jobs: Job.count,
+ FileSets: FileSet.count,
+ Schedules: Schedule.count,
+ TotalBytes: number_to_human_size(Job.sum(:job_bytes)),
+ TotalFiles: number_to_human(Job.sum(:job_files),
+ units: { thousand: :K, million: :M, billion: :G },
+ precision: 5, significant: false),
+ Volumes: Media.count,
+ VolumesSize: number_to_human_size(Media.sum(:VolBytes)),
+ Pools: Pool.count,
+ DatabaseSize: number_to_human_size(db_size, precision: 2, significant: false)
+ }
+ end
+
+ private
+
+ def db_size
+ ActiveRecord::Base.connection.
+ execute("select sum(data_length + index_length) from information_schema.TABLES where TABLE_SCHEMA='bacula';").
+ first.first.to_f
+ rescue
+ 0
+ end
+end
+#Database Size