UNPKG

2.18 kBJavaScriptView Raw
1/*
2 * Copyright (c) 2012 Dmitri Melikyan
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to permit
9 * persons to whom the Software is furnished to do so, subject to the
10 * following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25var nt = require('../nodetime');
26var proxy = require('../proxy');
27var samples = require('../samples');
28var info = require('../info');
29
30module.exports = function(obj) {
31 return; // needs rethinking
32
33 proxy.after(obj, ['connect', 'createConnection'], function(obj, args, ret) {
34 proxy.before(ret, 'write', function(obj, args) {
35 if(nt.paused) return;
36
37 if(args.length < 1) return;
38
39 info.metric('Sockets', 'Data sent per minute', size(args[0]), 'KB', 'sum');
40 });
41
42 proxy.before(ret, 'on', function(obj, args) {
43 if(args.length < 2 || args[0] !== 'data') return;
44
45 proxy.callback(args, -1, function(obj, args) {
46 if(nt.paused) return;
47
48 info.metric('Sockets', 'Data received per minute', size(args[0]), 'KB', 'sum');
49 });
50 });
51 });
52};
53
54var size = function(data) {
55 var bytes = 0;
56
57 if(Buffer.isBuffer(data)) {
58 bytes = data.length;
59 }
60 else if(typeof data === 'string') {
61 bytes = data.length; // yes I know, this is wrong!!!
62 }
63
64 return (bytes / 1000);
65};