forked from grihey/atsd-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity_print_metrics_html.py
31 lines (22 loc) · 1.25 KB
/
entity_print_metrics_html.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
from datetime import datetime, timedelta
from prettytable import PrettyTable
from atsd_client import connect, connect_url
from atsd_client.services import MetricsService, EntitiesService
# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')
entity = 'my-entity'
entities_service = EntitiesService(connection)
metrics_service = MetricsService(connection)
# query all metrics for entity
metrics = entities_service.metrics(entity, tags='frequency,seasonal_adjustment,observation_start,observation_end,category,parent_category', limit=5)
t = PrettyTable(['Top Category', 'Category', 'Name', 'Label', 'Frequency', 'Adjustment', 'Observation Start', 'Observation End'])
# iterate over metrics and add their fields/tags as rows into a PrettyTable
for metric in metrics:
t.add_row([metric.tags['category'], metric.tags['parent_category'], metric.name, metric.label, metric.tags['frequency'], metric.tags['seasonal_adjustment'], metric.tags['observation_start'], metric.tags['observation_end']])
# Sort metrics by name
t.sortby = "Name"
# Print metrics as ASCII table
#print(t)
# Print metrics as HTML table with header
print(t.get_html_string(title="Available Metrics"))