Class: Fluent::LibratoMetricsOutput::MetricsMixin::Metrics
- Inherits:
-
Object
- Object
- Fluent::LibratoMetricsOutput::MetricsMixin::Metrics
- Includes:
- Configurable
- Defined in:
- lib/fluent/plugin/out_librato_metrics_mixin.rb
Instance Attribute Summary collapse
-
#count_proc ⇒ Object
Returns the value of attribute count_proc.
-
#each_keys ⇒ Object
readonly
parsed ‘each_key’.
-
#key_proc ⇒ Object
Returns the value of attribute key_proc.
-
#match_proc ⇒ Object
Returns the value of attribute match_proc.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#value_proc ⇒ Object
Returns the value of attribute value_proc.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #create_combined_key_proc(keys) ⇒ Object
- #evaluate(tag, time, record) ⇒ Object
-
#initialize(pattern) ⇒ Metrics
constructor
A new instance of Metrics.
Constructor Details
#initialize(pattern) ⇒ Metrics
Returns a new instance of Metrics.
82 83 84 85 86 87 88 89 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 82 def initialize(pattern) super() if pattern && !pattern.empty? @pattern = MatchPattern.create(pattern) else @pattern = nil end end |
Instance Attribute Details
#count_proc ⇒ Object
Returns the value of attribute count_proc.
118 119 120 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 118 def count_proc @count_proc end |
#each_keys ⇒ Object (readonly)
parsed ‘each_key’
96 97 98 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 96 def each_keys @each_keys end |
#key_proc ⇒ Object
Returns the value of attribute key_proc.
116 117 118 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 116 def key_proc @key_proc end |
#match_proc ⇒ Object
Returns the value of attribute match_proc.
119 120 121 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 119 def match_proc @match_proc end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
91 92 93 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 91 def pattern @pattern end |
#value_proc ⇒ Object
Returns the value of attribute value_proc.
117 118 119 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 117 def value_proc @value_proc end |
Instance Method Details
#configure(conf) ⇒ Object
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 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 121 def configure(conf) super if @each_key @each_keys = @each_key.split(',').map {|e| e.strip } @key_proc = create_combined_key_proc(@each_keys) else @each_keys = [] use_keys = [@name] @key_proc = Proc.new {|record| use_keys } end case @type when :int if vk = @value_key dv = @default_value ? @default_value.to_i : nil @value_proc = Proc.new {|record| val = record[vk]; val ? val.to_i : dv } else dv = @default_value ? @default_value.to_i : 1 @value_proc = Proc.new {|record| dv } end when :float if vk = @value_key dv = @default_value ? @default_value.to_f : nil @value_proc = Proc.new {|record| val = record[vk]; val ? val.to_f : dv } else dv = @default_value ? @default_value.to_f : 1.0 @value_proc = Proc.new {|record| dv } end end if ck = @count_key @count_proc = Proc.new {|record| val = record[ck].to_i; val == 0 ? 1 : val } else @count_proc = Proc.new {|record| 1 } end if pt = @pattern @match_proc = Proc.new {|tag| pt.match(tag) } else @match_proc = Proc.new {|tag| true } end @data = Data.new(self) end |
#create_combined_key_proc(keys) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 167 def create_combined_key_proc(keys) if keys.length == 1 key = keys[0] Proc.new {|record| val = record[key] val ? [val] : nil } else Proc.new {|record| keys.map {|key| val = record[key] break nil unless val val } } end end |
#evaluate(tag, time, record) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/fluent/plugin/out_librato_metrics_mixin.rb', line 185 def evaluate(tag, time, record) return nil unless @match_proc.call(tag) data = @data keys = data.keys = @key_proc.call(record) return nil unless keys value = data.value = @value_proc.call(record) return nil unless value data.count = @count_proc.call(record) return data end |