forked from grihey/atsd-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_lagging_series_by_entity.py
34 lines (27 loc) · 1.32 KB
/
find_lagging_series_by_entity.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
32
33
34
from datetime import datetime, timedelta
from atsd_client import connect, connect_url
from atsd_client.services import MetricsService, EntitiesService
from atsd_client.utils import print_tags
'''
Locate series that have no data during the actual time interval (grace_interval) using specific entity.
'''
# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')
# set entity and grace_interval to one day
entity = 'nurswgvml007'
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)
entities_service = EntitiesService(connection)
metrics_service = MetricsService(connection)
# query all metrics for entity
metrics = entities_service.metrics(entity)
print('metric,entity,tags,last_insert_date')
for metric in metrics:
# query all series for each metric and entity
series = metrics_service.series(metric, entity, min_insert_date=min_insert_date, max_insert_date=max_insert_date)
for s in series:
print("%s,%s,%s,%s" % (s.metric, s.entity, print_tags(s.tags), s.last_insert_date))