Class: Yabeda::Datadog::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/yabeda/datadog/metric.rb

Overview

Internal adapter representation of metrics

Constant Summary collapse

SECOND =
1
DEFAULT_FLUSH_INTERVAL =
SECOND * 10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric, type, overides = {}) ⇒ Metric

Returns a new instance of Metric.



12
13
14
15
16
# File 'lib/yabeda/datadog/metric.rb', line 12

def initialize(metric, type, overides = {})
  @metric = metric
  @type = type
  @overides = overides
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/yabeda/datadog/metric.rb', line 18

def type
  @type
end

Class Method Details

.histogram_metrics(historgram) ⇒ Object

Build Datadog histogram metrics from Yabeda histogram metric



68
69
70
71
72
73
74
75
76
77
# File 'lib/yabeda/datadog/metric.rb', line 68

def histogram_metrics(historgram)
  [
    new(historgram, "gauge", name_sufix: "avg"),
    new(historgram, "gauge", name_sufix: "max"),
    new(historgram, "gauge", name_sufix: "min"),
    new(historgram, "gauge", name_sufix: "median"),
    new(historgram, "gauge", name_sufix: "95percentile", unit: nil, per_unit: nil),
    new(historgram, "rate", name_sufix: "count", unit: nil, per_unit: nil),
  ]
end

Instance Method Details

#descriptionObject

Datadog API argument



38
39
40
# File 'lib/yabeda/datadog/metric.rb', line 38

def description
  overides.fetch(:description, metric.comment)
end

#metadataObject

Datadog API argument



21
22
23
24
25
26
27
28
29
30
# File 'lib/yabeda/datadog/metric.rb', line 21

def 
  {
    type: type,
    description: description,
    short_name: name,
    unit: unit,
    per_unit: per_unit,
    statsd_interval: statsd_interval,
  }
end

#nameObject

Datadog API argument



33
34
35
# File 'lib/yabeda/datadog/metric.rb', line 33

def name
  [metric.group, metric.name.to_s, overides[:name_sufix]].compact.join(".")
end

#per_unitObject

Datadog API argument



48
49
50
# File 'lib/yabeda/datadog/metric.rb', line 48

def per_unit
  overides.fetch(:per_unit, Unit.find(metric.per))
end

#statsd_intervalObject

Datadog API argument



53
54
55
# File 'lib/yabeda/datadog/metric.rb', line 53

def statsd_interval
  DEFAULT_FLUSH_INTERVAL if type == "rate"
end

#unitObject

Datadog API argument



43
44
45
# File 'lib/yabeda/datadog/metric.rb', line 43

def unit
  overides.fetch(:unit, Unit.find(metric.unit))
end

#update(api) ⇒ Object

Update metric metadata



58
59
60
# File 'lib/yabeda/datadog/metric.rb', line 58

def update(api)
  api.(name, )
end