#!/usr/bin/python
# coding: utf-8
import os
import commands
import boto.ec2.cloudwatch
AWS_ACCESS_KEY = '********'
AWS_SECRET_ACCESS_KEY = '********'
AWS_REGION_NAME = '********'
def main():
instance_id = commands.getoutput("wget -q -O - http://169.254.169.254/latest/meta-data/instance-id")
load_averages = os.getloadavg()
cloud_watch = boto.ec2.cloudwatch.connect_to_region(
aws_access_key_id=AWS_ACCESS_KEY ,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_REGION_NAME,
)
cloud_watch.put_metric_data(
namespace='LoadAverage',
name='LoadAverage',
value=float(load_averages[0]),
dimensions={
'InstanceId': instance_id,
}
)
if __name__ == '__main__':
main()
Recommended Posts