Module: SafeMemoize::Adapters::StatsD
- Defined in:
- lib/safe_memoize/adapters/statsd.rb
Overview
Optional StatsD adapter.
Routes SafeMemoize lifecycle events to any StatsD-compatible client (any object that responds to +#increment+).
Configure via Configuration#statsd_client:
SafeMemoize.configure do |c| c.statsd_client = Datadog::Statsd.new end
Emitted metrics:
| Metric | Fires on |
|---|---|
| +safe_memoize.hit+ | cache hit |
| +safe_memoize.miss+ | cache miss |
| +safe_memoize.store+ | value written |
| +safe_memoize.evict+ | LRU eviction |
| +safe_memoize.expire+ | TTL expiration |
Every metric is tagged with +method:
Constant Summary collapse
- METRIC_NAMES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ on_hit: "safe_memoize.hit", on_miss: "safe_memoize.miss", on_evict: "safe_memoize.evict", on_expire: "safe_memoize.expire", on_store: "safe_memoize.store" }.freeze
Class Method Summary collapse
-
.dispatch(client, hook_type, cache_key, class_name) ⇒ void
Dispatches a lifecycle event to the StatsD client.
Class Method Details
.dispatch(client, hook_type, cache_key, class_name) ⇒ void
This method returns an undefined value.
Dispatches a lifecycle event to the StatsD client.
45 46 47 48 49 50 51 52 53 |
# File 'lib/safe_memoize/adapters/statsd.rb', line 45 def self.dispatch(client, hook_type, cache_key, class_name) metric = METRIC_NAMES[hook_type] return unless metric = ["method:#{cache_key[0]}", "class:#{class_name}"] client.increment(metric, tags: ) rescue => error warn "[SafeMemoize] StatsD dispatch error: #{error.}" end |