Skip to content

Instantly share code, notes, and snippets.

@harukasan
Last active December 12, 2015 00:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harukasan/4681483 to your computer and use it in GitHub Desktop.
Save harukasan/4681483 to your computer and use it in GitHub Desktop.
Forwardプラグインで投げるときにホスト名を追加する
#
# Forward with hostname
#
# harukasan <harukasan@pixiv.com>
#
# == configure
# key (optional):: キー名(default: host)
#
class ForwardWithHostnameOutput < Fluent::ForwardOutput
Fluent::Plugin.register_output('forward_with_hostname', self)
config_param :host_key, :string, :default => 'host'
def start
@hostname = `hostname`.strip
super
end
def emit(tag, es, chain)
es.each do |time, record|
record[@host_key] = @hostname
end
super(tag, es, chain)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment