Revert "тестовая проверка трафика"

This reverts commit 716c820e5b.

эксперементальный трафик
This commit is contained in:
Alexey Kasyanchuk 2017-08-24 10:03:30 +03:00
parent 716c820e5b
commit c11a60ea63
2 changed files with 15 additions and 11 deletions

View File

@ -71,10 +71,6 @@ class Client extends Emiter
socket.destroy(); socket.destroy();
}); });
socket.on('data', (data) => {
this.emit('traffic', data.length);
})
socket.on('timeout', (err) => { socket.on('timeout', (err) => {
socket.destroy(); socket.destroy();
}); });

View File

@ -7,6 +7,7 @@ const {Table, Node} = require('./table')
const Token = require('./token') const Token = require('./token')
const cpuUsage = require('./cpu-usage') const cpuUsage = require('./cpu-usage')
const config = require('../config') const config = require('../config')
const fs = require('fs')
const _debug = require('debug') const _debug = require('debug')
const cpuDebug = _debug('cpu') const cpuDebug = _debug('cpu')
@ -45,6 +46,7 @@ class Spider extends Emiter {
this.ignore = false; // ignore all requests this.ignore = false; // ignore all requests
this.initialized = false; this.initialized = false;
this.traffic = 0; this.traffic = 0;
this.trafficSpeed = 0
this.walkInterval = config.spider.walkInterval; this.walkInterval = config.spider.walkInterval;
this.cpuLimit = config.spider.cpuLimit; this.cpuLimit = config.spider.cpuLimit;
@ -206,7 +208,6 @@ class Spider extends Emiter {
}) })
this.udp.on('message', (data, addr) => { this.udp.on('message', (data, addr) => {
this.parse(data, addr) this.parse(data, addr)
this.traffic += data.length
}) })
this.udp.on('error', (err) => {}) this.udp.on('error', (err) => {})
setInterval(() => { setInterval(() => {
@ -217,13 +218,20 @@ class Spider extends Emiter {
this.join() this.join()
this.walk() this.walk()
setInterval(() => { setInterval(() => {
console.log(this.traffic / 1024, 'kb/s') fs.readFile('/sys/class/net/enp2s0/statistics/rx_bytes', (err, data) => {
this.traffic = 0 if(!err)
}, 1000) return
if(this.client)
this.client.on('traffic', (traffic) => { if(this.traffic === 0)
this.traffic += traffic this.traffic = data
this.trafficSpeed = data - this.traffic
console.log(this.trafficSpeed / 1024, 'kbps/s')
this.traffic = data
}) })
}, 1000)
} }
} }