forked from grihey/atsd-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_lagging_series_by_metric.py
29 lines (23 loc) · 1.12 KB
/
find_lagging_series_by_metric.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
from datetime import timedelta, datetime
from atsd_client import connect, connect_url
from atsd_client.services import MetricsService
from atsd_client.utils import print_tags
'''
Locate series that have no data during the actual time interval (grace_interval) using specific metric.
'''
# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')
# set metric and grace_interval to one day
metric = 'nmon.cpu.busy%'
grace_interval_minutes = 24 * 60
# query entities with last_insert_date
min_insert_date = "1970-01-01T00:00:00.000Z"
# calculate the upper boundary for the allowed last_insert_date values excluding grace_interval
max_insert_date = datetime.now() - timedelta(seconds=grace_interval_minutes * 60)
metrics_service = MetricsService(connection)
# query all series for metric
series = metrics_service.series(metric, min_insert_date=min_insert_date, max_insert_date=max_insert_date)
print('metric,entity,tags,last_insert_date')
for s in series:
print("%s,%s,%s,%s" % (s.metric, s.entity, print_tags(s.tags), s.last_insert_date))