Fluentd

How to Write Service Discovery Plugin

Fluentd supports pluggable service discovery which lets an output plugin resolve its destinations at run time. The plugin filenames prefixed sd_ are registered as Service Discovery Plugins.

See Plugin Base Class API for details on the common APIs for all the plugin types.

Here is an example of a custom service discovery plugin that reads a list of servers from a plain text file, one host:port per line, and re-reads it on a timer. It takes a required parameter called path, which is the pathname of that file, and an optional interval.

require 'fluent/plugin/service_discovery'
require 'fluent/plugin_helper'

module Fluent::Plugin
  class MyListServiceDiscovery < ServiceDiscovery
    include Fluent::PluginHelper::Mixin

    # Register MyListServiceDiscovery as 'my_list'.
    Fluent::Plugin.register_sd('my_list', self)

    helpers :timer

    config_param :path, :string
    config_param :interval, :time, default: 10

    def configure(conf)
      super

      unless File.readable?(@path)
        raise Fluent::ConfigError,