Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e09b3626
Commit
e09b3626
authored
May 15, 2017
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add waffle switch to enable dynamically.
parent
b16e75bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
openedx/core/djangoapps/monitoring_utils/middleware.py
+18
-7
No files found.
openedx/core/djangoapps/monitoring_utils/middleware.py
View file @
e09b3626
...
...
@@ -2,7 +2,7 @@
Middleware for handling the storage, aggregation, and reporting of custom
metrics for monitoring.
At this time, the custom metrics can only reported to New Relic.
At this time, the custom metrics can only
be
reported to New Relic.
This middleware will only call on the newrelic agent if there are any metrics
to report for this request, so it will not incur any processing overhead for
...
...
@@ -19,8 +19,11 @@ except ImportError:
import
psutil
import
request_cache
from
openedx.core.djangolib.waffle_utils
import
WaffleSwitchPlus
REQUEST_CACHE_KEY
=
'monitoring_custom_metrics'
WAFFLE_NAMESPACE
=
'monitoring_utils'
class
MonitoringCustomMetrics
(
object
):
...
...
@@ -82,15 +85,17 @@ class MonitoringMemoryMiddleware(object):
memory_data_key
=
u'memory_data'
def
process_request
(
self
,
request
):
log_prefix
=
self
.
_log_prefix
(
u"Before"
,
request
)
self
.
_cache
[
self
.
memory_data_key
]
=
self
.
_memory_data
(
log_prefix
)
if
self
.
_is_enabled
():
log_prefix
=
self
.
_log_prefix
(
u"Before"
,
request
)
self
.
_cache
[
self
.
memory_data_key
]
=
self
.
_memory_data
(
log_prefix
)
def
process_response
(
self
,
request
,
response
):
log_prefix
=
self
.
_log_prefix
(
u"After"
,
request
)
new_memory_data
=
self
.
_memory_data
(
log_prefix
)
if
self
.
_is_enabled
():
log_prefix
=
self
.
_log_prefix
(
u"After"
,
request
)
new_memory_data
=
self
.
_memory_data
(
log_prefix
)
log_prefix
=
self
.
_log_prefix
(
u"Diff"
,
request
)
self
.
_diff_memory_data
(
log_prefix
,
new_memory_data
,
self
.
_cache
.
get
(
self
.
memory_data_key
))
log_prefix
=
self
.
_log_prefix
(
u"Diff"
,
request
)
self
.
_log
_diff_memory_data
(
log_prefix
,
new_memory_data
,
self
.
_cache
.
get
(
self
.
memory_data_key
))
return
response
@property
...
...
@@ -153,3 +158,9 @@ class MonitoringMemoryMiddleware(object):
_process_rss
(
new_memory_data
)
-
_process_rss
(
old_memory_data
),
_process_vms
(
new_memory_data
)
-
_process_vms
(
old_memory_data
),
)
def
_is_enabled
(
self
):
"""
Returns whether this middleware is enabled.
"""
return
WaffleSwitchPlus
(
namespace
=
WAFFLE_NAMESPACE
)
.
is_enabled
(
u'enable_memory_middleware'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment