Hi,
I have an ELK stack for logging a DCOS cluster. I am trying to parse the container logs from one of the nodes and I would like to ship only the required container logs form the node. Here, I am trying to figure out a way to identify a container by its container name or image name.
So far my Logstash configuration is:
input {
beats { port=> 5044 }
}
filter {
if '/dcos' in [source] {
grok {
match => { 'message' => [ '%{SYSLOGTIMESTAMP:timestamp} %{GREEDYDATA:message}', '%{GREEDYDATA:message}' ] }
add_tag => 'dcos_log' } } }
filter { if '/mesos' in [source] {
grok {
match => { 'message' => [ '%{GREEDYDATA:message}'] }
add_tag => 'mesos_log' } } }
filter { if [docker][name] == 'nginx' {
grok {
match => { 'message' => [ '%{YEAR:year}/%{MONTHNUM:month}/%{MONTHDAY:day} %{TIME:time}', '%{MONTHDAY:date}/%{MONTH:month}/%{YEAR:year}:%{TIME:time}', '%{LOGLEVEL:level}: %{GREEDYDATA:text}', '%{IP:hostip}', '%{GREEDYDATA:message}' ] }
add_field => { 'timestamp' => '%{year}-%{month}-%{date}T%{time}Z' }
add_tag => 'container_log' }
mutate { remove_field => [ 'year', 'month', 'date', 'time' ] } } }
output {
if 'dcos_log' in [tags] {
elasticsearch { hosts => 'ElasticURL'
manage_template => false index => 'dcos-%{+YYYY.MM.dd}'} }
else if 'mesos_log' in [tags] {
elasticsearch { hosts => 'ElasticURL'
manage_template => false index => 'mesos-%{+YYYY.MM.dd}' } }
else {
elasticsearch { hosts => 'ElasticURL'
manage_template => false index => 'containers-%{+YYYY.MM.dd}' } } }
Filebeat Configuration:
filebeat.prospectors:
- input_type: log
paths:
- /var/log/mesos/*.log
- /var/log/dcos/dcos.log
- /var/lib/docker/containers/*/*.log
processors:
- add_docker_metadata: ~
exclude_files: ["stdout.logrotate.state", "stdout.logrotate.conf", "stderr.logrotate.state", "stderr.logrotate.conf"]
tail_files: true
#output.elasticsearch:
# hosts: ["ElasticURL"]
output.logstash:
hosts: logstashURL:5044
timeout: 90
bulk_max_size: 1024
I know there is a way by using the filebeat configuration
filebeat.prospectors:
- type: docker
containers.ids:
- '*'
paths:
- /var/lib/docker/containers/*.log
processors:
- add_docker_metadata: ~
But ideally if I'm handling multiple containers say a 50, I believe this wouldn't look neat.
Can anyone help?