-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
60 lines (47 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var _param = require('./param.json');
var _os = require('os');
var _memcached = require('mc');
var _tools = require('graphdat-plugin-tools');
var _client = new _memcached.Client((_param.host || 'localhost') + ':' + (_param.port || 11211));
var _pollInterval = _param.pollInterval || 1000;
var _source = _param.source || _os.hostname();
var _accum = {};
function accum(vals, name)
{
var last = _accum[name];
var cur = vals[name];
if (last === undefined)
last = cur;
var diff = cur - last;
_accum[name] = cur;
return diff;
}
function poll()
{
_client.stats(function(err, data)
{
if (err)
return console.error(err);
data = data[0];
// Report
console.log('MEMCACHED_ALLOCATED %d %s', data.bytes / data.limit_maxbytes, _source);
console.log('MEMCACHED_CONNECTIONS %d %s', data.curr_connections, _source);
console.log('MEMCACHED_HITS %d %s', accum(data, 'get_hits'), _source);
console.log('MEMCACHED_MISSES %d %s', accum(data, 'get_misses'), _source);
console.log('MEMCACHED_ITEMS %d %s', data.curr_items, _source);
console.log('MEMCACHED_REQUESTS %d %s', accum(data, 'cmd_get') + accum(data, 'cmd_set'), _source);
console.log('MEMCACHED_NETWORK_IN %d %s', accum(data, 'bytes_read'), _source);
console.log('MEMCACHED_NETWORK_OUT %d %s', accum(data, 'bytes_written'), _source);
});
setTimeout(poll, _pollInterval);
}
_client.connect(function(err)
{
if (err)
{
console.error('connection error: %s', err);
process.exit(1);
}
else
poll();
});