lib/fluent/plugin/out_metricsense.rb in fluent-plugin-metricsense-0.2.3 vs lib/fluent/plugin/out_metricsense.rb in fluent-plugin-metricsense-0.2.4
- old
+ new
@@ -28,10 +28,11 @@
end
module UpdateMode
ADD = 0
MAX = 1
+ AVERAGE = 2
end
class Backend
UpdateMode = MetricSenseOutput::UpdateMode
include Configurable
@@ -136,10 +137,12 @@
# get update_mode key
update_mode = record.delete(@update_mode_key)
case update_mode
when "max"
update_mode = UpdateMode::MAX
+ when "average"
+ update_mode = UpdateMode::AVERAGE
else
# default is add
update_mode = UpdateMode::ADD
end
@@ -209,10 +212,16 @@
def mode
UpdateMode::MAX
end
end
+ class AverageUpdater < MaxUpdater
+ def mode
+ UpdateMode::AVERAGE
+ end
+ end
+
AggregationKey = Struct.new(:tag, :time, :seg_val, :seg_key)
def write(chunk)
counters = {}
@@ -223,9 +232,11 @@
case update_mode
when UpdateMode::ADD
updater = AddUpdater
when UpdateMode::MAX
updater = MaxUpdater
+ when UpdateMode::AVERAGE # AVERAGE uses MaxUpdater and calculate average on server-side aggregation
+ updater = AverageUpdater
else # default is AddUpdater
updater = AddUpdater
end
# total value