From a1267b31beb17d3778550cae51e1e241fda4920f Mon Sep 17 00:00:00 2001 From: roks0n Date: Sun, 5 May 2019 21:57:11 +0200 Subject: [PATCH] stats for delay and version --- app.js | 39 ++++++++++++++++++++++++++++++++++++--- src/crawler.js | 7 +++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index c331ecd..7140651 100644 --- a/app.js +++ b/app.js @@ -1,11 +1,13 @@ const Crawler = require('./src/crawler') const { URL } = require('url') +const { orderBy } = require('lodash/collection') const crawler = new Crawler() const args = process.argv.slice(2) const report = (crawler) => { const blockStats = {} + const versionStats = {} for (const item of crawler.heights) { if (blockStats[item.height]) { @@ -17,19 +19,50 @@ const report = (crawler) => { blockStats[item.height].ids = {} blockStats[item.height].ids[item.id] = 1 } + + if (versionStats[item.version]) { + versionStats[item.version].count += 1 + } else { + versionStats[item.version] = { + count: 1, + version: item.version + } + } } + const allDelays = crawler.heights.filter(item => item.delay).map(item => item.delay) + const averageDelay = allDelays.reduce((a, b) => a + b, 0) / allDelays.length + const maxDelay = Math.max(...allDelays) + const minDelay = Math.min(...allDelays) + console.log(`===========================================`) console.log(`Total nodes visited: ${Object.keys(crawler.nodes).length}`) console.log(`Total nodes online: ${crawler.heights.length}`) console.log(`------------------------------------------`) - console.log(`Block stats:`) + + // height/block stats + console.log(`Height and block stats:`) for (const stat in blockStats) { - console.log(`${blockStats[stat].count} nodes on height ${stat} with hashes:`) + console.log(` ${blockStats[stat].count} nodes on height ${stat} with hashes:`) for (const hash in blockStats[stat].ids) { - console.log(` - ${hash} (${blockStats[stat].ids[hash]} nodes)`) + console.log(` - ${hash} (${blockStats[stat].ids[hash]} nodes)`) } } + + // version stats + console.log(``) + console.log(`Version stats:`) + for (const stat of orderBy(Object.values(versionStats))) { + console.log(` - ${stat.count} nodes on version ${stat.version}`) + } + + // delay stats + console.log(``) + console.log(`Delay`) + console.log(` Average delay: ${averageDelay}`) + console.log(` Min delay: ${minDelay}`) + console.log(` Max delay: ${maxDelay}`) + console.log(`------------------------------------------`) console.log(`Finished scanning in ${new Date() - crawler.startTime}ms`) diff --git a/src/crawler.js b/src/crawler.js index 9428bd9..1363890 100644 --- a/src/crawler.js +++ b/src/crawler.js @@ -6,7 +6,7 @@ class Crawler { * Initializes the internal request reactor. * @method constructor */ - constructor (timeout = 5000) { + constructor (timeout = 3000) { this._counter = 0 this._queue = [] this.timeout = timeout @@ -196,7 +196,10 @@ class Crawler { if (response.status === 200 && response.data && response.data.height) { this.heights.push({ height: response.data.height, - id: response.data.id + id: response.data.id, + version: node.version, + os: node.os, + delay: node.delay }) return Promise.resolve() } else {