Class: Fluent::MetricSenseOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::MetricSenseOutput
- Defined in:
- lib/fluent/plugin/out_metricsense.rb
Defined Under Namespace
Modules: Backends, UpdateMode Classes: AddUpdater, AggregationKey, Backend, MaxUpdater
Constant Summary collapse
- BACKENDS =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format_stream(tag, es) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Class Method Details
.register_backend(name, klass) ⇒ Object
26 27 28 |
# File 'lib/fluent/plugin/out_metricsense.rb', line 26 def self.register_backend(name, klass) BACKENDS[name] = klass end |
Instance Method Details
#configure(conf) ⇒ Object
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 |
# File 'lib/fluent/plugin/out_metricsense.rb', line 66 def configure(conf) super if @remove_tag_prefix @remove_tag_prefix = Regexp.new('^' + Regexp.escape(@remove_tag_prefix) + "\\.?") end @no_segment_keys = (conf.has_key?('no_segment_keys') && (conf['no_segment_keys'].empty? || conf['no_segment_keys'] == 'true')) if @only_segment_keys @only_segment_keys = @only_segment_keys.strip.split(/\s*,\s*/) end if @exclude_segment_keys @exclude_segment_keys = @exclude_segment_keys.strip.split(/\s*,\s*/) end be = BACKENDS[@backend] unless be raise ConfigError, "unknown backend: #{@backend.inspect}" end # aggregate_interval must be a multiple of 60 to normalize values # into X per minute @aggregate_interval = @aggregate_interval.to_i / 60 * 60 @normalize_factor = @aggregate_interval / 60 @backend = be.new @backend.configure(conf) end |
#format_stream(tag, es) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/fluent/plugin/out_metricsense.rb', line 107 def format_stream(tag, es) # modify tag tag = tag.sub(@remove_tag_prefix, '') if @remove_tag_prefix tag = "#{add_tag_prefix}.#{tag}" if @add_tag_prefix out = '' es.each do |time,record| # dup record to modify record = record.dup # get value value = record.delete(@value_key) # ignore record if value is invalid or 0 begin fv = value.to_f rescue next end next if fv == 0.0 # use integer if value.to_f == value.to_f.to_i iv = fv.to_i if iv.to_f == fv value = iv else value = fv end # get update_mode key update_mode = record.delete(@update_mode_key) case update_mode when "max" update_mode = UpdateMode::MAX else # default is add update_mode = UpdateMode::ADD end # get segments if @no_segment_keys segments = {} else if @only_segment_keys segments = {} @only_segment_keys.each {|key| if v = record[key] segments[key] = v end } else segments = record end if @exclude_segment_keys @exclude_segment_keys.each {|key| segments.delete(key) } end end [tag, time, value, segments, update_mode].to_msgpack(out) end out end |
#shutdown ⇒ Object
102 103 104 105 |
# File 'lib/fluent/plugin/out_metricsense.rb', line 102 def shutdown super @backend.shutdown end |
#start ⇒ Object
97 98 99 100 |
# File 'lib/fluent/plugin/out_metricsense.rb', line 97 def start @backend.start super end |
#write(chunk) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/fluent/plugin/out_metricsense.rb', line 216 def write(chunk) counters = {} # select sum(value) from chunk group by tag, time/60, seg_val, seg_key chunk.msgpack_each {|tag,time,value,segments,update_mode| time = time / @aggregate_interval * @aggregate_interval case update_mode when UpdateMode::ADD updater = AddUpdater when UpdateMode::MAX updater = MaxUpdater else # default is AddUpdater updater = AddUpdater end # total value ak = AggregationKey.new(tag, time, nil, nil) (counters[ak] ||= updater.new).add(value) # segmented values segments = Hash[segments] if segments.is_a?(Array) # for backward compat segments.each_pair {|seg_key,seg_val| ak = AggregationKey.new(tag, time, seg_val, seg_key) (counters[ak] ||= updater.new).add(value) } } data = [] counters.each_pair {|ak,up| data << [ak.tag, ak.time, up.normalized_value(@normalize_factor), ak.seg_key, ak.seg_val, up.mode] } @backend.write(data) end |