This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add basic performance statistics to phone home #3044
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,6 +402,10 @@ def profiled(*args, **kargs): | |
|
||
stats = {} | ||
|
||
# Contains the list of processes we will be monitoring | ||
# currently either 0 or 1 | ||
stats_process = [] | ||
|
||
@defer.inlineCallbacks | ||
def phone_stats_home(): | ||
logger.info("Gathering stats for reporting") | ||
|
@@ -428,6 +432,13 @@ def phone_stats_home(): | |
daily_sent_messages = yield hs.get_datastore().count_daily_sent_messages() | ||
stats["daily_sent_messages"] = daily_sent_messages | ||
|
||
if len(stats_process) > 0: | ||
stats["memory_rss"] = 0 | ||
stats["cpu_average"] = 0 | ||
for process in stats_process: | ||
stats["memory_rss"] += process.memory_info().rss | ||
stats["cpu_average"] += int(process.cpu_percent(interval=None)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to include the time since the last call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nvm |
||
|
||
logger.info("Reporting stats to matrix.org: %s" % (stats,)) | ||
try: | ||
yield hs.get_simple_http_client().put_json( | ||
|
@@ -437,10 +448,32 @@ def phone_stats_home(): | |
except Exception as e: | ||
logger.warn("Error reporting stats: %s", e) | ||
|
||
def performance_stats_init(): | ||
try: | ||
import psutil | ||
process = psutil.Process() | ||
# Ensure we can fetch both, and make the initial request for cpu_percent | ||
# so the next request will use this as the initial point. | ||
process.memory_info().rss | ||
process.cpu_percent(interval=None) | ||
logger.info("report_stats can use psutil") | ||
stats_process.append(process) | ||
except (ImportError, AttributeError): | ||
logger.warn( | ||
"report_stats enabled but psutil is not installed or incorrect version." | ||
" Disabling reporting of memory/cpu stats." | ||
" Ensuring psutil is available will help matrix.org track performance" | ||
" changes across releases." | ||
) | ||
|
||
if hs.config.report_stats: | ||
logger.info("Scheduling stats reporting for 3 hour intervals") | ||
clock.looping_call(phone_stats_home, 3 * 60 * 60 * 1000) | ||
|
||
# We need to defer this init for the cases that we daemonize | ||
# otherwise the process ID we get is that of the non-daemon process | ||
clock.call_later(0, performance_stats_init) | ||
|
||
# We wait 5 minutes to send the first set of stats as the server can | ||
# be quite busy the first few minutes | ||
clock.call_later(5 * 60, phone_stats_home) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably go in the changelog IMO, otherwise a) we'll forget to update
$NEXT_VERSION
and b) I think most people look at CHANGELOGThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably then move the historical information into the changelog and leave UPDATING as just the top level howto, referring to the changelog for any specific requirements on upgrade? Just so we don't split the idea of "upgrade notes" across multiple places.