Class: Fluent::Plugin::LocalMetrics

Inherits:
Metrics show all
Defined in:
lib/fluent/plugin/metrics_local.rb

Constant Summary

Constants inherited from Metrics

Metrics::DEFAULT_TYPE

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes inherited from Metrics

#has_methods_for_counter, #has_methods_for_gauge, #use_gauge_metric

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Metrics

#create, #dec, #set, #sub

Methods included from UniqueId::Mixin

#dump_unique_id_hex, #generate_unique_id

Methods included from Fluent::PluginLoggerMixin

included, #terminate

Methods included from Fluent::PluginId

#plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir, #stop

Methods inherited from Base

#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #inspect, #plugin_root_dir, #reloadable_plugin?, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type

Constructor Details

#initializeLocalMetrics

Returns a new instance of LocalMetrics.



25
26
27
28
29
# File 'lib/fluent/plugin/metrics_local.rb', line 25

def initialize
  super
  @store = 0
  @monitor = Monitor.new
end

Instance Method Details

#add(value) ⇒ Object



69
70
71
72
73
# File 'lib/fluent/plugin/metrics_local.rb', line 69

def add(value)
  @monitor.synchronize do
    @store += value
  end
end

#configure(conf) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin/metrics_local.rb', line 31

def configure(conf)
  super

  if use_gauge_metric
    class << self
      alias_method :dec, :dec_gauge
      alias_method :set, :set_gauge
      alias_method :sub, :sub_gauge
    end
  else
    class << self
      alias_method :set, :set_counter
    end
  end
end

#dec_gaugeObject



63
64
65
66
67
# File 'lib/fluent/plugin/metrics_local.rb', line 63

def dec_gauge
  @monitor.synchronize do
    @store -= 1
  end
end

#getObject



51
52
53
54
55
# File 'lib/fluent/plugin/metrics_local.rb', line 51

def get
  @monitor.synchronize do
    @store
  end
end

#incObject



57
58
59
60
61
# File 'lib/fluent/plugin/metrics_local.rb', line 57

def inc
  @monitor.synchronize do
    @store += 1
  end
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/fluent/plugin/metrics_local.rb', line 47

def multi_workers_ready?
  true
end

#set_counter(value) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/fluent/plugin/metrics_local.rb', line 81

def set_counter(value)
  return if @store > value

  @monitor.synchronize do
    @store = value
  end
end

#set_gauge(value) ⇒ Object



89
90
91
92
93
# File 'lib/fluent/plugin/metrics_local.rb', line 89

def set_gauge(value)
  @monitor.synchronize do
    @store = value
  end
end

#sub_gauge(value) ⇒ Object



75
76
77
78
79
# File 'lib/fluent/plugin/metrics_local.rb', line 75

def sub_gauge(value)
  @monitor.synchronize do
    @store -= value
  end
end