Created
May 27, 2016 01:41
-
-
Save jchauncey/b4ea7ec113747de130766739843ce1d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fluent/mixin/config_placeholders' | |
require 'fluent/mixin/plaintextformatter' | |
require 'fluent/mixin/rewrite_tag_name' | |
require 'fluent/output' | |
module Fluent | |
class DeisOutput < Output | |
Fluent::Plugin.register_output("deis_output", self) | |
include Fluent::Mixin::PlainTextFormatter | |
include Fluent::Mixin::ConfigPlaceholders | |
include Fluent::HandleTagNameMixin | |
include Fluent::Mixin::RewriteTagName | |
def initialize | |
super | |
require "remote_syslog_logger" | |
end | |
def start | |
super | |
end | |
def shutdown | |
super | |
end | |
def emit(tag, es, chain) | |
chain.next | |
es.each do |time, record| | |
tag = rewrite_tag!(tag.dup) | |
if from_container?(record, "deis-controller") || deis_deployed_app?(record) | |
puts "Record:#{record}" if debug? | |
send(tag, time, record, ENV['DEIS_LOGGER_SERVICE_HOST'], ENV['DEIS_LOGGER_SERVICE_PORT_TRANSPORT']) | |
end | |
if from_container(record, "deis-router") | |
# Send to influx | |
# DEIS_MONITOR_INFLUXAPI_SERVICE_HOST | |
# DEIS_MONITOR_INFLUXAPI_SERVICE_PORT_TRANSPORT | |
end | |
end | |
end | |
def self.kubernetes?(record) | |
return record[:kubernetes] != nil | |
end | |
def self.from_container?(record, regex) | |
if kubernetes? record | |
return true if Regexp.new(regex).match(record[:kubernetes][:container_name]) != nil | |
end | |
return false | |
end | |
def self.deis_deployed_app?(record) | |
if kubernetes? record | |
labels = record[:kubernetes][:labels] | |
return true if labels[:heritage] == "deis" && labels[:app] != nil | |
end | |
return false | |
end | |
def self.send(tag, time, record, host, port) | |
sender = RemoteSyslogLogger::UdpSender.new(host, port) | |
begin | |
sender.transmit format(tag, time, record) | |
rescue Exception => e | |
puts "Error:#{e.message}" | |
ensure | |
sender.close if sender | |
end | |
end | |
def self.debug? | |
ENV['DEUBG'] == "true" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./.ruby-version | |
./.travis.yml | |
./fluent-plugin-deis_output.gemspec | |
./Gemfile | |
./Gemfile.lock | |
./lib | |
./lib/fluent | |
./lib/fluent/plugin | |
./lib/fluent/plugin/out_deis.rb | |
./LICENSE | |
./pkg | |
./pkg/fluent-plugin-deis_output-0.1.0.gem | |
./Rakefile | |
./README.md | |
./test | |
./test/test_out_deis.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment