Dashboard memory warning

This commit is contained in:
Neil Lalonde 2013-03-22 15:47:25 -04:00
parent 9c38c13ac5
commit aa6e87c5c1
4 changed files with 42 additions and 1 deletions

View File

@ -1,3 +1,5 @@
require_dependency 'mem_info'
class AdminDashboardData
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails']
@ -9,7 +11,7 @@ class AdminDashboardData
def as_json
@json ||= {
reports: REPORTS.map { |type| Report.find(type) },
problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check].compact
problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check, ram_check].compact
}.merge(
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
)
@ -35,4 +37,8 @@ class AdminDashboardData
def clockwork_check
I18n.t('dashboard.clockwork_warning') unless Jobs::ClockworkHeartbeat.is_clockwork_running?
end
def ram_check
I18n.t('dashboard.memory_warning') if MemInfo.new.mem_total and MemInfo.new.mem_total < 1_000_000
end
end

View File

@ -286,6 +286,7 @@ en:
gc_warning: 'Your server is using default ruby garbage collection parameters, which will not give you the best performance. Read this topic on performance tuning: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork is not running. Ensure that a clockwork process is always running so that important jobs can be scheduled. <a href="https://github.com/tomykaira/clockwork">Learn about clockwork here</a>.'
sidekiq_warning: 'Sidekiq is not running. Many tasks, like sending emails, are executed asynchronously by sidekiq. Please ensure at least one sidekiq process is running. <a href="https://github.com/mperham/sidekiq">Learn about Sidekiq here</a>.'
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'
site_settings:
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"

15
lib/mem_info.rb Normal file
View File

@ -0,0 +1,15 @@
class MemInfo
# Total memory in kb. Only works on systems with /proc/meminfo.
# Returns nil if it cannot be determined.
def mem_total
@mem_total ||= begin
if s = `grep MemTotal /proc/meminfo`
/(\d+)/.match(s)[0].try(:to_i)
else
nil
end
end
end
end

View File

@ -102,4 +102,23 @@ describe AdminDashboardData do
end
end
describe 'ram_check' do
subject { AdminDashboardData.new.ram_check }
it 'returns nil when total ram is 1 GB' do
MemInfo.any_instance.stubs(:mem_total).returns(1025272)
subject.should be_nil
end
it 'returns nil when total ram cannot be determined' do
MemInfo.any_instance.stubs(:mem_total).returns(nil)
subject.should be_nil
end
it 'returns a string when total ram is less than 1 GB' do
MemInfo.any_instance.stubs(:mem_total).returns(512636)
subject.should_not be_nil
end
end
end