Class: Fluent::StatsitePlugin::MetricFormat
- Inherits:
-
Object
- Object
- Fluent::StatsitePlugin::MetricFormat
- Defined in:
- lib/fluent/plugin/statsite/metric_format.rb
Overview
This represent a key/value format of Metric
Constant Summary collapse
- CONSTANT_VALUE =
'\w+'- SUBSTITUTE =
'\$\{\w+\}'- SUBSTITUTE_REGEXP =
/\$\{(\w+)\}/- ELEMENT =
"(?:#{CONSTANT_VALUE}|#{SUBSTITUTE})"- PATTERN =
"#{ELEMENT}+"
Class Method Summary collapse
Instance Method Summary collapse
- #convert(record) ⇒ Object
-
#initialize(str) ⇒ MetricFormat
constructor
A new instance of MetricFormat.
- #to_s ⇒ Object
Constructor Details
#initialize(str) ⇒ MetricFormat
Returns a new instance of MetricFormat.
11 12 13 14 |
# File 'lib/fluent/plugin/statsite/metric_format.rb', line 11 def initialize(str) @str = str @no_substitute = str.index('$').nil? end |
Class Method Details
.validate(str) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fluent/plugin/statsite/metric_format.rb', line 28 def self.validate(str) if /^#{PATTERN}$/.match(str).nil? raise ConfigError, "invalid format of key/value field, it must be #{PATTERN}, but specified as #{str}" end new(str) end |
Instance Method Details
#convert(record) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/fluent/plugin/statsite/metric_format.rb', line 16 def convert(record) if @no_substitute @str else @str.gsub(SUBSTITUTE_REGEXP) { record.fetch($1) } rescue nil end end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/fluent/plugin/statsite/metric_format.rb', line 24 def to_s @str end |