From a885313e752bdd5db01f3f9b6fe6304705675441 Mon Sep 17 00:00:00 2001 From: Manson Wang Date: Wed, 30 Oct 2013 18:23:46 +0800 Subject: [PATCH] Dashboard with HighChart --- Gemfile | 4 + .../admin/dashboards_controller.rb | 32 +- app/controllers/pages_controller.rb | 6 +- .../admin/dashboards/_server_loading.erb | 400 ++++++++++++++++++ .../admin/dashboards/_traffic_loading.erb | 62 +++ app/views/admin/dashboards/index.html.erb | 35 +- config/mongoid.yml | 4 +- config/routes.rb | 4 + .../front_end/bulletins_controller.rb | 5 +- .../front_end/page_contexts_controller.rb | 3 +- 10 files changed, 540 insertions(+), 15 deletions(-) create mode 100644 app/views/admin/dashboards/_server_loading.erb create mode 100644 app/views/admin/dashboards/_traffic_loading.erb diff --git a/Gemfile b/Gemfile index 933772f0..a1c2c94e 100644 --- a/Gemfile +++ b/Gemfile @@ -71,6 +71,10 @@ gem 'redis-search' gem 'syslog-logger' gem "recaptcha", :require => "recaptcha/rails" +gem 'puma' +gem 'request-log-analyzer' +gem 'usagewatch' + # Gems used only for assets and not required # in production environments by default. group :assets do diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index c0acaf8d..e7fd745e 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -1,3 +1,6 @@ +require 'fileutils' +require 'usagewatch' + class Admin::DashboardsController < OrbitBackendController open_for_visitor @@ -8,7 +11,7 @@ class Admin::DashboardsController < OrbitBackendController check_backend_openness @module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link') @recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link') - @most_visited = get_most_visited('bulletin', 'page_context') + @most_visited = get_most_visited('bulletin', 'page_context','page') end def reload_all_content @@ -19,7 +22,7 @@ class Admin::DashboardsController < OrbitBackendController end def reload_most_visited - @most_visited = get_most_visited('bulletin', 'page_context') + @most_visited = get_most_visited('bulletin', 'page_context','page') respond_to do |format| format.js { render 'reload', locals: {div_id: 'most_visited'} } end @@ -32,6 +35,31 @@ class Admin::DashboardsController < OrbitBackendController end end + def get_cpu_usage + @usw = Usagewatch + render :js => @usw.uw_cpuused.to_s + end + + def get_mem_usage + @usw = Usagewatch + render :js => @usw.uw_memused.to_s + end + + def get_disk_usage + @usw = Usagewatch + render :json => @usw.uw_diskused_perc.to_s + end + + def get_month_traffic + result = [] + (0..31).each do |i| + the_day = i.day.ago + visits = Impression.where( created_at: {'$gte' => the_day.beginning_of_day, '$lte' => the_day.end_of_day}).count + result.push({the_day.strftime("%b-%d")=>visits}) + end + render :js => result.to_json + end + protected def get_module_app_count(*args) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 430bc408..0accef0b 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -8,7 +8,8 @@ class PagesController < ApplicationController @item = Page.find_by_name('home') if @item - delayed_impressionist(@item) + # delayed_impressionist(@item) + impressionist(@item) if params[:edit] if request.referer && request.referer.ends_with?("admin/items") redirect_to admin_page_url(@item) @@ -29,7 +30,8 @@ class PagesController < ApplicationController @item = Item.first(:conditions => {:path => params[:page_name]}) if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) - delayed_impressionist(@item) + # delayed_impressionist(@item) + impressionist(@item) case @item.class.to_s when 'Page' if params[:clicked_field_name] diff --git a/app/views/admin/dashboards/_server_loading.erb b/app/views/admin/dashboards/_server_loading.erb new file mode 100644 index 00000000..6ff3fa00 --- /dev/null +++ b/app/views/admin/dashboards/_server_loading.erb @@ -0,0 +1,400 @@ +
+

+ + + Server Loading +

+
+
+
+
+
+
+ \ No newline at end of file diff --git a/app/views/admin/dashboards/_traffic_loading.erb b/app/views/admin/dashboards/_traffic_loading.erb new file mode 100644 index 00000000..0dee91c6 --- /dev/null +++ b/app/views/admin/dashboards/_traffic_loading.erb @@ -0,0 +1,62 @@ +
+

+ + + Traffic Loading +

+
+
+
+
+ \ No newline at end of file diff --git a/app/views/admin/dashboards/index.html.erb b/app/views/admin/dashboards/index.html.erb index 236f9c70..1d700791 100644 --- a/app/views/admin/dashboards/index.html.erb +++ b/app/views/admin/dashboards/index.html.erb @@ -1,5 +1,33 @@ + + + + + + + +
+
+
+
+ <%= render 'server_loading' %> +
+
+
+
+ <%= render 'traffic' %> +
+
+
+
+
+
+ <%= render 'traffic_loading' %> +
+
+
+
@@ -14,11 +42,6 @@

-
-
- <%= render 'traffic' %> -
-
<%= render 'most_visited' %> @@ -26,4 +49,4 @@
-
+ \ No newline at end of file diff --git a/config/mongoid.yml b/config/mongoid.yml index 49a7167c..1b3b0585 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -8,7 +8,7 @@ defaults: &defaults development: <<: *defaults - database: test_site + database: test_site_new @@ -24,4 +24,4 @@ production: # password: <%= ENV['MONGOID_PASSWORD'] %> # database: <%= ENV['MONGOID_DATABASE'] %> <<: *defaults - database: test_site + database: test_site_new diff --git a/config/routes.rb b/config/routes.rb index 6d1e40c1..f15898c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,6 +67,10 @@ Orbit::Application.routes.draw do get 'reload_all_content' get 'reload_most_visited' get 'reload_recent_update' + get 'get_cpu_usage' + get 'get_mem_usage' + get 'get_disk_usage' + get 'get_month_traffic' end end resources :designs do diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index 07ba9fa2..407a5e44 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -53,7 +53,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController else @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) end - delayed_impressionist(@tag) if @tag + # delayed_impressionist(@tag) if @tag end end @@ -66,7 +66,8 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController @bulletin = Bulletin.all.can_display.where(_id: params[:id]).first if @bulletin and !@bulletin.disable? and !@bulletin.is_rejected if @bulletin.enabled_for_lang(I18n.locale.to_s) - delayed_impressionist(@bulletin) + # delayed_impressionist(@bulletin) + impressionist(@bulletin) else render :text => "
#{t('sys.can_not_display_due_to_no_context')}
".html_safe end diff --git a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb index 90a079e4..a9f5a462 100644 --- a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb +++ b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb @@ -8,7 +8,8 @@ class Panel::PageContent::FrontEnd::PageContextsController < OrbitWidgetControll def index # @page_context = PageContext.where("page_id" => params[:page_id], :archived => false) @page_context = PageContext.first(conditions: { page_id: params[:page_id], :archived => false }) - delayed_impressionist(@page_context) + # delayed_impressionist(@page_context) + impressionist(@page_context) respond_to do |format| format.html # index.html.erb