Class: Fluent::StackdriverMonitoringOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::StackdriverMonitoringOutput
- Defined in:
- lib/fluent/plugin/out_stackdriver_monitoring.rb
Constant Summary collapse
- TYPE_PREFIX =
'custom.googleapis.com/'.freeze
- PAST_DATA_TIME_LIMIT =
24h
60 * 60 * 24
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
44 45 46 |
# File 'lib/fluent/plugin/out_stackdriver_monitoring.rb', line 44 def format(tag, time, record) [tag, time, record].to_msgpack end |
#start ⇒ Object
39 40 41 42 |
# File 'lib/fluent/plugin/out_stackdriver_monitoring.rb', line 39 def start super @client.start end |
#write(chunk) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 |