-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebs_plugin.py
48 lines (37 loc) · 1.98 KB
/
ebs_plugin.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
import boto
import boto.ec2
import sys
from boundary_aws_plugin.cloudwatch_plugin import CloudwatchPlugin
from boundary_aws_plugin.cloudwatch_metrics import CloudwatchMetrics
class EbsCloudwatchMetrics(CloudwatchMetrics):
def __init__(self, access_key_id, secret_access_key):
return super(EbsCloudwatchMetrics, self).__init__(access_key_id, secret_access_key, 'AWS/EBS')
def get_region_list(self):
# Some regions are returned that actually do not support EC2. Skip those.
return [r for r in boto.ec2.regions() if r.name not in ['cn-north-1', 'us-gov-west-1']]
def get_entities_for_region(self, region):
ec2 = boto.connect_ec2(self.access_key_id, self.secret_access_key, region=region)
return ec2.get_all_volumes()
def get_entity_dimensions(self, region, volume):
return dict(VolumeId=volume.id)
def get_entity_source_name(self, volume):
return volume.id
def get_metric_list(self):
return (
('VolumeReadBytes', 'Sum', 'AWS_EBS_VOLUME_READ_BYTES'),
('VolumeWriteBytes', 'Sum', 'AWS_EBS_VOLUME_WRITE_BYTES'),
('VolumeReadOps', 'Sum', 'AWS_EBS_VOLUME_READ_OPS'),
('VolumeWriteOps', 'Sum', 'AWS_EBS_VOLUME_WRITE_OPS'),
('VolumeTotalReadTime', 'Sum', 'AWS_EBS_VOLUME_TOTAL_READ_TIME'),
('VolumeTotalWriteTime', 'Sum', 'AWS_EBS_VOLUME_TOTAL_WRITE_TIME'),
('VolumeIdleTime', 'Sum', 'AWS_EBS_VOLUME_IDLE_TIME'),
('VolumeQueueLength', 'Sum', 'AWS_EBS_VOLUME_QUEUE_LENGTH'),
('VolumeThroughputPercentage', 'Sum', 'AWS_EBS_VOLUME_THROUGHPUT_PERCENTAGE', 0.01),
('VolumeConsumedReadWriteOps', 'Sum', 'AWS_EBS_VOLUME_CONSUMED_READ_WRITE_OPS'),
)
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == '-v':
import logging
logging.basicConfig(level=logging.INFO)
plugin = CloudwatchPlugin(EbsCloudwatchMetrics, '', 'boundary-plugin-aws-ebs-python-status')
plugin.main()