Class: MetricsCapacitor::Model::Metric
- Inherits:
-
Object
- Object
- MetricsCapacitor::Model::Metric
- Extended by:
- Forwardable
- Defined in:
- lib/metrics-capacitor/model/metric.rb
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Metric
constructor
A new instance of Metric.
- #name ⇒ Object
- #tags ⇒ Object
- #timestamp(scale = :ms) ⇒ Object
- #to_elastic ⇒ Object
- #to_redis ⇒ Object
- #values ⇒ Object
Constructor Details
Instance Method Details
#name ⇒ Object
29 30 31 |
# File 'lib/metrics-capacitor/model/metric.rb', line 29 def name @metric[:name].to_s end |
#tags ⇒ Object
33 34 35 36 |
# File 'lib/metrics-capacitor/model/metric.rb', line 33 def return @metric[:tags] if ( @metric[:tags] || @metric[:tags].empty? ) { capacitor: 'untagged' } end |
#timestamp(scale = :ms) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/metrics-capacitor/model/metric.rb', line 51 def (scale = :ms) m = case scale when :ms 1000.0 when :us 1_000_000.0 when :ns 1_000_000_000.0 else 1.0 end return (Time.now.to_f * m).to_i.to_s unless @metric[:timestamp] (Time.at(@metric[:timestamp]).to_f * m).to_i.to_s end |
#to_elastic ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/metrics-capacitor/model/metric.rb', line 13 def to_elastic { index: { data: { :@name => name, :@timestamp => (:ms), :@tags => , :@values => values } } } end |
#to_redis ⇒ Object
25 26 27 |
# File 'lib/metrics-capacitor/model/metric.rb', line 25 def to_redis @metric.to_json end |
#values ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/metrics-capacitor/model/metric.rb', line 38 def values case @metric[:values] when Hash return @metric[:values] when Integer return { value: @metric[:values].to_f } when Float return { value: @metric[:values] } else return { value: 0.0 } end end |