40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/fluent/plugin/out_dogstatsd.rb', line 40
def write(chunk)
@statsd.batch do |s|
chunk.msgpack_each do |tag, time, record|
key = if @use_tag_as_key
tag
else
record.delete('key')
end
if !key && @use_tag_as_key_if_missing
key = tag
end
unless key
log.warn "'key' is not specified. skip this record:", tag: tag
next
end
value = record.delete(@value_key || 'value')
options = {}
title = record.delete('title')
text = record.delete('text')
type = @metric_type || record.delete('type')
sample_rate = @sample_rate || record.delete('sample_rate')
if sample_rate
options[:sample_rate] = sample_rate
end
tags = if @flat_tags || @flat_tag
record
else
record['tags']
end
if tags
options[:tags] = tags.map do |k, v|
"#{k}:#{v}"
end
end
case type
when 'increment'
s.increment(key, options)
when 'decrement'
s.decrement(key, options)
when 'count'
s.count(key, value, options)
when 'gauge'
s.gauge(key, value, options)
when 'histogram'
s.histogram(key, value, options)
when 'timing'
s.timing(key, value, options)
when 'set'
s.set(key, value, options)
when 'event'
options[:alert_type] = record['alert_type']
s.event(title, text, options)
when nil
log.warn "type is not provided (You can provide type via `metric_type` in config or `type` field in a record."
else
log.warn "Type '#{type}' is unknown."
end
end
end
end
|