-
-
Save supernova106/d704a0eab7df623947bf6a02892581e7 to your computer and use it in GitHub Desktop.
Revisions
-
qzaidi created this gist
Jun 22, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ "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);