-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaggregation-test.py
More file actions
66 lines (57 loc) · 2.58 KB
/
Copy pathaggregation-test.py
File metadata and controls
66 lines (57 loc) · 2.58 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Network paths - See how data is aggregated by changing hours_back and
# hour_range and seeing how Period changes.
#
import math
from api_fns import *
count = 0
metric = 'availablecapacity'
org_id = '11111' # organization ID
path_id = 222222 # network path ID
hours_back = 24*0 # the number of hours ago the range ends
hour_range = 24*10 # the number of hours in the range
if (hours_back == 0) & (hour_range == 0):
start = end = None
else:
if (hour_range == 0):
hour_range = 1
end = math.floor(time.time()-(60*60*hours_back))
start = (end - math.floor(60*60*hour_range))
print('Start time: {} ({})'.format(time.ctime(start), start))
print('End time: {} ({})'.format(time.ctime(end), end))
print('Org id: ({})'.format(org_id))
print('Path id: ({})'.format(path_id))
r1 = get_network_path_stats_id(org_id, path_id, start, end, metric)
if r1.status_code == requests.codes.ok:
for network_path_stats in r1.json():
print(' Network path ({})'.format(network_path_stats['pathId']))
# pp_json(network_path_stats)
if network_path_stats['pathId'] == path_id:
# pp_json(network_path_stats)
if network_path_stats['instrumentation'] == "ONE_WAY":
# Single-ended paths have data within 'data'
for test in network_path_stats['data']['availableCapacity']:
count += 1
print(' Single-ended path -> Start time={}' +
' Period={} Available Capacity value={} count={}'
.format(time.ctime(test['start']/1000),
test['period'],
math.floor(test['value']), count))
# pp_json(test)
else:
# Dual-ended paths have data within
# 'dataInbound' and 'dataOutbound'
for test in network_path_stats['dataInbound']['availableCapacity']:
count += 1
print(' Dual-ended path -> Start time={}' +
' Period={} Available Capacity value={} count={}'
.format(time.ctime(test['start']/1000),
test['period'],
math.floor(test['value']), count))
# pp_json(test)
elif r1.status_code == requests.codes.bad_request:
print_err_json(r1.json())
else:
print_err(r1)
print('Start time: {} ({})'.format(time.ctime(start), start))
print('End time: {} ({})'.format(time.ctime(end), end))