Skip to content

Commit

Permalink
Use light version of nmap scan (--version-light)
Browse files Browse the repository at this point in the history
Fix bug accessing the storage performance stats on a non-win32 machine
  • Loading branch information
davidreis97 committed Mar 18, 2020
1 parent 5810a35 commit 58f05c9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dockerfile-utils/src/dynamicAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ export class DynamicAnalysis {
return;
}

this.container.inspect((err, data) => {
this.container.inspect(async (err, data) => {
if (this.isDestroyed) {
this.sendProgress(true);
return;
Expand All @@ -604,9 +604,11 @@ export class DynamicAnalysis {

let tcpMappedPorts = mappedPorts.filter((_value, index, _array) => protocols[index] == "tcp");

await new Promise(r => setTimeout(r, 500)); //!- Waits 800ms - arbitrary measure

this.sendProgress("Running nmap...");

const nmapCommand = `nmap -oX - 127.0.0.1 -p ${tcpMappedPorts.join(",")} -sV`;
const nmapCommand = `nmap -oX - 127.0.0.1 -p ${tcpMappedPorts.join(",")} -sV --version-light`;

this.debugLog("Running: " + nmapCommand);

Expand Down Expand Up @@ -702,15 +704,15 @@ export class DynamicAnalysis {
}

//Based on https://github.com/moby/moby/blob/eb131c5383db8cac633919f82abad86c99bffbe5/cli/command/container/stats_helpers.go#L106-L125
private calculateStorage(stats) {
private calculateStorage(stats) { //! TODO - Test a container which actually uses storage
let readBytes = 0;
let writeBytes = 0;

if (process.platform === "win32") {
readBytes = stats.storage_stats.read_size_bytes || 0;
writeBytes = stats.storage_stats.write_size_bytes || 0;
} else {
for (let entry of stats.io_service_bytes_recursive) {
for (let entry of stats.blkio_stats.io_service_bytes_recursive) {
if (entry.op == "read") {
readBytes += entry.value;
} else if (entry.op == "write") {
Expand Down

0 comments on commit 58f05c9

Please sign in to comment.