forked from grihey/atsd-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_non-positive_values.py
51 lines (41 loc) · 1.74 KB
/
find_non-positive_values.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from datetime import datetime
from atsd_client import connect, connect_url
from atsd_client.models import SeriesFilter, EntityFilter, DateFilter, SeriesQuery
from atsd_client.services import SeriesService, MetricsService
'''
Load all series values that are non-positive for the specified metric.
Optionally, if deleteValues parameter is set replace these values with NaN.
'''
# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')
# disable deleting inappropriate values
deleteValues = False
# specify metric name
metric_name = "ca.daily.reservoir_storage_af"
svc = SeriesService(connection)
metrics_service = MetricsService(connection)
# query series with current metric and all entities
sf = SeriesFilter(metric=metric_name)
ef = EntityFilter(entity='*')
df = DateFilter(start_date="1970-01-01T00:00:00Z", end_date=datetime.now())
query = SeriesQuery(series_filter=sf, entity_filter=ef, date_filter=df)
series = svc.query(query)
if deleteValues:
print('Inappropriate values to be deleted.\n')
else:
print('Leave as is inappropriate values.\n')
print('metric,entity,tags,data')
for s in series:
# filter non-positive values
s.data = [sample for sample in s.data if sample.v is not None and sample.v <= 0]
if len(s.data) > 0:
print("%s,%s,%s,%s" % (s.metric, s.entity, s.tags, [sample.v for sample in s.data]))
if deleteValues:
# delete replace inappropriate values with Nan
for sample in s.data:
print("- Deleting %s, %s " % (sample.get_date(), sample.v))
sample.v = None
s.aggregate = None
# Uncomment next line to delete
# svc.insert(s)