Class: Fluent::GELFOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::GELFOutput
show all
- Includes:
- GelfUtil
- Defined in:
- lib/fluent/plugin/out_gelf.rb
Instance Method Summary
collapse
Methods included from GelfUtil
#make_gelfentry, #make_json
Constructor Details
Returns a new instance of GELFOutput.
23
24
25
|
# File 'lib/fluent/plugin/out_gelf.rb', line 23
def initialize
super
end
|
Instance Method Details
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/fluent/plugin/out_gelf.rb', line 27
def configure(conf)
super(conf)
raise ConfigError, "'host' parameter (hostname or address of Graylog2 server) is required" unless conf.has_key?('host')
if @protocol == 'udp' then @proto = GELF::Protocol::UDP
elsif @protocol == 'tcp' then @proto = GELF::Protocol::TCP
else raise ConfigError, "'protocol' parameter should be either 'udp' (default) or 'tcp'"
end
end
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/fluent/plugin/out_gelf.rb', line 64
def format(tag, time, record)
if defined? Fluent::EventTime and time.is_a? Fluent::EventTime then
timestamp = time.sec + (time.nsec.to_f/1000000000).round(3)
else
timestamp = time
end
begin
make_gelfentry(
tag,time,record,
{
:use_record_host => @use_record_host,
:add_msec_time => @add_msec_time
}
).to_msgpack
rescue Exception => e
log.error sprintf(
'Error trying to serialize %s: %s',
record.to_s.force_encoding('UTF-8'),
e.message.to_s.force_encoding('UTF-8')
)
end
end
|
104
105
106
|
# File 'lib/fluent/plugin/out_gelf.rb', line 104
def formatted_to_msgpack_binary
true
end
|
#shutdown ⇒ Object
60
61
62
|
# File 'lib/fluent/plugin/out_gelf.rb', line 60
def shutdown
super
end
|
#start ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/fluent/plugin/out_gelf.rb', line 41
def start
super
options = {:facility => 'fluentd', :protocol => @proto}
if @tls then
options[:tls] = @tls_options
end
@conn = GELF::Notifier.new(@host, @port, 'WAN', options)
@conn.level_mapping = 'direct'
@conn.collect_file_and_line = false
end
|
#write(chunk) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/fluent/plugin/out_gelf.rb', line 89
def write(chunk)
chunk.msgpack_each do |data|
begin
@conn.notify!(data)
rescue Exception => e
log.error sprintf(
'Error trying to publish %s: %s',
data.to_s.force_encoding('UTF-8'),
e.message.to_s.force_encoding('UTF-8')
)
end
end
end
|