-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
executable file
·68 lines (59 loc) · 1.73 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
61
62
63
64
65
66
67
68
var env = require('envalid');
var StatsD = require('node-statsd');
var allcontainers = require('docker-allcontainers');
var dockerstats = require('docker-stats');
var _ = require('lodash');
var through = require('through2');
env.validate(process.env, {
STATSD_HOST: {recommended: true},
STATSD_PORT: {recommended: true},
STATSD_PREFIX: {recommended: true},
});
var statsdClient = new StatsD({
host: env.get('STATSD_HOST', '127.0.0.1'),
port: env.get('STATSD_PORT', 8125),
prefix: env.get('STATSD_PREFIX', 'docker.'),
});
/*statsdClient = {
gauge: function(key, value){
console.log(key, value);
}
}*/
var stats = dockerstats({
docker: null,
events: allcontainers({
preheat: true,
docker:null})
});
stats.pipe(through.obj(update));
function update(chunk, enc, callback) {
var name = chunk.name;
var info = {
cpu: {
cpu_percent: chunk.stats.cpu_stats.cpu_usage.cpu_percent,
},
memory: {
usage: chunk.stats.memory_stats.usage,
max_usage: chunk.stats.memory_stats.max_usage,
total_rss: chunk.stats.memory_stats.stats.total_rss,
total_swap: chunk.stats.memory_stats.stats.total_swap,
total_pgpgin: chunk.stats.memory_stats.stats.total_pgpgin,
total_pgpgout: chunk.stats.memory_stats.stats.total_pgpgout,
total_pgfault: chunk.stats.memory_stats.stats.total_pgfault
}
};
//console.log(chunk.stats);
updateContainer(name, info)
callback();
}
function updateContainer (name, info) {
_.each(info, function(section, key){
if (!_.isObject(section)) {
statsdClient.gauge(name + '.' + key, section);
} else {
_.each(section, function(value, metric){
statsdClient.gauge(name + '.' + key + '.' + metric, value);
});
}
});
}