<commit_before>#!/usr/bin/env node
// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2012 AppsAttic Ltd - http://www.appsattic.com/
//
// Written by - <NAME>
// * Email    - <EMAIL>
// * Site     - http://chilts.org/
// * Blog     - http://chilts.org/blog/
// * Twitter  - https://twitter.com/andychilton
//
// License: http://opensource.org/licenses/MIT
//
// --------------------------------------------------------------------------------------------------------------------

var fs = require('fs');
var exec = require('child_process').exec
var util = require('util');

var inspect = require('eyes').inspector();
var async = require('async');
var nconf = require('nconf');
var osenv = require('osenv');
var Seq   = require('seq');
var oibackoff = require('oibackoff');

var awssum     = require('awssum');
var amazon     = awssum.load('amazon/amazon');
var CloudWatch = awssum.load('amazon/cloudwatch').CloudWatch;
var Imd        = awssum.load('amazon/imd').Imd;

// --------------------------------------------------------------------------------------------------------------------

var KILO = 1024;
var MEGA = 1048576;
var GIGA = 1073741824;

var hostname;
var instanceId;
var region;
var availZone;
var home = process.env.HOME;
var stats = {};
var data = {
    'Namespace'  : 'System/Linux',
    'MetricData' : [],
};
var timestamp = (new Date()).toISOString();
var verbose;

function msg() {
    if ( verbose ) {
        console.log.apply(null, arguments);
    }
};

function dump(name, data) {
    if ( verbose ) {
        console.log(name + ' : ' + util.inspect(data, false, null, true));
    }
}

function li(msg) {
    if ( verbose ) {
        console.log('* ' + msg);
    }
}

// backoff strategy
var backoff = oibackoff.backoff({
    'algorithm'  : 'exponential',
    'delayRatio' : 0.2,
    'maxTries'   : 3,
});

// --------------------------------------------------------------------------------------------------------------------

// top ones take precendence over lower ones (hence the default is at the bottom)
nconf
    .argv()
    .env()
    .file({ file: osenv.home() + '/.awssum' })
    .defaults({
        'test'    : false,
        'verbose' : false,
        'memory'  : false,
        'swap'    : false,
    });

// get a few things from the config
verbose = nconf.get('verbose');

// firstly, do a few things in order to start off with

Seq()
    .seq(getInstanceId)
    .seq(getRegion)
    .seq(getHostname)
    .seq(gatherMemInfo)
    .seq(gatherDiskInfo)
    .seq(sendMetrics)
    .catch(function(err) {
        console.error(err.stack ? err.stack : err);
    })
;

// --------------------------------------------------------------------------------------------------------------------
// all functions which deal with sequences or queues

function getInstanceId() {
    msg('Getting instance id ...');

    var next = this;

    var imd = new Imd();
    imd.Get({
        Category : '/meta-data/instance-id',
        Version  : 'latest',
    }, function(err, data) {
        if (err) {
            console.error("Can't get instance-id");
            next();
            return;
        }
        instanceId = data.Body;
        msg('Getting instance id ... ' + instanceid);
        next();
    });
}

function getRegion() {
    msg('Getting availability zone ...');

    var next = this;

    var imd = new Imd();
    imd.Get({
        Category : '/meta-data/placement/availability-zone',
        Version  : 'latest',
    }, function(err, data) {
        if (err) {
            console.error("Can't get availability zone");
            next();
            return;
        }
        availZone = data.Body;
        region = availZone.substr(0, availZone.length-1);
        msg('Getting availability zone ... ' + availZone);
        msg('Regions is ' + region);
        next();
    });
}<commit_msg>Fix the instanceId variable name<commit_after>#!/usr/bin/env node
// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2012 AppsAttic Ltd - http://www.appsattic.com/
//
// Written by - <NAME>
// * Email    - <EMAIL>
// * Site     - http://chilts.org/
// * Blog     - http://chilts.org/blog/
// * Twitter  - https://twitter.com/andychilton
//
// License: http://opensource.org/licenses/MIT
//
// --------------------------------------------------------------------------------------------------------------------

var fs = require('fs');
var exec = require('child_process').exec
var util = require('util');

var inspect = require('eyes').inspector();
var async = require('async');
var nconf = require('nconf');
var osenv = require('osenv');
var Seq   = require('seq');
var oibackoff = require('oibackoff');

var awssum     = require('awssum');
var amazon     = awssum.load('amazon/amazon');
var CloudWatch = awssum.load('amazon/cloudwatch').CloudWatch;
var Imd        = awssum.load('amazon/imd').Imd;

// --------------------------------------------------------------------------------------------------------------------

var KILO = 1024;
var MEGA = 1048576;
var GIGA = 1073741824;

var hostname;
var instanceId;
var region;
var availZone;
var home = process.env.HOME;
var stats = {};
var data = {
    'Namespace'  : 'System/Linux',
    'MetricData' : [],
};
var timestamp = (new Date()).toISOString();
var verbose;

function msg() {
    if ( verbose ) {
        console.log.apply(null, arguments);
    }
};

function dump(name, data) {
    if ( verbose ) {
        console.log(name + ' : ' + util.inspect(data, false, null, true));
    }
}

function li(msg) {
    if ( verbose ) {
        console.log('* ' + msg);
    }
}

// backoff strategy
var backoff = oibackoff.backoff({
    'algorithm'  : 'exponential',
    'delayRatio' : 0.2,
    'maxTries'   : 3,
});

// --------------------------------------------------------------------------------------------------------------------

// top ones take precendence over lower ones (hence the default is at the bottom)
nconf
    .argv()
    .env()
    .file({ file: osenv.home() + '/.awssum' })
    .defaults({
        'test'    : false,
        'verbose' : false,
        'memory'  : false,
        'swap'    : false,
    });

// get a few things from the config
verbose = nconf.get('verbose');

// firstly, do a few things in order to start off with

Seq()
    .seq(getInstanceId)
    .seq(getRegion)
    .seq(getHostname)
    .seq(gatherMemInfo)
    .seq(gatherDiskInfo)
    .seq(sendMetrics)
    .catch(function(err) {
        console.error(err.stack ? err.stack : err);
    })
;

// --------------------------------------------------------------------------------------------------------------------
// all functions which deal with sequences or queues

function getInstanceId() {
    msg('Getting instance id ...');

    var next = this;

    var imd = new Imd();
    imd.Get({
        Category : '/meta-data/instance-id',
        Version  : 'latest',
    }, function(err, data) {
        if (err) {
            console.error("Can't get instance-id");
            next();
            return;
        }
        instanceId = data.Body;
        msg('Getting instance id ... ' + instanceId);
        next();
    });
}

function getRegion() {
    msg('Getting availability zone ...');

    var next = this;

    var imd = new Imd();
    imd.Get({
        Category : '/meta-data/placement/availability-zone',
        Version  : 'latest',
    }, function(err, data) {
        if (err) {
            console.error("Can't get availability zone");
            next();
            return;
        }
        availZone = data.Body;
        region = availZone.substr(0, availZone.length-1);
        msg('Getting availability zone ... ' + availZone);
        msg('Regions is ' + region);
        next();
    });
}
{'fraction_non_alphanumeric': 0.28865979381443296, 'fraction_numerical': 0.007636502481863307, 'mean_word_length': 1.4472127063220181, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4990276', 'n_tokens_mistral': 2300, 'n_tokens_neox': 2214, 'n_words': 540}