-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·47 lines (39 loc) · 1.15 KB
/
index.js
File metadata and controls
executable file
·47 lines (39 loc) · 1.15 KB
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
#!/usr/bin/env node
var net = require('net');
var allContainers = require('docker-allcontainers');
var loghose = require("docker-loghose");
var program = require('commander');
var through = require('through2');
var os = require("os");
program
.version('0.1.0')
.option('-h, --host [host]', 'LogIo server host', 'localhost')
.option('-p, --port [port]', 'LogIo server port', 28777)
.option('-n, --name [name]', 'LogIo node name', os.hostname())
.parse(process.argv);
function connect() {
var stream = net.createConnection(program.port, program.host);
return stream;
}
var s = connect();
var ee = allContainers({
preheat: true,
docker: null,
});
var opts = {
json: false,
docker: null,
events: ee
};
loghose(opts).pipe(through.obj(function(chunk, enc, cb){
this.push('+log|'+chunk.image+'|'+program.name+':'+chunk.id+'|info|'+chunk.line+'\r\n');
cb();
})).pipe(s);
ee.on('start', function(meta, container) {
var id = meta.id.substring(0, 12);
s.write('+node|'+program.name+':'+id+'|'+meta.image+'\r\n');
});
ee.on('stop', function(meta, container) {
var id = meta.id.substring(0, 12);
s.write('-node|'+program.name+':'+id+'\r\n');
});