Module: Trabox::Metric
- Defined in:
- lib/trabox/metric.rb
Overview
Traboxのメトリクス
-
unpublished_event_count: パブリッシュするイベント数
-
published_event_count: パブリッシュしたイベント数
-
find_events_error_count: パブリッシュするイベントの取得に失敗した数
-
publish_event_error_count: イベントのパブリッシュに失敗した数
-
update_event_record_error_count: パブリッシュしたイベントのカラム更新に失敗した数
Constant Summary collapse
- NAMESPACE =
ENV.fetch('TRABOX_METRIC_NAMESPACE', 'trabox')
- LOG_PREFIX =
'[metric]'
- SERVICE_OK =
Datadog::Statsd::OK
- SERVICE_CRITICAL =
Datadog::Statsd::CRITICAL
Class Attribute Summary collapse
-
.statsd ⇒ Object
readonly
Returns the value of attribute statsd.
Class Method Summary collapse
- .batch {|_self| ... } ⇒ Object
- .close(**kwargs) ⇒ Object
- .count(name, count, opts = {}) ⇒ Object
- .decrement(name, opts = {}) ⇒ Object
- .distribution(name, value, opts = {}) ⇒ Object
- .distribution_time(name, opts = {}, &block) ⇒ Object
- .event(title, text, opts = {}) ⇒ Object
- .flush(**kwargs) ⇒ Object
- .gauge(name, value, opts = {}) ⇒ Object
- .histogram(name, value, opts = {}) ⇒ Object
- .increment(name, opts = {}) ⇒ Object
- .service_check(name, status, opts = {}) ⇒ Object
- .set(name, value, opts = {}) ⇒ Object
-
.setup(*args, **kwargs) ⇒ Object
Datadog::Statsd.new arguments.
- .time(name, opts = {}, &block) ⇒ Object
- .timing(name, ms, opts = {}) ⇒ Object
Class Attribute Details
.statsd ⇒ Object (readonly)
Returns the value of attribute statsd.
20 21 22 |
# File 'lib/trabox/metric.rb', line 20 def statsd @statsd end |
Class Method Details
.batch {|_self| ... } ⇒ Object
122 123 124 |
# File 'lib/trabox/metric.rb', line 122 def batch yield self end |
.close(**kwargs) ⇒ Object
126 127 128 129 130 |
# File 'lib/trabox/metric.rb', line 126 def close(**kwargs) @statsd&.close(**kwargs) Rails.logger.debug "#{LOG_PREFIX} type=close opts=#{kwargs}" end |
.count(name, count, opts = {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/trabox/metric.rb', line 44 def count(name, count, opts = {}) name = metric_name(name) @statsd&.count(name, count, opts) Rails.logger.debug "#{LOG_PREFIX} type=count name=#{name} count=#{count} opts=#{opts}" end |
.decrement(name, opts = {}) ⇒ Object
56 57 58 |
# File 'lib/trabox/metric.rb', line 56 def decrement(name, opts = {}) count name, -1, opts end |
.distribution(name, value, opts = {}) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/trabox/metric.rb', line 60 def distribution(name, value, opts = {}) name = metric_name(name) @statsd&.distribution name, value, opts Rails.logger.debug "#{LOG_PREFIX} type=distribution name=#{name} value=#{value} opts=#{opts}" end |
.distribution_time(name, opts = {}, &block) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/trabox/metric.rb', line 68 def distribution_time(name, opts = {}, &block) name = metric_name(name) @statsd&.distribution_time name, opts, &block Rails.logger.debug "#{LOG_PREFIX} type=distribution_time name=#{name} opts=#{opts}" end |
.event(title, text, opts = {}) ⇒ Object
76 77 78 79 80 |
# File 'lib/trabox/metric.rb', line 76 def event(title, text, opts = {}) @statsd&.event title, text, opts Rails.logger.debug "#{LOG_PREFIX} type=event title=#{title} opts=#{opts}" end |
.flush(**kwargs) ⇒ Object
132 133 134 135 136 |
# File 'lib/trabox/metric.rb', line 132 def flush(**kwargs) @statsd&.flush(**kwargs) Rails.logger.debug "#{LOG_PREFIX} type=flush opts=#{kwargs}" end |
.gauge(name, value, opts = {}) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/trabox/metric.rb', line 82 def gauge(name, value, opts = {}) name = metric_name(name) @statsd&.gauge name, value, opts Rails.logger.debug "#{LOG_PREFIX} type=gauge name=#{name} value=#{value} opts=#{opts}" end |
.histogram(name, value, opts = {}) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/trabox/metric.rb', line 90 def histogram(name, value, opts = {}) name = metric_name(name) @statsd&.histogram name, value, opts Rails.logger.debug "#{LOG_PREFIX} type=histogram name=#{name} value=#{value} opts=#{opts}" end |
.increment(name, opts = {}) ⇒ Object
52 53 54 |
# File 'lib/trabox/metric.rb', line 52 def increment(name, opts = {}) count name, 1, opts end |
.service_check(name, status, opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/trabox/metric.rb', line 27 def service_check(name, status, opts = {}) name = metric_name(name) @statsd&.service_check(name, status, opts) status = case status when SERVICE_OK 'ok' when SERVICE_CRITICAL 'critical' else 'undefined' end Rails.logger.debug "#{LOG_PREFIX} type=service_check name=#{name} status=#{status} opts=#{opts}" end |
.set(name, value, opts = {}) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/trabox/metric.rb', line 98 def set(name, value, opts = {}) name = metric_name(name) @statsd&.set name, value, opts Rails.logger.debug "#{LOG_PREFIX} type=set name=#{name} value=#{value} opts=#{opts}" end |
.setup(*args, **kwargs) ⇒ Object
Datadog::Statsd.new arguments
23 24 25 |
# File 'lib/trabox/metric.rb', line 23 def setup(*args, **kwargs) @statsd = Datadog::Statsd.new(*args, **kwargs) end |
.time(name, opts = {}, &block) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/trabox/metric.rb', line 106 def time(name, opts = {}, &block) name = metric_name(name) @statsd&.time name, opts, &block Rails.logger.debug "#{LOG_PREFIX} type=time name=#{name} opts=#{opts}" end |
.timing(name, ms, opts = {}) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/trabox/metric.rb', line 114 def timing(name, ms, opts = {}) name = metric_name(name) @statsd&.timing name, ms, opts Rails.logger.debug "#{LOG_PREFIX} type=timing name=#{name} ms=#{ms} opts=#{opts}" end |