2013-03-22 14:47:25 -05:00
|
|
|
require_dependency 'mem_info'
|
|
|
|
|
2013-03-19 22:18:00 -05:00
|
|
|
class AdminDashboardData
|
|
|
|
|
2013-04-16 15:56:18 -05:00
|
|
|
REPORTS = [
|
|
|
|
'visits',
|
|
|
|
'signups',
|
|
|
|
'topics',
|
|
|
|
'posts',
|
2015-06-22 12:46:51 -05:00
|
|
|
'time_to_first_response',
|
|
|
|
'topics_with_no_response',
|
2013-04-16 15:56:18 -05:00
|
|
|
'flags',
|
|
|
|
'users_by_trust_level',
|
|
|
|
'likes',
|
2013-04-18 13:27:22 -05:00
|
|
|
'bookmarks',
|
2013-04-16 15:56:18 -05:00
|
|
|
'emails',
|
|
|
|
'user_to_user_private_messages',
|
|
|
|
'system_private_messages',
|
|
|
|
'moderator_warning_private_messages',
|
|
|
|
'notify_moderators_private_messages',
|
2015-02-05 21:39:04 -06:00
|
|
|
'notify_user_private_messages',
|
|
|
|
'page_view_total_reqs'
|
2015-02-04 23:08:52 -06:00
|
|
|
] + ApplicationRequest.req_types.keys.map{|r| r + "_reqs"}
|
2013-03-19 22:18:00 -05:00
|
|
|
|
2013-04-25 16:53:31 -05:00
|
|
|
def problems
|
|
|
|
[ rails_env_check,
|
2013-10-24 17:22:47 -05:00
|
|
|
ruby_version_check,
|
2013-04-25 16:53:31 -05:00
|
|
|
host_names_check,
|
|
|
|
gc_checks,
|
2015-04-15 14:52:28 -05:00
|
|
|
sidekiq_check,
|
2013-04-25 16:53:31 -05:00
|
|
|
ram_check,
|
2014-05-21 17:19:40 -05:00
|
|
|
google_oauth2_config_check,
|
2013-04-25 16:53:31 -05:00
|
|
|
facebook_config_check,
|
|
|
|
twitter_config_check,
|
|
|
|
github_config_check,
|
2013-06-19 15:11:11 -05:00
|
|
|
s3_config_check,
|
2013-06-19 15:36:56 -05:00
|
|
|
image_magick_check,
|
2013-04-25 16:53:31 -05:00
|
|
|
failing_emails_check,
|
|
|
|
default_logo_check,
|
|
|
|
contact_email_check,
|
2013-06-10 02:08:06 -05:00
|
|
|
send_consumer_email_check,
|
2013-06-25 14:05:16 -05:00
|
|
|
title_check,
|
2013-09-11 15:32:49 -05:00
|
|
|
site_description_check,
|
2013-09-06 02:28:37 -05:00
|
|
|
site_contact_username_check,
|
2015-05-11 17:27:25 -05:00
|
|
|
notification_email_check
|
2013-11-15 09:46:41 -06:00
|
|
|
].compact
|
2013-04-25 16:53:31 -05:00
|
|
|
end
|
|
|
|
|
2014-05-21 17:19:40 -05:00
|
|
|
|
2013-08-02 17:31:25 -05:00
|
|
|
def self.fetch_stats
|
2013-03-19 22:18:00 -05:00
|
|
|
AdminDashboardData.new
|
|
|
|
end
|
2013-08-02 17:31:25 -05:00
|
|
|
def self.fetch_cached_stats
|
|
|
|
# The DashboardStats job is responsible for generating and caching this.
|
|
|
|
stats = $redis.get(stats_cache_key)
|
|
|
|
stats ? JSON.parse(stats) : nil
|
|
|
|
end
|
|
|
|
def self.stats_cache_key
|
|
|
|
'dash-stats'
|
|
|
|
end
|
2013-03-19 22:18:00 -05:00
|
|
|
|
2013-03-29 14:48:26 -05:00
|
|
|
def self.fetch_problems
|
|
|
|
AdminDashboardData.new.problems
|
|
|
|
end
|
|
|
|
|
2014-08-20 13:14:19 -05:00
|
|
|
def as_json(_options = nil)
|
2013-03-19 22:18:00 -05:00
|
|
|
@json ||= {
|
2013-05-14 15:17:17 -05:00
|
|
|
reports: REPORTS.map { |type| Report.find(type).as_json },
|
2013-03-29 01:29:58 -05:00
|
|
|
admins: User.admins.count,
|
2013-05-01 17:12:02 -05:00
|
|
|
moderators: User.moderators.count,
|
2013-11-07 12:53:32 -06:00
|
|
|
suspended: User.suspended.count,
|
2013-06-04 10:53:19 -05:00
|
|
|
blocked: User.blocked.count,
|
2013-05-14 15:17:17 -05:00
|
|
|
top_referrers: IncomingLinksReport.find('top_referrers').as_json,
|
|
|
|
top_traffic_sources: IncomingLinksReport.find('top_traffic_sources').as_json,
|
2013-08-02 17:31:25 -05:00
|
|
|
top_referred_topics: IncomingLinksReport.find('top_referred_topics').as_json,
|
|
|
|
updated_at: Time.zone.now.as_json
|
2013-07-30 11:11:51 -05:00
|
|
|
}
|
2013-03-19 22:18:00 -05:00
|
|
|
end
|
|
|
|
|
2013-08-02 17:31:25 -05:00
|
|
|
def self.recalculate_interval
|
2013-08-07 12:25:05 -05:00
|
|
|
# Could be configurable, multisite need to support it.
|
2013-08-02 17:31:25 -05:00
|
|
|
30 # minutes
|
|
|
|
end
|
|
|
|
|
2013-03-19 22:18:00 -05:00
|
|
|
def rails_env_check
|
2014-08-18 01:42:48 -05:00
|
|
|
I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env.production?
|
2013-03-19 22:18:00 -05:00
|
|
|
end
|
2013-03-20 14:38:28 -05:00
|
|
|
|
|
|
|
def host_names_check
|
|
|
|
I18n.t("dashboard.host_names_warning") if ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
|
|
|
|
end
|
2013-03-20 15:16:23 -05:00
|
|
|
|
|
|
|
def gc_checks
|
|
|
|
I18n.t("dashboard.gc_warning") if ENV['RUBY_GC_MALLOC_LIMIT'].nil?
|
|
|
|
end
|
2013-03-21 15:51:19 -05:00
|
|
|
|
2013-03-22 10:35:32 -05:00
|
|
|
def sidekiq_check
|
|
|
|
last_job_performed_at = Jobs.last_job_performed_at
|
|
|
|
I18n.t('dashboard.sidekiq_warning') if Jobs.queued > 0 and (last_job_performed_at.nil? or last_job_performed_at < 2.minutes.ago)
|
|
|
|
end
|
|
|
|
|
2013-03-22 14:47:25 -05:00
|
|
|
def ram_check
|
|
|
|
I18n.t('dashboard.memory_warning') if MemInfo.new.mem_total and MemInfo.new.mem_total < 1_000_000
|
|
|
|
end
|
2013-03-29 12:31:00 -05:00
|
|
|
|
2014-05-21 17:19:40 -05:00
|
|
|
def google_oauth2_config_check
|
2014-05-21 18:11:02 -05:00
|
|
|
I18n.t('dashboard.google_oauth2_config_warning') if SiteSetting.enable_google_oauth2_logins && (SiteSetting.google_oauth2_client_id.blank? || SiteSetting.google_oauth2_client_secret.blank?)
|
2014-05-21 17:19:40 -05:00
|
|
|
end
|
|
|
|
|
2013-03-29 12:31:00 -05:00
|
|
|
def facebook_config_check
|
2014-05-21 17:19:40 -05:00
|
|
|
I18n.t('dashboard.facebook_config_warning') if SiteSetting.enable_facebook_logins && (SiteSetting.facebook_app_id.blank? || SiteSetting.facebook_app_secret.blank?)
|
2013-03-29 12:31:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def twitter_config_check
|
2013-06-19 15:11:11 -05:00
|
|
|
I18n.t('dashboard.twitter_config_warning') if SiteSetting.enable_twitter_logins and (SiteSetting.twitter_consumer_key.blank? or SiteSetting.twitter_consumer_secret.blank?)
|
2013-03-29 12:31:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def github_config_check
|
2013-06-19 15:11:11 -05:00
|
|
|
I18n.t('dashboard.github_config_warning') if SiteSetting.enable_github_logins and (SiteSetting.github_client_id.blank? or SiteSetting.github_client_secret.blank?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def s3_config_check
|
2014-07-05 17:16:13 -05:00
|
|
|
bad_keys = (SiteSetting.s3_access_key_id.blank? or SiteSetting.s3_secret_access_key.blank?) and !SiteSetting.s3_use_iam_profile
|
|
|
|
|
|
|
|
return I18n.t('dashboard.s3_config_warning') if SiteSetting.enable_s3_uploads and (bad_keys or SiteSetting.s3_upload_bucket.blank?)
|
|
|
|
return I18n.t('dashboard.s3_backup_config_warning') if SiteSetting.enable_s3_backups and (bad_keys or SiteSetting.s3_backup_bucket.blank?)
|
2014-03-17 14:56:59 -05:00
|
|
|
nil
|
2013-03-29 12:31:00 -05:00
|
|
|
end
|
2013-04-22 12:37:16 -05:00
|
|
|
|
2013-06-19 15:36:56 -05:00
|
|
|
def image_magick_check
|
2013-06-20 20:42:18 -05:00
|
|
|
I18n.t('dashboard.image_magick_warning') if SiteSetting.create_thumbnails and !system("command -v convert >/dev/null;")
|
2013-06-19 15:36:56 -05:00
|
|
|
end
|
|
|
|
|
2013-04-22 12:37:16 -05:00
|
|
|
def failing_emails_check
|
|
|
|
num_failed_jobs = Jobs.num_email_retry_jobs
|
|
|
|
I18n.t('dashboard.failing_emails_warning', num_failed_jobs: num_failed_jobs) if num_failed_jobs > 0
|
|
|
|
end
|
2013-04-22 14:38:48 -05:00
|
|
|
|
|
|
|
def default_logo_check
|
2013-06-05 15:59:19 -05:00
|
|
|
if SiteSetting.logo_url =~ /#{SiteSetting.defaults[:logo_url].split('/').last}/ or
|
|
|
|
SiteSetting.logo_small_url =~ /#{SiteSetting.defaults[:logo_small_url].split('/').last}/ or
|
|
|
|
SiteSetting.favicon_url =~ /#{SiteSetting.defaults[:favicon_url].split('/').last}/
|
2013-04-22 14:38:48 -05:00
|
|
|
I18n.t('dashboard.default_logo_warning')
|
|
|
|
end
|
|
|
|
end
|
2013-04-24 10:15:37 -05:00
|
|
|
|
|
|
|
def contact_email_check
|
|
|
|
return I18n.t('dashboard.contact_email_missing') if !SiteSetting.contact_email.present?
|
|
|
|
return I18n.t('dashboard.contact_email_invalid') if !(SiteSetting.contact_email =~ User::EMAIL)
|
|
|
|
end
|
2013-04-25 16:53:31 -05:00
|
|
|
|
|
|
|
def title_check
|
|
|
|
I18n.t('dashboard.title_nag') if SiteSetting.title == SiteSetting.defaults[:title]
|
|
|
|
end
|
2013-05-01 17:12:02 -05:00
|
|
|
|
2013-09-11 15:32:49 -05:00
|
|
|
def site_description_check
|
2013-11-15 09:46:41 -06:00
|
|
|
I18n.t('dashboard.site_description_missing') if !SiteSetting.site_description.present?
|
2013-09-11 15:32:49 -05:00
|
|
|
end
|
|
|
|
|
2013-06-10 02:08:06 -05:00
|
|
|
def send_consumer_email_check
|
2014-08-18 01:42:48 -05:00
|
|
|
I18n.t('dashboard.consumer_email_warning') if Rails.env.production? and ActionMailer::Base.smtp_settings[:address] =~ /gmail\.com|live\.com|yahoo\.com/
|
2013-05-29 12:54:49 -05:00
|
|
|
end
|
|
|
|
|
2013-09-06 02:28:37 -05:00
|
|
|
def site_contact_username_check
|
2015-01-05 10:55:03 -06:00
|
|
|
I18n.t('dashboard.site_contact_username_warning') if !SiteSetting.site_contact_username.present? || SiteSetting.site_contact_username == SiteSetting.defaults[:site_contact_username]
|
2013-06-26 09:57:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def notification_email_check
|
2015-01-05 10:55:03 -06:00
|
|
|
I18n.t('dashboard.notification_email_warning') if !SiteSetting.notification_email.present? || SiteSetting.notification_email == SiteSetting.defaults[:notification_email]
|
2013-06-26 09:57:04 -05:00
|
|
|
end
|
|
|
|
|
2013-10-24 17:22:47 -05:00
|
|
|
def ruby_version_check
|
|
|
|
I18n.t('dashboard.ruby_version_warning') if RUBY_VERSION == '2.0.0' and RUBY_PATCHLEVEL < 247
|
|
|
|
end
|
|
|
|
|
2013-06-19 15:11:11 -05:00
|
|
|
end
|