Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added agent initialization step

  • Loading branch information...
commit a7f48d05ff16c8a2aa642a492cf21b9e7731d080 1 parent 29a3925
@DamonOehlman authored
Showing with 74 additions and 3 deletions.
  1. +6 −0 lib/agent.js
  2. +63 −0 lib/agents.inprogress/net.js
  3. +5 −3 lib/collector.js
View
6 lib/agent.js
@@ -4,6 +4,12 @@ var DEFAULT_AMOUNT = Math.pow(10, 5);
var BaseAgent = exports.BaseAgent = function() {
};
+BaseAgent.prototype.init = function(callback) {
+ if (callback) {
+ callback(true);
+ } // if
+}; // init
+
BaseAgent.prototype.roundVal = function(value, decimals) {
// initialise the amount, avoid math if we can
var amount = decimals ? Math.pow(10, decimals) : DEFAULT_AMOUNT;
View
63 lib/agents.inprogress/net.js
@@ -0,0 +1,63 @@
+var os = require('os'),
+ exec = require('child_process').exec,
+ util = require('util'),
+ BaseAgent = require('../agent').BaseAgent;
+
+function getStats(iface, callback) {
+ var adapter = exec('/sbin/ifconfig', function(err, stdout, stderr) {
+ console.log(stdout);
+ });
+} // getStats
+
+var Agent = exports.Agent = function() {
+ // initialise frequency to once every 5 seconds
+ this.frequency = '*/5 * * * * *';
+};
+
+util.inherits(Agent, BaseAgent);
+
+Agent.prototype.init = function(callback) {
+ this.iface = this.opts.iface || 'eth0';
+
+ getStats(this.iface, function(data) {
+ console.log(data);
+ });
+}; // init
+
+Agent.prototype.run = function(callback) {
+ getStats(this.iface, function(data) {
+
+ });
+};
+
+/*
+module.exports = (function() {
+ var reNetworkAct = /(\wX).*?\:(\d+)/g,
+ oldData = {};
+
+ collect(function(traffic) {
+ oldData = traffic;
+ });
+
+ function run(callback) {
+ function compare(newData) {
+ var timeElapsed = newData.tickCount - oldData.tickCount,
+ netIO = {
+ transmit : Math.floor((newData.TX - oldData.TX) * (1000 / timeElapsed)),
+ receive : Math.floor((newData.RX - oldData.RX) * (1000 / timeElapsed))
+ };
+ // reset the Data for the next pass
+ oldData = newData;
+ //console.log(netIO);
+ callback(netIO);
+ } // compare
+ collect(compare);
+ } // run
+
+ return {
+ // define the frequency for
+ frequency: '* * * * * *',
+ run: run
+ };
+})();
+*/
View
8 lib/collector.js
@@ -31,9 +31,11 @@ function loadAgents(collector, agentPaths, callback) {
// initialise the frequency
// priority = options first, default frequency (if set) 2nd, cron pattern for every second last
agent.frequency = agent.opts.frequency || agent.frequency || '* * * * * *';
-
- // add the list of active agents
- collector.agents.push(agent);
+
+ // initialise the agent - if initialized ok, then add to the agents
+ agent.init(function(initOK) {
+ collector.agents.push(agent);
+ });
} // if
else {
console.log('Agent= no run handler for agent "' + agentId + '", not registering');
Please sign in to comment.
Something went wrong with that request. Please try again.