Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
OpenEdx
configuration
Commits
284bb743
Commit
284bb743
authored
Dec 04, 2015
by
Edward Zarecor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renaming file
parent
c77d8ac7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
99 deletions
+11
-99
playbooks/callback_plugins/datadog_tasks_timing.py
+11
-9
playbooks/callback_plugins/tasks_timing.py
+0
-90
No files found.
playbooks/callback_plugins/datadog_tasks_timing.py
View file @
284bb743
...
...
@@ -24,14 +24,6 @@ class CallbackModule(object):
def
__init__
(
self
):
self
.
stats
=
{}
self
.
current_task
=
None
self
.
datadog_api_key
=
os
.
getenv
(
'DATADOG_API_KEY'
)
self
.
datadog_app_key
=
os
.
getenv
(
'DATADOG_APP_KEY'
)
self
.
datadog_api_initialized
=
False
if
self
.
datadog_api_key
and
self
.
datadog_app_key
:
datadog
.
initialize
(
api_key
=
datadog_api_key
,
app_key
=
datadog_app_key
)
self
.
datadog_api_initialized
=
True
def
playbook_on_task_start
(
self
,
name
,
is_conditional
):
...
...
@@ -60,8 +52,18 @@ class CallbackModule(object):
# Sort the tasks by their running time
results
=
sorted
(
self
.
stats
.
items
(),
key
=
lambda
value
:
value
[
1
][
1
],
reverse
=
True
)
datadog_api_key
=
os
.
getenv
(
'DATADOG_API_KEY'
)
datadog_app_key
=
os
.
getenv
(
'DATADOG_APP_KEY'
)
datadog_api_initialized
=
True
if
datadog_api_key
and
datadog_app_key
:
datadog
.
initialize
(
api_key
=
datadog_api_key
,
app_key
=
datadog_app_key
)
else
:
datadog_api_initialized
=
False
# send the metric to datadog
if
self
.
datadog_api_initialized
:
if
datadog_api_initialized
:
for
name
,
points
in
results
:
datadog
.
api
.
Metric
.
send
(
metric
=
"edx.ansible.{0}.task_duration"
.
format
(
name
.
replace
(
" | "
,
"."
)
.
replace
(
" "
,
"-"
)
.
lower
()),
...
...
playbooks/callback_plugins/tasks_timing.py
deleted
100644 → 0
View file @
c77d8ac7
import
os
import
datetime
import
time
import
logging
import
datadog
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logger
=
logging
.
getLogger
(
__name__
)
"""
Originally written by 'Jharrod LaFon'
#https://github.com/jlafon/ansible-profile/blob/master/callback_plugins/profile_tasks.py
"""
class
CallbackModule
(
object
):
"""
Ansible plugin get the time of each task and total time to run the complete playbook
"""
def
__init__
(
self
):
self
.
stats
=
{}
self
.
current_task
=
None
def
playbook_on_task_start
(
self
,
name
,
is_conditional
):
"""
Logs the start of each task
"""
if
self
.
current_task
is
not
None
:
# Record the running time of the last executed task
self
.
stats
[
self
.
current_task
]
=
(
time
.
time
(),
time
.
time
()
-
self
.
stats
[
self
.
current_task
])
# Record the start time of the current task
self
.
current_task
=
name
self
.
stats
[
self
.
current_task
]
=
time
.
time
()
def
playbook_on_stats
(
self
,
stats
):
"""
Prints the timing of each task and total time to run the complete playbook
"""
# Record the timing of the very last task, we use it here, because we don't have stop task function by default
if
self
.
current_task
is
not
None
:
self
.
stats
[
self
.
current_task
]
=
(
time
.
time
(),
time
.
time
()
-
self
.
stats
[
self
.
current_task
])
# Sort the tasks by their running time
results
=
sorted
(
self
.
stats
.
items
(),
key
=
lambda
value
:
value
[
1
][
1
],
reverse
=
True
)
datadog_api_key
=
os
.
getenv
(
'DATADOG_API_KEY'
)
datadog_app_key
=
os
.
getenv
(
'DATADOG_APP_KEY'
)
datadog_api_initialized
=
True
if
datadog_api_key
and
datadog_app_key
:
datadog
.
initialize
(
api_key
=
datadog_api_key
,
app_key
=
datadog_app_key
)
else
:
datadog_api_initialized
=
False
# send the metric to datadog
if
datadog_api_initialized
:
for
name
,
points
in
results
:
datadog
.
api
.
Metric
.
send
(
metric
=
"edx.ansible.{0}.task_duration"
.
format
(
name
.
replace
(
" | "
,
"."
)
.
replace
(
" "
,
"-"
)
.
lower
()),
date_happened
=
[
0
],
points
=
points
[
1
],
)
# Log the time of each task
for
name
,
elapsed
in
results
:
logger
.
info
(
"{0:-<80}{1:->8}"
.
format
(
'{0} '
.
format
(
name
),
' {0:.02f}s'
.
format
(
elapsed
[
1
]),
)
)
# Total time to run the complete playbook
total_seconds
=
sum
([
x
[
1
][
1
]
for
x
in
self
.
stats
.
items
()])
logger
.
info
(
"
\n
Playbook finished: {0}, {1} total tasks. {2} elapsed.
\n
"
.
format
(
time
.
asctime
(),
len
(
self
.
stats
.
items
()),
datetime
.
timedelta
(
seconds
=
(
int
(
total_seconds
)))
)
)
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