-
Notifications
You must be signed in to change notification settings - Fork 130
/
query_freshness.py
31 lines (23 loc) · 1.03 KB
/
query_freshness.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#########################################################################
#Use a cronjob to submit regularily the Metric
#
#crontab -e
#(vim) */1 * * * * cd <path_to_the_script> ; python query_freshness.py
#(vim) !wq
#crontab -l
#########################################################################
from datadog import initialize, api
import time
options = {
'api_key': '149***e4',
'app_key': 'f2e***a5'
}
initialize(**options)
now = int(time.time())
query = 'system.cpu.system{*}' # Modify the metric you want to track the freshness of
metric = api.Metric.query(start=now - 3600, end=now, query=query) # how far back in time you want to go (the default is one hour)
nb_points = len(metric['series'][0]['pointlist']) - 1
last_submission = int(metric['series'][0]['pointlist'][nb_points][0]) / 1000
freshness = now - last_submission
print "freshness is: ", freshness
api.Metric.send(metric='freshness', points=freshness, tags=["metric:" + str(query)])