class Fluent::StackdriverMonitoringOutput
Constants
- PAST_DATA_TIME_LIMIT
- TYPE_PREFIX
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_stackdriver_monitoring.rb, line 20 def configure(conf) super unless is_custom_metric? @custom_metrics.type raise Fluent::ConfigError.new "custom_metrics.type must start with \"#{TYPE_PREFIX}\"" end if @custom_metrics.metric_kind == :CUMULATIVE if @custom_metrics.time_interval == 0 raise Fluent::ConfigError.new 'time_interval must be greater than 0 if metric_kind is set to CUMULATIVE' end if @custom_metrics.value_type == :BOOL raise Fluent::ConfigError.new 'custom metric does not support BOOL value type if metric_kind is set to CUMULATIVE' end end @client = Fluent::StackdriverMonitoring::Writer.new @project, @custom_metrics, log end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_stackdriver_monitoring.rb, line 44 def format(tag, time, record) [tag, time, record].to_msgpack end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_stackdriver_monitoring.rb, line 39 def start super @client.start end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_stackdriver_monitoring.rb, line 48 def write(chunk) current_time = Time.now.to_i chunk.msgpack_each do |tag, time, record| if (current_time - time) >= PAST_DATA_TIME_LIMIT log.warn 'Drop data point because it cannot be written more than 24h in the past', time: Time.at(time).to_s, metric_name: @metric_name next end value = record[@custom_metrics.key] start_time = time - @custom_metrics.time_interval @client.write start_time, time, value end end
Private Instance Methods
is_custom_metric?(metric_type)
click to toggle source
# File lib/fluent/plugin/out_stackdriver_monitoring.rb, line 64 def is_custom_metric?(metric_type) metric_type.start_with? TYPE_PREFIX end