fluentd run in docker
docker run -d -p 24224:24224 \
-p 9880:9880 \
-v `pwd`/log:/var/log/httpd \
-v `pwd`/forward.conf:/fluentd/etc/fluent.conf \
fluent/fluentd
fluentd.conf
<source>
type tail
format none
path /var/log/apache*/access.log,/var/log/apache*/access_log,/var/log/httpd/access.log,/var/log/httpd/access_log
pos_file /fluentd/log/apache-access.pos
read_from_head true
tag apache-access
</source>
<source>
type tail
format none
path /var/log/apache*/error.log,/var/log/apache*/error_log,/var/log/httpd/error.log,/var/log/httpd/error_log
pos_file /fluentd/log/apache-error.pos
read_from_head true
tag apache-error
</source>
<source>
type http
port 9880
</source>
<source>
@type forward
port 24224
</source>
<match **>
@type copy
<store>
@type stdout
output_type json
</store>
<store>
@type forward
send_timeout 60s
recover_wait 10s
heartbeat_interval 1s
phi_threshold 16
hard_timeout 60s
<server>
name loggw
host 35.185.159.2
port 24224
weight 60
</server>
<secondary>
@type file
path /fluentd/log/fluent-forward-failed
</secondary>
</store>
</match>
package.js
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "2.5.9",
"fluent-logger": "0.1.0"
}
}
web.js
var express = require('express');
var app = express.createServer(express.logger());
var logger = require('fluent-logger');
logger.configure('fluentd.test', {host: 'localhost', port: 24224});
app.get('/', function(request, response) {
logger.emit('follow', {from: 'userA', to: 'userB', ts: new Date().getTime()});
response.send('Hello World!');
});
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("Listening on " + port);
});