Created
June 22, 2013 05:40
-
-
Save qzaidi/5835999 to your computer and use it in GitHub Desktop.
dashing job for fetching CPU usage and Instance count from AWS. Create an aws-config.json, and update your AutoScalingGroupName here. It assumes a List widget named servers and a Meter widget named cpu in your dashboard. { "accessKeyId": "XXXXXX", "secretAccessKey": "XXXXX", "region": "ap-southeast-1" }
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var AWS = require('aws-sdk'); | |
AWS.config.loadFromPath(__dirname + '/../aws-config.json'); | |
var autoscaling = new AWS.AutoScaling(); | |
var cloudwatch = new AWS.CloudWatch(); | |
function goFigure() { | |
var e = new Date(); | |
var d = new Date(Date.now() - 5*60*1000); | |
autoscaling.describeAutoScalingInstances({},function(err,data) { | |
if (!err) { | |
var items = data.AutoScalingInstances.map(function(srv) { | |
return { label: srv.InstanceId, value: srv.HealthStatus }; | |
}); | |
send_event('servers', { items: items }); | |
} | |
}); | |
cloudwatch.getMetricStatistics({ Namespace: 'AWS/EC2' , MetricName: 'CPUUtilization', | |
Dimensions: [ { Name: 'AutoScalingGroupName', Value: 'adproxyasgrp' } ], | |
StartTime:d , EndTime: e, Period: 60, Statistics: [ 'Average','SampleCount' ], | |
}, function(err,data) { | |
var datapoint = data.Datapoints.pop(); | |
if (err) { | |
return console.log(err); | |
} | |
send_event('cpu',{ value: Math.floor(datapoint.Average), | |
moreinfo: 'CPU usage at ' + datapoint.Timestamp.toTimeString() }); | |
}); | |
} | |
goFigure(); | |
setInterval(goFigure,60*1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment