Module: UnicornMetrics::Registry
- Defined in:
- lib/unicorn_metrics/registry.rb
Overview
UnicornMetrics::Registry is a container for Metrics
Constant Summary collapse
- METRIC_TYPES =
Map metrics types to class names
{ :counter => 'Counter', :timer => 'Timer', :response_counter => 'ResponseCounter', :request_counter => 'RequestCounter', :request_timer => 'RequestTimer' }
Class Method Summary collapse
-
.as_json ⇒ Hash
Default JSON representation of metrics.
-
.metrics ⇒ Hash
Return a hash of metrics that have been defined.
-
.register(type, name, *args) ⇒ Counter, ...
Register a new metric.
Class Method Details
.as_json ⇒ Hash
Returns default JSON representation of metrics.
44 45 46 47 48 |
# File 'lib/unicorn_metrics/registry.rb', line 44 def as_json(*) metrics.inject({}) do |hash, (name, metric)| hash.merge(metric.as_json) end end |
.metrics ⇒ Hash
Return a hash of metrics that have been defined
24 25 26 |
# File 'lib/unicorn_metrics/registry.rb', line 24 def metrics @metrics ||= {} end |
.register(type, name, *args) ⇒ Counter, ...
Register a new metric. Arguments are optional. See metric class definitions.
33 34 35 36 37 38 39 40 41 |
# File 'lib/unicorn_metrics/registry.rb', line 33 def register(type, name, *args) type = METRIC_TYPES.fetch(type) { raise "Invalid type: #{type}" } validate_name!(name) metric = UnicornMetrics.const_get(type).new(name,*args) metrics[name] = metric define_getter(name) metric end |