{"size": 1061, "ext": "js", "max_stars_repo_path": "node_modules/pm2/node_modules/pmx/lib/monitor.js", "max_stars_repo_name": "zlq32326/ZLQ", "max_stars_repo_stars_event_min_datetime": "2016-08-12T07:41:04.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-12T07:41:04.000Z", "max_issues_repo_path": "node_modules/pm2/node_modules/pmx/lib/monitor.js", "max_issues_repo_name": "zlq32326/ZLQ", "max_issues_repo_issues_event_min_datetime": "2020-09-06T11:47:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T01:07:05.000Z", "max_forks_repo_path": "node_modules/pm2/node_modules/pmx/lib/monitor.js", "max_forks_repo_name": "zlq32326/ZLQ", "max_forks_repo_forks_event_min_datetime": "2020-01-07T12:45:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-29T16:47:33.000Z"}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": 2, "avg_line_length": 21.22, "max_line_length": 51, "alphanum_fraction": 0.6908576814}

var Transport = require('./utils/transport.js');
var debug = require('debug')('axm:monitor');

var Monitor = {};

function cookData(data) {
  var cooked_data = {};

  Object.keys(data).forEach(function(probe_name) {
    if (typeof(data[probe_name]) == 'function')
      cooked_data[probe_name] = data[probe_name]();
    else
      cooked_data[probe_name] = data[probe_name];
  });
  return cooked_data;
};

function enableProbes(custom_namespace) {
  if (!custom_namespace)
    custom_namespace = 'axm';

  if (!global[custom_namespace])
    global[custom_namespace] = {};

  if (this.interval)
    return global[custom_namespace];

  this.interval = setInterval(function() {
    Transport.send({
      type : 'axm:monitor',
      data : cookData(global[custom_namespace])
    });
  }, 990);

  return global[custom_namespace];
};

function stopProbing() {
  clearInterval(this.interval);
}

Monitor.enableProbes = enableProbes;
Monitor.enableProbe = enableProbes;

Monitor.stopProbe = stopProbing;
Monitor.stopProbes = stopProbing;

module.exports = Monitor;
