Skip to content

Commit

Permalink
stats for delay and version
Browse files Browse the repository at this point in the history
  • Loading branch information
roks0n committed May 5, 2019
1 parent 8992211 commit a1267b3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
39 changes: 36 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -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]) {
Expand All @@ -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`)

Expand Down
7 changes: 5 additions & 2 deletions src/crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a1267b3

Please sign in to comment.