-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudwatch_metric.py
76 lines (65 loc) · 2.12 KB
/
cloudwatch_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
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
67
68
69
70
71
72
73
74
import boto3
import datetime
def collect_metrics_ebs_volume(volid,connectionobject,startdate,enddate):
# spliiting date as there will be only 1440 datapoints in a single API call
metric_data=[]
split=enddate-startdate
if(split<=datetime.timedelta(0)):
print("Start time cannot be greater than or equl to end time")
exit(1)
intervel=int((split.days)/5)
if intervel==0:
intervel=1
print("intervel")
for x in range(intervel):
print("entered the loop")
if x==intervel-1:
enddate=startdate+(datetime.timedelta(split.days%5))
else:
enddate=startdate+datetime.timedelta(5)
print(enddate)
response1 = connectionobject.get_metric_statistics(
Namespace='AWS/EBS',
MetricName='VolumeReadOps',
Dimensions=[
{
'Name': 'VolumeId',
'Value': volid
},
],
StartTime=startdate,
EndTime=enddate,
Period=300,
Statistics=['Sum', ]
)
response2 = connectionobject.get_metric_statistics(
Namespace='AWS/EBS',
MetricName='VolumeWriteOps',
Dimensions=[
{
'Name': 'VolumeId',
'Value': volid
},
],
StartTime=startdate,
EndTime=enddate,
Period=300,
Statistics=['Sum', ]
)
# for debug purpose
print(response2)
print(response1)
startdate = enddate
for x,y in zip(response2.get("Datapoints"),response1.get("Datapoints")):
tmprow=[volid,x.get("Timestamp"),(x.get("Sum")+y.get("Sum"))/300]
metric_data.append(tmprow)
print(x.get("Timestamp"))
print(x.get("Sum"))
#print(y.get("Sum"))
return metric_data
# for sample in response2.get("Datapoints"):
#
# print(sample.get("Sum"))
#
# for sample in response1.get("Datapoints"):
# print(sample.get("Sum"))