new major version 4.0
This commit is contained in:
+51
-1
@@ -203,10 +203,60 @@ function docker_calcBlockIO(blkio_stats) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function dockerContainerStats(containerIDs, callback) {
|
||||
|
||||
let containerArray = [];
|
||||
// fallback - if only callback is given
|
||||
if (util.isFunction(containerIDs) && !callback) {
|
||||
callback = containerIDs;
|
||||
containerIDs = '*';
|
||||
} else {
|
||||
containerIDs = containerIDs || '*';
|
||||
containerIDs = containerIDs.trim().toLowerCase().replace(/,+/g, '|');
|
||||
containerArray = containerIDs.split('|');
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
|
||||
const result = [];
|
||||
|
||||
const workload = [];
|
||||
if (containerArray.length && containerArray[0].trim() === '*') {
|
||||
containerArray = [];
|
||||
dockerContainers().then(allContainers => {
|
||||
for (let container of allContainers) {
|
||||
containerArray.push(container.id);
|
||||
}
|
||||
dockerContainerStats(containerArray.join(',')).then(result => {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
for (let containerID of containerArray) {
|
||||
workload.push(dockerContainerStatsSingle(containerID.trim()));
|
||||
}
|
||||
if (workload.length) {
|
||||
Promise.all(
|
||||
workload
|
||||
).then(data => {
|
||||
if (callback) { callback(data); }
|
||||
resolve(data);
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// container stats (for one container)
|
||||
|
||||
function dockerContainerStats(containerID, callback) {
|
||||
function dockerContainerStatsSingle(containerID, callback) {
|
||||
containerID = containerID || '';
|
||||
let result = {
|
||||
id: containerID,
|
||||
|
||||
Vendored
+13
-1
@@ -39,6 +39,16 @@ export namespace Systeminformation {
|
||||
assetTag: string;
|
||||
}
|
||||
|
||||
interface ChassisData {
|
||||
manufacturer: string;
|
||||
model: string;
|
||||
type: string;
|
||||
version: string;
|
||||
serial: string;
|
||||
assetTag: string;
|
||||
sku: string;
|
||||
}
|
||||
|
||||
// 3. CPU, Memory, Disks, Battery, Graphics
|
||||
|
||||
interface CpuData {
|
||||
@@ -446,6 +456,7 @@ export namespace Systeminformation {
|
||||
system: SystemData;
|
||||
bios: BiosData;
|
||||
baseboard: BaseboardData;
|
||||
chassis: ChassisData;
|
||||
os: OsData;
|
||||
uuid: UuidData;
|
||||
versions: VersionData;
|
||||
@@ -462,6 +473,7 @@ export function version(): string;
|
||||
export function system(cb?: (data: Systeminformation.SystemData) => any): Promise<Systeminformation.SystemData>;
|
||||
export function bios(cb?: (data: Systeminformation.BiosData) => any): Promise<Systeminformation.BiosData>;
|
||||
export function baseboard(cb?: (data: Systeminformation.BaseboardData) => any): Promise<Systeminformation.BaseboardData>;
|
||||
export function chassis(cb?: (data: Systeminformation.ChassisData) => any): Promise<Systeminformation.ChassisData>;
|
||||
|
||||
export function time(): Systeminformation.TimeData;
|
||||
export function osInfo(cb?: (data: Systeminformation.OsData) => any): Promise<Systeminformation.OsData>;
|
||||
@@ -492,7 +504,7 @@ export function diskLayout(cb?: (data: Systeminformation.DiskLayoutData) => any)
|
||||
export function networkInterfaceDefault(cb?: (data: string) => any): Promise<string>;
|
||||
export function networkInterfaces(cb?: (data: Systeminformation.NetworkInterfacesData[]) => any): Promise<Systeminformation.NetworkInterfacesData[]>;
|
||||
|
||||
export function networkStats(iface?: string, cb?: (data: Systeminformation.NetworkStatsData) => any): Promise<Systeminformation.NetworkStatsData>;
|
||||
export function networkStats(ifaces?: string, cb?: (data: Systeminformation.NetworkStatsData[]) => any): Promise<Systeminformation.NetworkStatsData[]>;
|
||||
export function networkConnections(cb?: (data: Systeminformation.NetworkConnectionsData[]) => any): Promise<Systeminformation.NetworkConnectionsData[]>;
|
||||
export function inetChecksite(url: string, cb?: (data: Systeminformation.InetChecksiteData) => any): Promise<Systeminformation.InetChecksiteData>;
|
||||
export function inetLatency(host?: string, cb?: (data: number) => any): Promise<number>;
|
||||
|
||||
+52
-16
@@ -341,7 +341,7 @@ function networkInterfaces(callback) {
|
||||
try {
|
||||
lines = execSync(cmd).toString().split('\n');
|
||||
} catch (e) {
|
||||
|
||||
util.noop();
|
||||
}
|
||||
duplex = util.getValue(lines, 'duplex');
|
||||
duplex = duplex.startsWith('cat') ? '' : duplex;
|
||||
@@ -456,7 +456,57 @@ function calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_e
|
||||
return result;
|
||||
}
|
||||
|
||||
function networkStats(iface, callback) {
|
||||
function networkStats(ifaces, callback) {
|
||||
|
||||
let ifacesArray = [];
|
||||
// fallback - if only callback is given
|
||||
if (util.isFunction(ifaces) && !callback) {
|
||||
callback = ifaces;
|
||||
ifaces = [getDefaultNetworkInterface()];
|
||||
} else {
|
||||
ifaces = ifaces || getDefaultNetworkInterface();
|
||||
ifaces = ifaces.trim().toLowerCase().replace(/,+/g, '|');
|
||||
ifacesArray = ifaces.split('|');
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
|
||||
const result = [];
|
||||
|
||||
const workload = [];
|
||||
if (ifacesArray.length && ifacesArray[0].trim() === '*') {
|
||||
ifacesArray = [];
|
||||
networkInterfaces().then(allIFaces => {
|
||||
for (let iface of allIFaces) {
|
||||
ifacesArray.push(iface.iface);
|
||||
}
|
||||
networkStats(ifacesArray.join(',')).then(result => {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
for (let iface of ifacesArray) {
|
||||
workload.push(networkStatsSingle(iface.trim()));
|
||||
}
|
||||
if (workload.length) {
|
||||
Promise.all(
|
||||
workload
|
||||
).then(data => {
|
||||
if (callback) { callback(data); }
|
||||
resolve(data);
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function networkStatsSingle(iface) {
|
||||
|
||||
function parseLinesWindowsPerfData(sections) {
|
||||
let perfData = [];
|
||||
@@ -480,17 +530,9 @@ function networkStats(iface, callback) {
|
||||
return perfData;
|
||||
}
|
||||
|
||||
// fallback - if only callback is given
|
||||
if (util.isFunction(iface) && !callback) {
|
||||
callback = iface;
|
||||
iface = '';
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
|
||||
iface = iface || getDefaultNetworkInterface();
|
||||
|
||||
let result = {
|
||||
iface: iface,
|
||||
operstate: 'unknown',
|
||||
@@ -539,11 +581,9 @@ function networkStats(iface, callback) {
|
||||
result = calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
|
||||
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
@@ -566,7 +606,6 @@ function networkStats(iface, callback) {
|
||||
}
|
||||
result = calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
@@ -595,7 +634,6 @@ function networkStats(iface, callback) {
|
||||
result = calcNetworkSpeed(iface, rx_bytes, tx_bytes, result.operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
@@ -635,7 +673,6 @@ function networkStats(iface, callback) {
|
||||
if (rx_bytes && tx_bytes) {
|
||||
result = calcNetworkSpeed(ifaceName, parseInt(rx_bytes), parseInt(tx_bytes), operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
@@ -647,7 +684,6 @@ function networkStats(iface, callback) {
|
||||
result.tx_sec = _network[iface].tx_sec;
|
||||
result.ms = _network[iface].last_ms;
|
||||
result.operstate = _network[iface].operstate;
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user