<commit_before>/**
 * Created by <NAME> on 04/01/2017.
 */

'use strict';

const log = require("../../net2/logger.js")(__filename, "info");

let fs = require('fs');
let util = require('util');

let f = require('../../net2/Firewalla.js');
let fHome = f.getFirewallaHome();
let logFolder = f.getLogFolder();

let config = require("../../net2/config.js").getConfig();

let userID = f.getUserID();

const df = require('node-df');

//let SysManager = require('../../net2/SysManager');
//let sysManager = new SysManager();

let os  = require('../../vendor_lib/osutils.js');

let exec = require('child-process-promise').exec;

const rclient = require('../../util/redis_manager.js').getRedisClient()
let _async = require('async');

let Promise = require('bluebird');

const async = require('asyncawait/async');
const await = require('asyncawait/await');

let cpuUsage = 0;
let memUsage = 0;
let realMemUsage = 0;
let usedMem = 0;
let allMem = 0;
let curTemp = 0;
let peakTemp = 0;

let conn = 0;
let peakConn = 0;

let redisMemory = 0;

let updateFlag = 0;

let updateInterval = 30 * 1000; // every 30 seconds

let releaseBranch = null;

let threadInfo = {};

let diskInfo = null;

let intelQueueSize = 0;

let multiProfileSupport = false;

getMultiProfileSupportFlag();

function update() {
  os.cpuUsage((v) => {
    log.debug( 'CPU Usage (%): ' + v );
    cpuUsage = v;
  });

  getRealMemoryUsage();
  getTemp();
  getConns();
  getRedisMemoryUsage();
  getThreadInfo();
  getIntelQueueSize();
  getDiskInfo();
  getMultiProfileSupportFlag();

  if(updateFlag) {
    setTimeout(() => { update(); }, updateInterval);
  }
}

function startUpdating() {
  updateFlag = 1;
  update();
}

function stopUpdating() {
  updateFlag = 0;
}

function getThreadInfo() {
  return async(() => {
    let count = await (exec("ps -Haux | wc -l", {encoding: 'utf8'}));
    let mainCount = await (exec("ps -Haux | grep Fi[r]eMain | wc -l", {encoding: 'utf8'}));
    let apiCount = await (exec("ps -Haux | grep Fi[r]eApi | wc -l", {encoding: 'utf8'}));
    let monitorCount = await (exec("ps -Haux | grep Fi[r]eMon | wc -l", {encoding: 'utf8'}));
    threadInfo.count = count.stdout.replace("\n", "");
    threadInfo.mainCount = mainCount.stdout.replace("\n", "");
    threadInfo.apiCount = apiCount.stdout.replace("\n", "");
    threadInfo.monitorCount = monitorCount.stdout.replace("\n", "");
  })();
}

function getDiskInfo() {
  df((err, response) => {
    if(err) {
      log.error("Failed to get disk info, err:", err);
      return;
    }

    const disks = response.filter((entry) => {
      return entry.filesystem.startsWith("/dev/mmc");
    })

    diskInfo = disks;
  });
}

function getMultiProfileSupportFlag() {
  fs.access("/etc/openvpn/multi_profile_support", fs.F_OK, (err) => {
    if(err) {
      multiProfileSupport = false;
    } else {
      multiProfileSupport = true;
    }
  })
}<commit_msg>bug fix<commit_after>/**
 * Created by <NAME> on 04/01/2017.
 */

'use strict';

const log = require("../../net2/logger.js")(__filename, "info");

let fs = require('fs');
let util = require('util');

let f = require('../../net2/Firewalla.js');
let fHome = f.getFirewallaHome();
let logFolder = f.getLogFolder();

let config = require("../../net2/config.js").getConfig();

let userID = f.getUserID();

const df = require('node-df');

//let SysManager = require('../../net2/SysManager');
//let sysManager = new SysManager();

let os  = require('../../vendor_lib/osutils.js');

let exec = require('child-process-promise').exec;

const rclient = require('../../util/redis_manager.js').getRedisClient()
let _async = require('async');

let Promise = require('bluebird');

const async = require('asyncawait/async');
const await = require('asyncawait/await');

let cpuUsage = 0;
let memUsage = 0;
let realMemUsage = 0;
let usedMem = 0;
let allMem = 0;
let curTemp = 0;
let peakTemp = 0;

let conn = 0;
let peakConn = 0;

let redisMemory = 0;

let updateFlag = 0;

let updateInterval = 30 * 1000; // every 30 seconds

let releaseBranch = null;

let threadInfo = {};

let diskInfo = null;

let intelQueueSize = 0;

let multiProfileSupport = false;

getMultiProfileSupportFlag();

function update() {
  os.cpuUsage((v) => {
    log.debug( 'CPU Usage (%): ' + v );
    cpuUsage = v;
  });

  getRealMemoryUsage();
  getTemp();
  getConns();
  getRedisMemoryUsage();
  getThreadInfo();
  getIntelQueueSize();
  getDiskInfo();
  getMultiProfileSupportFlag();

  if(updateFlag) {
    setTimeout(() => { update(); }, updateInterval);
  }
}

function startUpdating() {
  updateFlag = 1;
  update();
}

function stopUpdating() {
  updateFlag = 0;
}

function getThreadInfo() {
  return async(() => {
    let count = await (exec("ps -Haux | wc -l", {encoding: 'utf8'}));
    let mainCount = await (exec("ps -Haux | grep Fi[r]eMain | wc -l", {encoding: 'utf8'}));
    let apiCount = await (exec("ps -Haux | grep Fi[r]eApi | wc -l", {encoding: 'utf8'}));
    let monitorCount = await (exec("ps -Haux | grep Fi[r]eMon | wc -l", {encoding: 'utf8'}));
    threadInfo.count = count.stdout.replace("\n", "");
    threadInfo.mainCount = mainCount.stdout.replace("\n", "");
    threadInfo.apiCount = apiCount.stdout.replace("\n", "");
    threadInfo.monitorCount = monitorCount.stdout.replace("\n", "");
  })();
}

function getDiskInfo() {
  df((err, response) => {
    if(err) {
      log.error("Failed to get disk info, err:", err);
      return;
    }

    const disks = response.filter((entry) => {
      return entry.filesystem.startsWith("/dev/mmc");
    })

    diskInfo = disks;
  });
}

function getMultiProfileSupportFlag() {
  fs.access("/etc/openvpn/multi_profile_support", fs.F_OK, (err) => {
    if(err) {
      multiProfileSupport = false;
    } else {
      fs.access("/etc/openvpn/easy-rsa/keys2", fs.F_OK, (err) => {
        if(err) {
          multiProfileSupport = true;
        } else {
          multiProfileSupport = false;
        }
      })
    }
  })
}
{'fraction_non_alphanumeric': 0.1849545607539549, 'fraction_numerical': 0.012958599798047796, 'mean_word_length': 3.4417040358744395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2201321', 'n_tokens_mistral': 2084, 'n_tokens_neox': 2031, 'n_words': 476}