Skip to content

Instantly share code, notes, and snippets.

@marcy-terui
Created January 8, 2015 08:38
Show Gist options
  • Select an option

  • Save marcy-terui/cde3054dda4cc9df4cd3 to your computer and use it in GitHub Desktop.

Select an option

Save marcy-terui/cde3054dda4cc9df4cd3 to your computer and use it in GitHub Desktop.
Python botoでCloudWatch Metricsの一覧とUnitの単位の対応表を取得する ref: http://qiita.com/Marcy/items/ca392728efa787be4f97
#!/usr/bin/env python
import sys
import datetime
import re
from boto.ec2 import cloudwatch
end = datetime.datetime.utcnow()
start = end - datetime.timedelta(minutes=10)
cw = cloudwatch.connect_to_region('ap-northeast-1')
def main():
if len(sys.argv) not in [2,3]:
print('Usage: python %s <namespace> [separator]' % sys.argv[0])
quit()
namespace = sys.argv[1]
separator = "\t" if len(sys.argv) == 2 else sys.argv[2]
results = []
for metric in cw.list_metrics(namespace=namespace):
for data in metric.query(start_time=start, end_time=end, statistics='Average'):
results.append(separator.join([namespace, metric.name, data['Unit']]))
results = list(set(results))
for ret in results:
print(ret)
if __name__ == '__main__':
main()
python <script-file-name> <namespace> [separator]
$ python get-metrics-unit-type.py AWS/EC2
AWS/EC2 CPUCreditUsage Count
AWS/EC2 CPUCreditBalance Count
AWS/EC2 StatusCheckFailed Count
AWS/EC2 DiskReadOps Count
AWS/EC2 StatusCheckFailed_System Count
AWS/EC2 DiskWriteBytes Bytes
AWS/EC2 NetworkOut Bytes
AWS/EC2 DiskReadBytes Bytes
AWS/EC2 NetworkIn Bytes
AWS/EC2 DiskWriteOps Count
AWS/EC2 StatusCheckFailed_Instance Count
AWS/EC2 CPUUtilization Percent
$ python get-metrics-unit-type.py AWS/EBS
AWS/EBS VolumeWriteBytes Bytes
AWS/EBS VolumeQueueLength Count
AWS/EBS VolumeReadOps Count
AWS/EBS VolumeIdleTime Seconds
AWS/EBS VolumeTotalWriteTime Seconds
AWS/EBS VolumeWriteOps Count
$ python get-metrics-unit-type.py AWS/RDS
AWS/RDS FreeableMemory Bytes
AWS/RDS NetworkTransmitThroughput Bytes/Second
AWS/RDS DatabaseConnections Count
AWS/RDS WriteIOPS Count/Second
AWS/RDS ReadIOPS Count/Second
AWS/RDS ReadLatency Seconds
AWS/RDS WriteThroughput Bytes/Second
AWS/RDS ReadThroughput Bytes/Second
AWS/RDS FreeStorageSpace Bytes
AWS/RDS WriteLatency Seconds
AWS/RDS DiskQueueDepth Count
AWS/RDS CPUUtilization Percent
AWS/RDS CPUCreditUsage Count
AWS/RDS NetworkReceiveThroughput Bytes/Second
AWS/RDS CPUCreditBalance Count
AWS/RDS BinLogDiskUsage Bytes
AWS/RDS SwapUsage Bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment