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

This commit is contained in:
Alexey Kasyanchuk
2017-08-24 09:26:03 +03:00
parent 69a2ad1c54
commit 716c820e5b
2 changed files with 14 additions and 0 deletions

View File

@ -71,6 +71,10 @@ 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

@ -44,6 +44,7 @@ class Spider extends Emiter {
this.client = client this.client = client
this.ignore = false; // ignore all requests this.ignore = false; // ignore all requests
this.initialized = false; this.initialized = false;
this.traffic = 0;
this.walkInterval = config.spider.walkInterval; this.walkInterval = config.spider.walkInterval;
this.cpuLimit = config.spider.cpuLimit; this.cpuLimit = config.spider.cpuLimit;
@ -205,6 +206,7 @@ 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(() => {
@ -214,6 +216,14 @@ class Spider extends Emiter {
}, 3000) }, 3000)
this.join() this.join()
this.walk() this.walk()
setInterval(() => {
console.log(this.traffic / 1024, 'kb/s')
this.traffic = 0
}, 1000)
if(this.client)
this.client.on('traffic', (traffic) => {
this.traffic += traffic
})
} }
} }