FEATURE: daily performance reports

This commit is contained in:
Sam 2015-06-26 13:33:09 +10:00
parent c8ec1ad2be
commit 542e796fb0
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,48 @@
module Jobs
class DailyPerformanceReport < Jobs::Scheduled
every 1.day
per_host
def execute(args)
if SiteSetting.daily_performance_report
result = `ruby #{Rails.root}/script/nginx_analyze.rb --limit 1440`
if result.strip.empty?
result = "Report is only available in latest image, please run: \n\n cd /var/discourse && ./launcher rebuild app"
end
report_data = "```text\n#{result}\n```"
PostCreator.create(Discourse.system_user,
topic_id: performance_topic_id,
raw: report_data,
skip_validations: true)
end
end
def performance_topic_id
if SiteSetting.performance_report_topic_id > 0
topic = Topic.find_by(id: SiteSetting.performance_report_topic_id)
return topic.id if topic
end
staff_category = Category.find_by(id: SiteSetting.staff_category_id)
raise StandardError, "Staff category was not found" unless staff_category
post = PostCreator.create(Discourse.system_user,
raw: I18n.t('performance_report.initial_post_raw'),
category: staff_category.name,
title: I18n.t('performance_report.initial_topic_title'),
skip_validations: true)
unless post && post.topic_id
raise StandardError, "Could not create or retrieve performance report topic id"
end
SiteSetting.performance_report_topic_id = post.topic_id
end
end
end

View File

@ -1119,6 +1119,9 @@ en:
enable_mobile_theme: "Mobile devices use a mobile-friendly theme, with the ability to switch to the full site. Disable this if you want to use a custom stylesheet that is fully responsive."
dominating_topic_minimum_percent: "What percentage of posts a user has to make in a topic before being reminded about overly dominating a topic."
daily_performance_report: "Analyze NGINX logs daily and post a Staff Only topic with details"
suppress_uncategorized_badge: "Don't show the badge for uncategorized topics in topic lists."
global_notice: "Display an URGENT, EMERGENCY global banner notice to all visitors, change to blank to hide it (HTML allowed)."
@ -2503,3 +2506,7 @@ en:
discourse_hub:
access_token_problem: "Tell an admin: Please update the site settings to include the correct discourse_org_access_key."
performance_report:
initial_post_raw: This topic includes daily performance reports for your site.
initial_topic_title: Website performance reports

View File

@ -870,6 +870,9 @@ uncategorized:
sequential_replies_threshold: 2
dominating_topic_minimum_percent: 20
# Reporting
daily_performance_report: false
global_notice:
default: ""
client: true
@ -881,13 +884,19 @@ uncategorized:
lounge_category_id:
default: -1
hidden: true
meta_category_id:
default: -1
hidden: true
staff_category_id:
default: -1
hidden: true
performance_report_topic_id:
default: -1
hidden: true
notify_about_flags_after: 48
enable_cdn_js_debugging: false