Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save supernova106/d704a0eab7df623947bf6a02892581e7 to your computer and use it in GitHub Desktop.
Save supernova106/d704a0eab7df623947bf6a02892581e7 to your computer and use it in GitHub Desktop.

Revisions

  1. @qzaidi qzaidi created this gist Jun 22, 2013.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original 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);