mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
Dashboard memory warning
This commit is contained in:
parent
9c38c13ac5
commit
aa6e87c5c1
@ -1,3 +1,5 @@
|
|||||||
|
require_dependency 'mem_info'
|
||||||
|
|
||||||
class AdminDashboardData
|
class AdminDashboardData
|
||||||
|
|
||||||
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails']
|
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails']
|
||||||
@ -9,7 +11,7 @@ class AdminDashboardData
|
|||||||
def as_json
|
def as_json
|
||||||
@json ||= {
|
@json ||= {
|
||||||
reports: REPORTS.map { |type| Report.find(type) },
|
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(
|
}.merge(
|
||||||
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
|
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
|
||||||
)
|
)
|
||||||
@ -35,4 +37,8 @@ class AdminDashboardData
|
|||||||
def clockwork_check
|
def clockwork_check
|
||||||
I18n.t('dashboard.clockwork_warning') unless Jobs::ClockworkHeartbeat.is_clockwork_running?
|
I18n.t('dashboard.clockwork_warning') unless Jobs::ClockworkHeartbeat.is_clockwork_running?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ram_check
|
||||||
|
I18n.t('dashboard.memory_warning') if MemInfo.new.mem_total and MemInfo.new.mem_total < 1_000_000
|
||||||
|
end
|
||||||
end
|
end
|
@ -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>.'
|
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>.'
|
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>.'
|
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:
|
site_settings:
|
||||||
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
||||||
|
15
lib/mem_info.rb
Normal file
15
lib/mem_info.rb
Normal 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
|
@ -102,4 +102,23 @@ describe AdminDashboardData do
|
|||||||
end
|
end
|
||||||
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
|
end
|
Loading…
x
Reference in New Issue
Block a user