Module: Kotoshu::Metrics
- Defined in:
- lib/kotoshu/metrics_module.rb,
lib/kotoshu/metrics_collector.rb
Overview
Metrics and instrumentation for Kotoshu.
Provides thread-safe collection of performance metrics:
-
Lookup counts and timing
-
Cache hit/miss rates
-
Suggestion generation stats
-
Optional export to StatsD or Prometheus
Defined Under Namespace
Classes: Collector
Class Attribute Summary collapse
-
.collector ⇒ Collector?
readonly
Get the metrics collector.
Class Method Summary collapse
-
.disable ⇒ Object
Disable metrics collection.
-
.enable ⇒ Object
Enable metrics collection.
-
.enabled? ⇒ Boolean
Check if metrics are enabled.
-
.record_cache(cache_type, hit:) ⇒ Object
Record a cache operation.
-
.record_lookup(word, result:, time:) ⇒ Object
Record a lookup operation.
-
.record_suggestions(word, count:, time:) ⇒ Object
Record suggestion generation.
-
.reset ⇒ Object
Reset all metrics.
-
.stats ⇒ Hash
Get current metrics statistics.
-
.to_prometheus ⇒ String
Get metrics as Prometheus format.
-
.to_statsd ⇒ String
Get metrics as StatsD format.
Class Attribute Details
.collector ⇒ Collector? (readonly)
Get the metrics collector.
41 42 43 |
# File 'lib/kotoshu/metrics_module.rb', line 41 def collector @collector end |
Class Method Details
.disable ⇒ Object
Disable metrics collection.
26 27 28 29 |
# File 'lib/kotoshu/metrics_module.rb', line 26 def disable @enabled = false @collector = nil end |
.enable ⇒ Object
Enable metrics collection.
20 21 22 23 |
# File 'lib/kotoshu/metrics_module.rb', line 20 def enable @enabled = true @collector = Collector.new end |
.enabled? ⇒ Boolean
Check if metrics are enabled.
34 35 36 |
# File 'lib/kotoshu/metrics_module.rb', line 34 def enabled? @enabled ||= false end |
.record_cache(cache_type, hit:) ⇒ Object
Record a cache operation.
58 59 60 61 62 |
# File 'lib/kotoshu/metrics_module.rb', line 58 def record_cache(cache_type, hit:) return unless enabled? collector&.record_cache(cache_type, hit: hit) end |
.record_lookup(word, result:, time:) ⇒ Object
Record a lookup operation.
48 49 50 51 52 |
# File 'lib/kotoshu/metrics_module.rb', line 48 def record_lookup(word, result:, time:) return unless enabled? collector&.record_lookup(word, result: result, time: time) end |
.record_suggestions(word, count:, time:) ⇒ Object
Record suggestion generation.
69 70 71 72 73 |
# File 'lib/kotoshu/metrics_module.rb', line 69 def record_suggestions(word, count:, time:) return unless enabled? collector&.record_suggestions(word, count: count, time: time) end |
.reset ⇒ Object
Reset all metrics.
85 86 87 88 89 |
# File 'lib/kotoshu/metrics_module.rb', line 85 def reset return unless enabled? collector&.reset end |
.stats ⇒ Hash
Get current metrics statistics.
78 79 80 81 82 |
# File 'lib/kotoshu/metrics_module.rb', line 78 def stats return {} unless enabled? collector&.stats || {} end |
.to_prometheus ⇒ String
Get metrics as Prometheus format.
103 104 105 106 107 |
# File 'lib/kotoshu/metrics_module.rb', line 103 def to_prometheus return "" unless enabled? collector&.to_prometheus || "" end |
.to_statsd ⇒ String
Get metrics as StatsD format.
94 95 96 97 98 |
# File 'lib/kotoshu/metrics_module.rb', line 94 def to_statsd return "" unless enabled? collector&.to_statsd || "" end |