New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hyperledger/caliper-core

Package Overview
Dependencies
Maintainers
4
Versions
304
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hyperledger/caliper-core - npm Package Compare versions

Comparing version 0.5.0-unstable-20220415132826 to 0.5.0-unstable-20220425152914

174

lib/manager/monitors/monitor-docker.js

@@ -26,3 +26,2 @@ /*

const Docker = require('dockerode');
const SystemInformation = require('systeminformation');

@@ -67,3 +66,3 @@ /**

this.containers = [];
let filterName = { local: [], remote: {} };
let filterName = {};
// Split docker items that are local or remote

@@ -79,9 +78,13 @@ if (this.options.hasOwnProperty('containers')) {

} else if (filterName.remote.hasOwnProperty(remote.hostname)) {
filterName.remote[remote.hostname].containers.push(remote.pathname);
filterName[remote.hostname].containers.push(remote.pathname);
} else {
filterName.remote[remote.hostname] = { port: remote.port, containers: [remote.pathname] };
filterName[remote.hostname] = { port: remote.port, containers: [remote.pathname] };
}
} else {
// Is local
filterName.local.push(container);
if (filterName.hasOwnProperty('localhost')) {
filterName.localhost.containers.push(container);
} else {
filterName.localhost = { containers: [container] };
}
}

@@ -91,48 +94,35 @@ }

// Filter local containers by name
if (filterName.local.length > 0) {
// Filter containers by name
for (let hostname in filterName) {
try {
const containers = await SystemInformation.dockerContainers('active');
let size = containers.length;
if (size === 0) {
Logger.error('Could not find any active local containers');
let docker;
if (hostname === 'localhost'){
// Instantiate for local host
docker = new Docker({});
} else {
if (filterName.local.indexOf('all') !== -1) {
// Add all containers
for (let i = 0; i < size; i++) {
this.containers.push({ id: containers[i].id, name: containers[i].name, remote: null });
this.stats[containers[i].id] = this.newContainerStat();
}
} else {
// Filter containers
for (let i = 0; i < size; i++) {
if (filterName.local.indexOf(containers[i].name) !== -1) {
this.containers.push({ id: containers[i].id, name: containers[i].name, remote: null });
this.stats[containers[i].id] = this.newContainerStat();
}
}
}
// Instantiate for the host/port
docker = new Docker({
host: hostname,
port: filterName[hostname].port
});
}
} catch (error) {
Logger.error(`Error retrieving local containers: ${error}`);
}
}
// Filter remote containers by name
for (let h in filterName.remote) {
try {
// Instantiate for the host/port
let docker = new Docker({
host: h,
port: filterName.remote[h].port
});
// Retrieve and filter containers
// Retrieve and filter containers
const containers = await docker.listContainers();
const simplifyName = (host, containerName) => {
if (host === 'localhost') {
return containerName;
}
return host + containerName;
};
if (containers.length === 0) {
Logger.error('monitor-docker: could not find remote container at ' + h);
Logger.error('monitor-docker: could not find container at' + hostname);
} else {
if (filterName.remote[h].containers.indexOf('/all') !== -1) {
if (filterName[hostname].containers.indexOf('all') !== -1) {
for (let i = 0; i < containers.length; i++) {
let container = docker.getContainer(containers[i].Id);
this.containers.push({ id: containers[i].Id, name: h + containers[i].Names[0], remote: container });
this.containers.push({ id: containers[i].Id, name: simplifyName(hostname, containers[i].Names[0]), container: container });
this.stats[containers[i].Id] = this.newContainerStat();

@@ -142,5 +132,5 @@ }

for (let i = 0; i < containers.length; i++) {
if (filterName.remote[h].containers.indexOf(containers[i].Names[0]) !== -1) {
if (filterName[hostname].containers.indexOf(containers[i].Names[0]) !== -1) {
let container = docker.getContainer(containers[i].Id);
this.containers.push({ id: containers[i].Id, name: h + containers[i].Names[0], remote: container });
this.containers.push({ id: containers[i].Id, name: simplifyName(hostname, containers[i].Names[0]), container: container });
this.stats[containers[i].Id] = this.newContainerStat();

@@ -152,3 +142,3 @@ }

} catch (error) {
Logger.error(`Error retrieving remote containers: ${error}`);
Logger.error(`Error retrieving containers: ${error}`);
}

@@ -187,9 +177,3 @@ }

for (let i = 0; i < this.containers.length; i++) {
if (this.containers[i].remote === null) {
// local
startPromises.push(SystemInformation.dockerContainerStats(this.containers[i].id));
} else {
// remote
startPromises.push(this.containers[i].remote.stats({ stream: false }));
}
startPromises.push(this.containers[i].container.stats({ stream: false }));
}

@@ -201,2 +185,3 @@

let stat = results[i];
let id = stat.id;

@@ -210,64 +195,41 @@ if (this.containers.length <= i) {

}
if (this.containers[i].remote === null) {
// local
const actualMemUsage = stat.memory_stats.usage - stat.memory_stats.stats.cache;
this.stats[id].mem_usage.push(actualMemUsage);
this.stats[id].mem_percent.push(actualMemUsage / stat.mem_limit);
let cpuDelta = stat.cpu_stats.cpu_usage.total_usage - stat.precpu_stats.cpu_usage.total_usage;
let sysDelta = stat.cpu_stats.system_cpu_usage - stat.precpu_stats.system_cpu_usage;
if (cpuDelta > 0 && sysDelta > 0) {
if (stat.cpu_stats.cpu_usage.hasOwnProperty('percpu_usage') && stat.cpu_stats.cpu_usage.percpu_usage !== null) {
this.stats[id].cpu_percent.push(cpuDelta / sysDelta * this.coresInUse(stat.cpu_stats) * 100.0);
} else {
this.stats[id].cpu_percent.push(cpuDelta / sysDelta * 100.0);
}
// get stats
const actualMemUsage = stat.memory_stats.usage - stat.memory_stats.stats.inactive_file;
this.stats[id].mem_usage.push(actualMemUsage);
this.stats[id].mem_percent.push(actualMemUsage / stat.mem_limit);
let cpuDelta = stat.cpu_stats.cpu_usage.total_usage - stat.precpu_stats.cpu_usage.total_usage;
let sysDelta = stat.cpu_stats.system_cpu_usage - stat.precpu_stats.system_cpu_usage;
if (cpuDelta > 0 && sysDelta > 0) {
if (stat.cpu_stats.cpu_usage.hasOwnProperty('percpu_usage') && stat.cpu_stats.cpu_usage.percpu_usage !== null) {
// this.stats[id].cpu_percent.push(cpuDelta / sysDelta * stat.cpu_stats.cpu_usage.percpu_usage.length * 100.0);
this.stats[id].cpu_percent.push(cpuDelta / sysDelta * this.coresInUse(stat.cpu_stats) * 100.0);
} else {
this.stats[id].cpu_percent.push(0);
this.stats[id].cpu_percent.push(cpuDelta / sysDelta * 100.0);
}
this.stats[id].netIO_rx.push(stat.netIO.rx);
this.stats[id].netIO_tx.push(stat.netIO.tx);
this.stats[id].blockIO_rx.push(stat.blockIO.r);
this.stats[id].blockIO_wx.push(stat.blockIO.w);
} else {
// remote
const actualMemUsage = stat.memory_stats.usage - stat.memory_stats.stats.cache;
this.stats[id].mem_usage.push(actualMemUsage);
this.stats[id].mem_percent.push(actualMemUsage / stat.mem_limit);
//this.stats[id].cpu_percent.push((stat.cpu_stats.cpu_usage.total_usage - stat.precpu_stats.cpu_usage.total_usage) / (stat.cpu_stats.system_cpu_usage - stat.precpu_stats.system_cpu_usage) * 100);
let cpuDelta = stat.cpu_stats.cpu_usage.total_usage - stat.precpu_stats.cpu_usage.total_usage;
let sysDelta = stat.cpu_stats.system_cpu_usage - stat.precpu_stats.system_cpu_usage;
if (cpuDelta > 0 && sysDelta > 0) {
if (stat.cpu_stats.cpu_usage.hasOwnProperty('percpu_usage') && stat.cpu_stats.cpu_usage.percpu_usage !== null) {
// this.stats[id].cpu_percent.push(cpuDelta / sysDelta * stat.cpu_stats.cpu_usage.percpu_usage.length * 100.0);
this.stats[id].cpu_percent.push(cpuDelta / sysDelta * this.coresInUse(stat.cpu_stats) * 100.0);
} else {
this.stats[id].cpu_percent.push(cpuDelta / sysDelta * 100.0);
this.stats[id].cpu_percent.push(0);
}
let ioRx = 0, ioTx = 0;
for (let eth in stat.networks) {
ioRx += stat.networks[eth].rx_bytes;
ioTx += stat.networks[eth].tx_bytes;
}
this.stats[id].netIO_rx.push(ioRx);
this.stats[id].netIO_tx.push(ioTx);
let diskR = 0, diskW = 0;
if (stat.blkio_stats && stat.blkio_stats.hasOwnProperty('io_service_bytes_recursive')) {
//Logger.debug(stat.blkio_stats.io_service_bytes_recursive);
let temp = stat.blkio_stats.io_service_bytes_recursive;
for (let dIo = 0; dIo < temp.length; dIo++) {
if (temp[dIo].op.toLowerCase() === 'read') {
diskR += temp[dIo].value;
}
} else {
this.stats[id].cpu_percent.push(0);
}
let ioRx = 0, ioTx = 0;
for (let eth in stat.networks) {
ioRx += stat.networks[eth].rx_bytes;
ioTx += stat.networks[eth].tx_bytes;
}
this.stats[id].netIO_rx.push(ioRx);
this.stats[id].netIO_tx.push(ioTx);
let diskR = 0, diskW = 0;
if (stat.blkio_stats && stat.blkio_stats.hasOwnProperty('io_service_bytes_recursive')) {
//Logger.debug(stat.blkio_stats.io_service_bytes_recursive);
let temp = stat.blkio_stats.io_service_bytes_recursive;
for (let dIo = 0; dIo < temp.length; dIo++) {
if (temp[dIo].op.toLowerCase() === 'read') {
diskR += temp[dIo].value;
}
if (temp[dIo].op.toLowerCase() === 'write') {
diskW += temp[dIo].value;
}
if (temp[dIo].op.toLowerCase() === 'write') {
diskW += temp[dIo].value;
}
}
//Logger.debug(diskR+' W: '+diskW);
this.stats[id].blockIO_rx.push(diskR);
this.stats[id].blockIO_wx.push(diskW);
}
//Logger.debug(diskR+' W: '+diskW);
this.stats[id].blockIO_rx.push(diskR);
this.stats[id].blockIO_wx.push(diskW);
}

@@ -274,0 +236,0 @@ this.isReading = false;

{
"name": "@hyperledger/caliper-core",
"description": "Core Hyperledger Caliper module, used for running performance benchmarks that interact with blockchain technologies",
"version": "0.5.0-unstable-20220415132826",
"version": "0.5.0-unstable-20220425152914",
"repository": {

@@ -27,3 +27,3 @@ "type": "git",

"compare-versions": "^3.4.0",
"dockerode": "3.1.0",
"dockerode": "3.3.1",
"express": "4.17.1",

@@ -39,3 +39,2 @@ "js-yaml": "^3.13.1",

"ps-node": "^0.1.6",
"systeminformation": "^3.23.7",
"table": "^4.0.1",

@@ -42,0 +41,0 @@ "winston": "^3.2.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc