2013-03-22 15:47:25 -04:00
|
|
|
require_dependency 'mem_info'
|
|
|
|
|
2013-03-19 23:18:00 -04:00
|
|
|
class AdminDashboardData
|
|
|
|
|
2013-04-16 16:56:18 -04:00
|
|
|
REPORTS = [
|
|
|
|
'visits',
|
|
|
|
'signups',
|
|
|
|
'topics',
|
|
|
|
'posts',
|
|
|
|
'flags',
|
|
|
|
'users_by_trust_level',
|
|
|
|
'likes',
|
2013-04-18 14:27:22 -04:00
|
|
|
'bookmarks',
|
|
|
|
'favorites',
|
2013-04-16 16:56:18 -04:00
|
|
|
'emails',
|
|
|
|
'user_to_user_private_messages',
|
|
|
|
'system_private_messages',
|
|
|
|
'moderator_warning_private_messages',
|
|
|
|
'notify_moderators_private_messages',
|
|
|
|
'notify_user_private_messages'
|
|
|
|
]
|
2013-03-19 23:18:00 -04:00
|
|
|
|
2013-04-25 17:53:31 -04:00
|
|
|
def problems
|
|
|
|
[ rails_env_check,
|
|
|
|
host_names_check,
|
|
|
|
gc_checks,
|
|
|
|
sidekiq_check || queue_size_check || clockwork_check,
|
|
|
|
ram_check,
|
|
|
|
facebook_config_check,
|
|
|
|
twitter_config_check,
|
|
|
|
github_config_check,
|
2013-06-19 16:11:11 -04:00
|
|
|
s3_config_check,
|
2013-06-19 16:36:56 -04:00
|
|
|
image_magick_check,
|
2013-04-25 17:53:31 -04:00
|
|
|
failing_emails_check,
|
|
|
|
default_logo_check,
|
|
|
|
contact_email_check,
|
2013-06-10 03:08:06 -04:00
|
|
|
send_consumer_email_check,
|
2013-04-25 17:53:31 -04:00
|
|
|
title_check ].compact
|
|
|
|
end
|
|
|
|
|
2013-03-29 15:48:26 -04:00
|
|
|
def self.fetch_all
|
2013-03-19 23:18:00 -04:00
|
|
|
AdminDashboardData.new
|
|
|
|
end
|
|
|
|
|
2013-03-29 15:48:26 -04:00
|
|
|
def self.fetch_problems
|
|
|
|
AdminDashboardData.new.problems
|
|
|
|
end
|
|
|
|
|
2013-03-19 23:18:00 -04:00
|
|
|
def as_json
|
|
|
|
@json ||= {
|
2013-05-14 16:17:17 -04:00
|
|
|
reports: REPORTS.map { |type| Report.find(type).as_json },
|
2013-03-29 02:29:58 -04:00
|
|
|
admins: User.admins.count,
|
2013-05-01 18:12:02 -04:00
|
|
|
moderators: User.moderators.count,
|
2013-06-04 11:53:19 -04:00
|
|
|
blocked: User.blocked.count,
|
2013-05-14 16:17:17 -04:00
|
|
|
top_referrers: IncomingLinksReport.find('top_referrers').as_json,
|
|
|
|
top_traffic_sources: IncomingLinksReport.find('top_traffic_sources').as_json,
|
|
|
|
top_referred_topics: IncomingLinksReport.find('top_referred_topics').as_json
|
2013-03-19 23:18:00 -04:00
|
|
|
}.merge(
|
|
|
|
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rails_env_check
|
|
|
|
I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env == 'production'
|
|
|
|
end
|
2013-03-20 15:38:28 -04:00
|
|
|
|
|
|
|
def host_names_check
|
|
|
|
I18n.t("dashboard.host_names_warning") if ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
|
|
|
|
end
|
2013-03-20 16:16:23 -04:00
|
|
|
|
|
|
|
def gc_checks
|
|
|
|
I18n.t("dashboard.gc_warning") if ENV['RUBY_GC_MALLOC_LIMIT'].nil?
|
|
|
|
end
|
2013-03-21 16:51:19 -04:00
|
|
|
|
2013-03-22 11:35:32 -04: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-21 16:51:19 -04:00
|
|
|
def clockwork_check
|
|
|
|
I18n.t('dashboard.clockwork_warning') unless Jobs::ClockworkHeartbeat.is_clockwork_running?
|
|
|
|
end
|
2013-03-22 15:47:25 -04:00
|
|
|
|
2013-04-22 13:02:24 -04:00
|
|
|
def queue_size_check
|
|
|
|
queue_size = Jobs.queued
|
|
|
|
I18n.t('dashboard.queue_size_warning', queue_size: queue_size) unless queue_size < 100
|
|
|
|
end
|
|
|
|
|
2013-03-22 15:47:25 -04: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 13:31:00 -04:00
|
|
|
|
|
|
|
def facebook_config_check
|
2013-06-19 16:11:11 -04:00
|
|
|
I18n.t('dashboard.facebook_config_warning') if SiteSetting.enable_facebook_logins and (SiteSetting.facebook_app_id.blank? or SiteSetting.facebook_app_secret.blank?)
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def twitter_config_check
|
2013-06-19 16:11:11 -04: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 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def github_config_check
|
2013-06-19 16:11:11 -04: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
|
|
|
|
I18n.t('dashboard.s3_config_warning') if SiteSetting.enable_s3_uploads and (SiteSetting.s3_access_key_id.blank? or SiteSetting.s3_secret_access_key.blank? or SiteSetting.s3_upload_bucket.blank?)
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
2013-04-22 13:37:16 -04:00
|
|
|
|
2013-06-19 16:36:56 -04:00
|
|
|
def image_magick_check
|
2013-06-20 21:42:18 -04:00
|
|
|
I18n.t('dashboard.image_magick_warning') if SiteSetting.create_thumbnails and !system("command -v convert >/dev/null;")
|
2013-06-19 16:36:56 -04:00
|
|
|
end
|
|
|
|
|
2013-04-22 13:37:16 -04: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 15:38:48 -04:00
|
|
|
|
|
|
|
def default_logo_check
|
2013-06-05 16:59:19 -04: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 15:38:48 -04:00
|
|
|
I18n.t('dashboard.default_logo_warning')
|
|
|
|
end
|
|
|
|
end
|
2013-04-24 11:15:37 -04: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 17:53:31 -04:00
|
|
|
|
|
|
|
def title_check
|
|
|
|
I18n.t('dashboard.title_nag') if SiteSetting.title == SiteSetting.defaults[:title]
|
|
|
|
end
|
2013-05-01 18:12:02 -04:00
|
|
|
|
2013-06-10 03:08:06 -04:00
|
|
|
def send_consumer_email_check
|
|
|
|
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 13:54:49 -04:00
|
|
|
end
|
|
|
|
|
2013-06-19 16:11:11 -04:00
|
|
|
end
|