logstash-filter-k8s

This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program


License
MIT
Install
gem install logstash-filter-k8s -v 0.1.0

Documentation

Logstash Plugin

This is a plugin for Logstash.

Rubygems: https://rubygems.org/gems/logstash-filter-k8s

Documentation

This plugin does not require access to Kubernetes API.

Example configuration

input {
  file {
    # Path to to docker logs
    path => "/var/lib/docker/containers/**/*-json.log"
    tags => ["kubernetes", "docker"]
  }
}

filter {
  kubernetes {
    add_tag => ["kubernetes_filtered"]  
  }
}

output {
  if "kubernetes_filtered" in [tags] {
    elasticsearch {
      ...
      document_type => "%{[kubernetes][namespace]}_%{[kubernetes][pod]}_%{[kubernetes][container_name]}"
    }
  }
}

Available variables

[kubernetes][pod]
[kubernetes][namespace]
[kubernetes][container_name]
[kubernetes][container_id]
[kubernetes][image]
[kubernetes][container_hash]

If you're running logstash in a container, make sure that you mount both, /var/log/containers and /var/lib/docker/containers for logstash input to be able to follow symlinks.

Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one central location.

Need Help?

Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.

Developing

1. Plugin Developement and Testing

Code

  • To get started, you'll need JRuby with the Bundler gem installed.

  • Create a new plugin or clone and existing from the GitHub logstash-plugins organization. We also provide example plugins.

  • Install dependencies

bundle install

Test

  • Update your dependencies
bundle install
  • Run tests
bundle exec rspec

2. Running your unpublished Plugin in Logstash

2.1 Run in a local Logstash clone

  • Edit Logstash Gemfile and add the local plugin path, for example:
gem "logstash-filter-k8s", :path => "/your/local/logstash-filter-k8s"
  • Install plugin
bin/plugin install --no-verify
  • Run Logstash with your plugin
bin/logstash -e 'filter {kubernetes {}}'

At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.

2.2 Run in an installed Logstash

You can use the same 2.1 method to run your plugin in an installed Logstash by editing its Gemfile and pointing the :path to your local plugin development directory or you can build the gem and install it using:

  • Build your plugin gem
gem build logstash-filter-k8s.gemspec
  • Install the plugin from the Logstash home
bin/plugin install /your/local/plugin/logstash-filter-k8s.gem
  • Start Logstash and proceed to test the plugin

Contributing

All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.

Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.

It is more important to the community that you are able to contribute.

For more information about contributing, see the CONTRIBUTING file.