mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-10 21:33:38 +00:00
Synced with server repo
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -169,23 +169,23 @@ function lme_heci(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this[name][port] == null)
|
if (this[name][port] == null)
|
||||||
{ // Bind a new server socket if not already present
|
{
|
||||||
this[name][port] = require('net').createServer();
|
|
||||||
this[name][port].HECI = this;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Bind a new server socket if not already present
|
||||||
|
this[name][port] = require('net').createServer();
|
||||||
|
this[name][port].HECI = this;
|
||||||
if (lme_port_offset == 0) {
|
if (lme_port_offset == 0) {
|
||||||
this[name][port].listen({ port: port, host: '127.0.0.1' }); // Normal mode
|
this[name][port].listen({ port: port, host: '127.0.0.1' }); // Normal mode
|
||||||
} else {
|
} else {
|
||||||
this[name][port].listen({ port: (port + lme_port_offset) }); // Debug mode
|
this[name][port].listen({ port: (port + lme_port_offset) }); // Debug mode
|
||||||
}
|
}
|
||||||
} catch (ex) { console.log('Binding error, LMS port ' + (port + lme_port_offset) + ': ' + ex) } // TODO: We can't bind
|
this[name][port].on('connection', function (socket) {
|
||||||
this[name][port].on('connection', function (socket) {
|
//console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort);
|
||||||
//console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort);
|
this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset);
|
||||||
this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset);
|
});
|
||||||
});
|
this._binded[port] = true;
|
||||||
this._binded[port] = true;
|
this.LMS.emit('bind', this._binded);
|
||||||
this.LMS.emit('bind', this._binded);
|
} catch (ex) { console.log(ex, 'Port ' + port); }
|
||||||
}
|
}
|
||||||
var outBuffer = Buffer.alloc(5);
|
var outBuffer = Buffer.alloc(5);
|
||||||
outBuffer.writeUInt8(81, 0);
|
outBuffer.writeUInt8(81, 0);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018-2019 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -20,6 +20,7 @@ function amt_heci() {
|
|||||||
emitterUtils.createEvent('error');
|
emitterUtils.createEvent('error');
|
||||||
|
|
||||||
var heci = require('heci');
|
var heci = require('heci');
|
||||||
|
var sendConsole = function (msg) { try { require('MeshAgent').SendCommand({ "action": "msg", "type": "console", "value": msg }); } catch (ex) { } }
|
||||||
|
|
||||||
this._ObjectID = "pthi";
|
this._ObjectID = "pthi";
|
||||||
this._rq = new Q();
|
this._rq = new Q();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018-2019 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -64,7 +64,7 @@ function AMTScanner() {
|
|||||||
if (masknum <= 16 || masknum > 32) return null;
|
if (masknum <= 16 || masknum > 32) return null;
|
||||||
masknum = 32 - masknum;
|
masknum = 32 - masknum;
|
||||||
for (var i = 0; i < masknum; i++) { mask = (mask << 1); mask++; }
|
for (var i = 0; i < masknum; i++) { mask = (mask << 1); mask++; }
|
||||||
return { min: ip & (0xFFFFFFFF - mask), max: (ip & (0xFFFFFFFF - mask)) + mask };
|
return { min: (ip & (0xFFFFFFFF - mask))+1, max: (ip & (0xFFFFFFFF - mask)) + mask -1 };//remove network and broadcast address to avoid irrecoverable socket error
|
||||||
}
|
}
|
||||||
x = this.parseIpv4Addr(range);
|
x = this.parseIpv4Addr(range);
|
||||||
if (x == null) return null;
|
if (x == null) return null;
|
||||||
@@ -83,7 +83,7 @@ function AMTScanner() {
|
|||||||
return ((num >> 24) & 0xFF) + '.' + ((num >> 16) & 0xFF) + '.' + ((num >> 8) & 0xFF) + '.' + (num & 0xFF);
|
return ((num >> 24) & 0xFF) + '.' + ((num >> 16) & 0xFF) + '.' + ((num >> 8) & 0xFF) + '.' + (num & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scan = function (rangestr, timeout) {
|
this.scan = function (rangestr, timeout, callback) {
|
||||||
var iprange = this.parseIPv4Range(rangestr);
|
var iprange = this.parseIPv4Range(rangestr);
|
||||||
var rmcp = this.buildRmcpPing(0);
|
var rmcp = this.buildRmcpPing(0);
|
||||||
var server = this.dgram.createSocket({ type: 'udp4' });
|
var server = this.dgram.createSocket({ type: 'udp4' });
|
||||||
@@ -91,11 +91,15 @@ function AMTScanner() {
|
|||||||
server.scanResults = [];
|
server.scanResults = [];
|
||||||
server.on('error', function (err) { console.log('Error:' + err); });
|
server.on('error', function (err) { console.log('Error:' + err); });
|
||||||
server.on('message', function (msg, rinfo) { if (rinfo.size > 4) { this.parent.parseRmcpPacket(this, msg, rinfo, function (s, res) { s.scanResults.push(res); }) }; });
|
server.on('message', function (msg, rinfo) { if (rinfo.size > 4) { this.parent.parseRmcpPacket(this, msg, rinfo, function (s, res) { s.scanResults.push(res); }) }; });
|
||||||
server.on('listening', function () { for (var i = iprange.min; i <= iprange.max; i++) { server.send(rmcp, 623, server.parent.IPv4NumToStr(i)); } });
|
server.on('listening', function () { for (var i = iprange.min; i <= iprange.max; i++) {
|
||||||
|
server.send(rmcp, 623, server.parent.IPv4NumToStr(i)); } });
|
||||||
server.bind({ address: '0.0.0.0', port: 0, exclusive: true });
|
server.bind({ address: '0.0.0.0', port: 0, exclusive: true });
|
||||||
var tmout = setTimeout(function cb() {
|
var tmout = setTimeout(function cb() {
|
||||||
//console.log("Server closed");
|
//console.log("Server closed");
|
||||||
server.close();
|
server.close();
|
||||||
|
if (callback) {
|
||||||
|
callback(server.scanResults);
|
||||||
|
}
|
||||||
server.parent.emit('found', server.scanResults);
|
server.parent.emit('found', server.scanResults);
|
||||||
delete server;
|
delete server;
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018-2019 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -88,8 +88,10 @@ function CreateWsmanComm(/*host, port, user, pass, tls, extra*/)
|
|||||||
obj.digest.http = require('http');
|
obj.digest.http = require('http');
|
||||||
}
|
}
|
||||||
var request = { protocol: (obj.tls == 1 ? 'https:' : 'http:'), method: 'POST', host: obj.host, path: '/wsman', port: obj.port, rejectUnauthorized: false, checkServerIdentity: function (cert) { console.log('checkServerIdentity', JSON.stringify(cert)); } };
|
var request = { protocol: (obj.tls == 1 ? 'https:' : 'http:'), method: 'POST', host: obj.host, path: '/wsman', port: obj.port, rejectUnauthorized: false, checkServerIdentity: function (cert) { console.log('checkServerIdentity', JSON.stringify(cert)); } };
|
||||||
|
|
||||||
var req = obj.digest.request(request);
|
var req = obj.digest.request(request);
|
||||||
//console.log('Request ' + (obj.RequestCount++));
|
//console.log('Request ' + (obj.RequestCount++));
|
||||||
|
|
||||||
req.on('error', function (e) { obj.gotNextMessagesError({ status: 600 }, 'error', null, [postdata, callback, tag]); });
|
req.on('error', function (e) { obj.gotNextMessagesError({ status: 600 }, 'error', null, [postdata, callback, tag]); });
|
||||||
req.on('response', function (response) {
|
req.on('response', function (response) {
|
||||||
//console.log('Response: ' + response.statusCode);
|
//console.log('Response: ' + response.statusCode);
|
||||||
@@ -105,6 +107,7 @@ function CreateWsmanComm(/*host, port, user, pass, tls, extra*/)
|
|||||||
|
|
||||||
// Send POST body, this work with binary.
|
// Send POST body, this work with binary.
|
||||||
req.end(postdata);
|
req.end(postdata);
|
||||||
|
|
||||||
obj.ActiveAjaxCount++;
|
obj.ActiveAjaxCount++;
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018-2019 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -177,7 +177,7 @@ function WsmanStackCreateService(/*CreateWsmanComm, host, port, user, pass, tls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _PutObjToSelectorsXml(selectorSet) {
|
function _PutObjToSelectorsXml(selectorSet) {
|
||||||
if (!selectorSet) return '';
|
if ((selectorSet == null) || (selectorSet == 'null')) return '';
|
||||||
if (typeof selectorSet == 'string') return selectorSet;
|
if (typeof selectorSet == 'string') return selectorSet;
|
||||||
if (selectorSet['InstanceID']) return "<w:SelectorSet><w:Selector Name=\"InstanceID\">" + selectorSet['InstanceID'] + "</w:Selector></w:SelectorSet>";
|
if (selectorSet['InstanceID']) return "<w:SelectorSet><w:Selector Name=\"InstanceID\">" + selectorSet['InstanceID'] + "</w:Selector></w:SelectorSet>";
|
||||||
var result = '<w:SelectorSet>';
|
var result = '<w:SelectorSet>';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018-2019 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -121,65 +121,68 @@ function _getChildElementsByTagName(name) { var ret = []; if (this.childNodes !=
|
|||||||
function _getChildElementsByTagNameNS(ns, name) { var ret = []; if (this.childNodes != null) { for (var node in this.childNodes) { if (this.childNodes[node].localName == name && (ns == '*' || this.childNodes[node].namespace == ns)) { ret.push(this.childNodes[node]); } } } return (ret); }
|
function _getChildElementsByTagNameNS(ns, name) { var ret = []; if (this.childNodes != null) { for (var node in this.childNodes) { if (this.childNodes[node].localName == name && (ns == '*' || this.childNodes[node].namespace == ns)) { ret.push(this.childNodes[node]); } } } return (ret); }
|
||||||
function _xmlTraverseAllRec(nodes, func) { for (var i in nodes) { func(nodes[i]); if (nodes[i].childNodes) { _xmlTraverseAllRec(nodes[i].childNodes, func); } } }
|
function _xmlTraverseAllRec(nodes, func) { for (var i in nodes) { func(nodes[i]); if (nodes[i].childNodes) { _xmlTraverseAllRec(nodes[i].childNodes, func); } } }
|
||||||
function _turnToXmlRec(text) {
|
function _turnToXmlRec(text) {
|
||||||
var elementStack = new _treeBuilder(), lastElement = null, x1 = text.split('<'), ret = [], element = null, currentElementName = null;
|
try {
|
||||||
for (var i in x1) {
|
if (text == null) return null;
|
||||||
var x2 = x1[i].split('>'), x3 = x2[0].split(' '), elementName = x3[0];
|
var elementStack = new _treeBuilder(), lastElement = null, x1 = text.split('<'), ret = [], element = null, currentElementName = null;
|
||||||
if ((elementName.length > 0) && (elementName[0] != '?')) {
|
for (var i in x1) {
|
||||||
if (elementName[0] != '/') {
|
var x2 = x1[i].split('>'), x3 = x2[0].split(' '), elementName = x3[0];
|
||||||
var attributes = [], localName, localname2 = elementName.split(' ')[0].split(':'), localName = (localname2.length > 1) ? localname2[1] : localname2[0];
|
if ((elementName.length > 0) && (elementName[0] != '?')) {
|
||||||
Object.defineProperty(attributes, "get",
|
if (elementName[0] != '/') {
|
||||||
{
|
var attributes = [], localName, localname2 = elementName.split(' ')[0].split(':'), localName = (localname2.length > 1) ? localname2[1] : localname2[0];
|
||||||
value: function () {
|
Object.defineProperty(attributes, "get",
|
||||||
if (arguments.length == 1) {
|
{
|
||||||
for (var a in this) { if (this[a].name == arguments[0]) { return (this[a]); } }
|
value: function () {
|
||||||
}
|
if (arguments.length == 1) {
|
||||||
else if (arguments.length == 2) {
|
for (var a in this) { if (this[a].name == arguments[0]) { return (this[a]); } }
|
||||||
for (var a in this) { if (this[a].name == arguments[1] && (arguments[0] == '*' || this[a].namespace == arguments[0])) { return (this[a]); } }
|
}
|
||||||
}
|
else if (arguments.length == 2) {
|
||||||
else {
|
for (var a in this) { if (this[a].name == arguments[1] && (arguments[0] == '*' || this[a].namespace == arguments[0])) { return (this[a]); } }
|
||||||
throw ('attributes.get(): Invalid number of parameters');
|
}
|
||||||
}
|
else {
|
||||||
}
|
throw ('attributes.get(): Invalid number of parameters');
|
||||||
});
|
|
||||||
elementStack.push({ name: elementName, localName: localName, getChildElementsByTagName: _getChildElementsByTagName, getElementsByTagNameNS: _getElementsByTagNameNS, getChildElementsByTagNameNS: _getChildElementsByTagNameNS, attributes: attributes, childNodes: [], nsTable: {} });
|
|
||||||
// Parse Attributes
|
|
||||||
if (x3.length > 0) {
|
|
||||||
var skip = false;
|
|
||||||
for (var j in x3) {
|
|
||||||
if (x3[j] == '/') {
|
|
||||||
// This is an empty Element
|
|
||||||
elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':')));
|
|
||||||
elementStack.peek().textContent = '';
|
|
||||||
lastElement = elementStack.pop();
|
|
||||||
skip = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
var k = x3[j].indexOf('=');
|
|
||||||
if (k > 0) {
|
|
||||||
var attrName = x3[j].substring(0, k);
|
|
||||||
var attrValue = x3[j].substring(k + 2, x3[j].length - 1);
|
|
||||||
var attrNS = elementStack.getNamespace('*');
|
|
||||||
|
|
||||||
if (attrName == 'xmlns') {
|
|
||||||
elementStack.addNamespace('*', attrValue);
|
|
||||||
attrNS = attrValue;
|
|
||||||
} else if (attrName.startsWith('xmlns:')) {
|
|
||||||
elementStack.addNamespace(attrName.substring(6), attrValue);
|
|
||||||
} else {
|
|
||||||
var ax = attrName.split(':');
|
|
||||||
if (ax.length == 2) { attrName = ax[1]; attrNS = elementStack.getNamespace(ax[0]); }
|
|
||||||
}
|
}
|
||||||
var x = { name: attrName, value: attrValue }
|
|
||||||
if (attrNS != null) x.namespace = attrNS;
|
|
||||||
elementStack.peek().attributes.push(x);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
elementStack.push({ name: elementName, localName: localName, getChildElementsByTagName: _getChildElementsByTagName, getElementsByTagNameNS: _getElementsByTagNameNS, getChildElementsByTagNameNS: _getChildElementsByTagNameNS, attributes: attributes, childNodes: [], nsTable: {} });
|
||||||
|
// Parse Attributes
|
||||||
|
if (x3.length > 0) {
|
||||||
|
var skip = false;
|
||||||
|
for (var j in x3) {
|
||||||
|
if (x3[j] == '/') {
|
||||||
|
// This is an empty Element
|
||||||
|
elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':')));
|
||||||
|
elementStack.peek().textContent = '';
|
||||||
|
lastElement = elementStack.pop();
|
||||||
|
skip = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var k = x3[j].indexOf('=');
|
||||||
|
if (k > 0) {
|
||||||
|
var attrName = x3[j].substring(0, k);
|
||||||
|
var attrValue = x3[j].substring(k + 2, x3[j].length - 1);
|
||||||
|
var attrNS = elementStack.getNamespace('*');
|
||||||
|
|
||||||
|
if (attrName == 'xmlns') {
|
||||||
|
elementStack.addNamespace('*', attrValue);
|
||||||
|
attrNS = attrValue;
|
||||||
|
} else if (attrName.startsWith('xmlns:')) {
|
||||||
|
elementStack.addNamespace(attrName.substring(6), attrValue);
|
||||||
|
} else {
|
||||||
|
var ax = attrName.split(':');
|
||||||
|
if (ax.length == 2) { attrName = ax[1]; attrNS = elementStack.getNamespace(ax[0]); }
|
||||||
|
}
|
||||||
|
var x = { name: attrName, value: attrValue }
|
||||||
|
if (attrNS != null) x.namespace = attrNS;
|
||||||
|
elementStack.peek().attributes.push(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (skip) { continue; }
|
||||||
}
|
}
|
||||||
if (skip) { continue; }
|
elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':')));
|
||||||
}
|
if (x2[1]) { elementStack.peek().textContent = x2[1]; }
|
||||||
elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':')));
|
} else { lastElement = elementStack.pop(); }
|
||||||
if (x2[1]) { elementStack.peek().textContent = x2[1]; }
|
}
|
||||||
} else { lastElement = elementStack.pop(); }
|
|
||||||
}
|
}
|
||||||
}
|
} catch (ex) { return null; }
|
||||||
return lastElement;
|
return lastElement;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018-2019 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2019 Intel Corporation
|
Copyright 2019-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -191,7 +191,12 @@ function SMBiosTables()
|
|||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
if (JSON.stringify(r).length > 65535) { r = {}; }
|
try
|
||||||
|
{
|
||||||
|
if (JSON.stringify(r).length > 65535) { r = {}; }
|
||||||
|
}
|
||||||
|
catch(ee)
|
||||||
|
{}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
this.processorInfo = function processorInfo(data) {
|
this.processorInfo = function processorInfo(data) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2019 Intel Corporation
|
Copyright 2019-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const PDH_FMT_LONG = 0x00000100;
|
var PDH_FMT_LONG = 0x00000100;
|
||||||
const PDH_FMT_DOUBLE = 0x00000200;
|
var PDH_FMT_DOUBLE = 0x00000200;
|
||||||
|
|
||||||
var promise = require('promise');
|
var promise = require('promise');
|
||||||
if (process.platform == 'win32')
|
if (process.platform == 'win32')
|
||||||
@@ -72,11 +72,11 @@ function windows_cpuUtilization()
|
|||||||
szName = item.Deref(0, GM.PointerSize).Deref();
|
szName = item.Deref(0, GM.PointerSize).Deref();
|
||||||
if (szName.String == '_Total')
|
if (szName.String == '_Total')
|
||||||
{
|
{
|
||||||
u.total = item.Deref(16, 8).toBuffer().readDoubleLE().toFixed(2);
|
u.total = item.Deref(16, 8).toBuffer().readDoubleLE();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
u.cpus[parseInt(szName.String)] = item.Deref(16, 8).toBuffer().readDoubleLE().toFixed(2);
|
u.cpus[parseInt(szName.String)] = item.Deref(16, 8).toBuffer().readDoubleLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +99,8 @@ function windows_memUtilization()
|
|||||||
MemFree: require('bignum').fromBuffer(info.Deref(16, 8).toBuffer(), { endian: 'little' })
|
MemFree: require('bignum').fromBuffer(info.Deref(16, 8).toBuffer(), { endian: 'little' })
|
||||||
};
|
};
|
||||||
|
|
||||||
ret.percentFree = ((ret.MemFree.div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100).toFixed(2);
|
ret.percentFree = ((ret.MemFree.div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100);//.toFixed(2);
|
||||||
ret.percentConsumed = ((ret.MemTotal.sub(ret.MemFree).div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100).toFixed(2);
|
ret.percentConsumed = ((ret.MemTotal.sub(ret.MemFree).div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100);//.toFixed(2);
|
||||||
ret.MemTotal = ret.MemTotal.toString();
|
ret.MemTotal = ret.MemTotal.toString();
|
||||||
ret.MemFree = ret.MemFree.toString();
|
ret.MemFree = ret.MemFree.toString();
|
||||||
return (ret);
|
return (ret);
|
||||||
@@ -123,7 +123,7 @@ function linux_cpuUtilization()
|
|||||||
while (columns[++x] == '');
|
while (columns[++x] == '');
|
||||||
for (y = x; y < columns.length; ++y) { sum += parseInt(columns[y]); }
|
for (y = x; y < columns.length; ++y) { sum += parseInt(columns[y]); }
|
||||||
idle = parseInt(columns[3 + x]);
|
idle = parseInt(columns[3 + x]);
|
||||||
utilization = (100 - ((idle / sum) * 100)).toFixed(2);
|
utilization = (100 - ((idle / sum) * 100)); //.toFixed(2);
|
||||||
if (!ret.total)
|
if (!ret.total)
|
||||||
{
|
{
|
||||||
ret.total = utilization;
|
ret.total = utilization;
|
||||||
@@ -157,8 +157,8 @@ function linux_memUtilization()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.percentFree = ((ret.free / ret.total) * 100).toFixed(2);
|
ret.percentFree = ((ret.free / ret.total) * 100);//.toFixed(2);
|
||||||
ret.percentConsumed = (((ret.total - ret.free) / ret.total) * 100).toFixed(2);
|
ret.percentConsumed = (((ret.total - ret.free) / ret.total) * 100);//.toFixed(2);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,8 +205,8 @@ function macos_memUtilization()
|
|||||||
|
|
||||||
mem.MemTotal = parseInt(bdown[0].trim().split(' ')[0]);
|
mem.MemTotal = parseInt(bdown[0].trim().split(' ')[0]);
|
||||||
mem.MemFree = parseInt(bdown[1].trim().split(' ')[0]);
|
mem.MemFree = parseInt(bdown[1].trim().split(' ')[0]);
|
||||||
mem.percentFree = ((mem.MemFree / mem.MemTotal) * 100).toFixed(2);
|
mem.percentFree = ((mem.MemFree / mem.MemTotal) * 100);//.toFixed(2);
|
||||||
mem.percentConsumed = (((mem.MemTotal - mem.MemFree)/ mem.MemTotal) * 100).toFixed(2);
|
mem.percentConsumed = (((mem.MemTotal - mem.MemFree) / mem.MemTotal) * 100);//.toFixed(2);
|
||||||
return (mem);
|
return (mem);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 Intel Corporation
|
Copyright 2018-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2019 Intel Corporation
|
Copyright 2019-2020 Intel Corporation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
Reference in New Issue
Block a user