Skip to content

Commit 23b465b

Browse files
committed
Rename Evil Metrics to Yabeda
1 parent b9626a8 commit 23b465b

22 files changed

+211
-227
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ source "https://rubygems.org"
44

55
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

7-
# Specify your gem's dependencies in evil-metrics.gemspec
7+
# Specify your gem's dependencies in yabeda.gemspec
88
gemspec
99

1010
group :development, :test do

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Evil::Metrics
1+
# Yabeda
22

33
**This software is Work in Progress: features will appear and disappear, API will be changed, your feedback is always welcome!**
44

@@ -9,9 +9,9 @@ Extensible solution for easy setup of monitoring in your Ruby apps.
99
Most of the time you don't need to add this gem to your Gemfile directly (unless you're only collecting your custom metrics):
1010

1111
```ruby
12-
gem 'evil-metrics'
12+
gem 'yabeda'
1313
# Then add monitoring system adapter, e.g.:
14-
# gem 'evil-metrics-prometheus'
14+
# gem 'yabeda-prometheus'
1515
```
1616

1717
And then execute:
@@ -23,7 +23,7 @@ And then execute:
2323
1. Declare your metrics:
2424

2525
```ruby
26-
Evil::Metrics.configure do
26+
Yabeda.configure do
2727
group :your_app
2828

2929
counter :bells_rang_count, "Total number of bells being rang"
@@ -38,19 +38,19 @@ And then execute:
3838
def ring_the_bell(id)
3939
bell = Bell.find(id)
4040
bell.ring!
41-
Evil::Metrics.your_app_bells_rang_count.increment({bell_size: bell.size}, by: 1)
41+
Yabeda.your_app_bells_rang_count.increment({bell_size: bell.size}, by: 1)
4242
end
4343
4444
def whistle!
45-
Evil::Metrics.your_app_whistle_runtime.measure do
45+
Yabeda.your_app_whistle_runtime.measure do
4646
# Run your code
4747
end
4848
end
4949
```
5050

5151
3. Setup collecting of metrics that do not tied to specific events in you application. E.g.: reporting your app's current state
5252
```ruby
53-
Evil::Metrics.configure do
53+
Yabeda.configure do
5454
# This block will be executed periodically few times in a minute
5555
# (by timer or external request depending on adapter you're using)
5656
# Keep it fast and simple!
@@ -93,7 +93,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
9393
9494
## Contributing
9595
96-
Bug reports and pull requests are welcome on GitHub at https://github.com/evil-metrics/evil-metrics.
96+
Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda.
9797
9898
## License
9999

bin/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
require "bundler/setup"
5-
require "evil/metrics"
5+
require "yabeda"
66

77
# You can add fixtures and/or initialization code here to make experimenting
88
# with your gem easier. You can also use a different console, if you like.

lib/evil/metrics.rb

-28
This file was deleted.

lib/evil/metrics/base_adapter.rb

-40
This file was deleted.

lib/evil/metrics/counter.rb

-20
This file was deleted.

lib/evil/metrics/dsl.rb

-55
This file was deleted.

lib/evil/metrics/gauge.rb

-16
This file was deleted.

lib/evil/metrics/histogram.rb

-17
This file was deleted.

lib/evil/metrics/metric.rb

-27
This file was deleted.

lib/evil/metrics/version.rb

-7
This file was deleted.

lib/yabeda.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
require "concurrent"
4+
5+
require "yabeda/version"
6+
require "yabeda/dsl"
7+
8+
module Yabeda
9+
include DSL
10+
11+
cattr_reader :metrics, default: Concurrent::Hash.new
12+
cattr_reader :adapters, default: Concurrent::Hash.new
13+
cattr_reader :collectors, default: Concurrent::Array.new
14+
15+
class << self
16+
# @param [Symbol] name
17+
# @param [BaseAdapter] instance
18+
def register_adapter(name, instance)
19+
adapters[name] = instance
20+
# NOTE: Pretty sure there is race condition
21+
metrics.each do |_, metric|
22+
instance.register!(metric)
23+
end
24+
end
25+
end
26+
end

lib/yabeda/base_adapter.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module Yabeda
4+
class BaseAdapter
5+
def register!(metric)
6+
case metric
7+
when Counter then register_counter!(metric)
8+
when Gauge then register_gauge!(metric)
9+
when Histogram then register_histogram!(metric)
10+
else raise "#{metric.class} is unknown metric type"
11+
end
12+
end
13+
14+
def register_counter!(_metric)
15+
raise NotImplementedError, "#{self.class} doesn't support counters as metric type!"
16+
end
17+
18+
def perform_counter_increment!(_counter, _tags, _increment)
19+
raise NotImplementedError, "#{self.class} doesn't support incrementing counters"
20+
end
21+
22+
def register_gauge!(_metric)
23+
raise NotImplementedError, "#{self.class} doesn't support gauges as metric type!"
24+
end
25+
26+
def perform_gauge_set!(_metric, _tags, _value)
27+
raise NotImplementedError, "#{self.class} doesn't support setting gauges"
28+
end
29+
30+
def register_histogram!(_metric)
31+
raise NotImplementedError, "#{self.class} doesn't support histograms as metric type!"
32+
end
33+
34+
def perform_histogram_measure!(_metric, _tags, _value)
35+
raise NotImplementedError, "#{self.class} doesn't support measuring histograms"
36+
end
37+
end
38+
end

lib/yabeda/counter.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module Yabeda
4+
# Growing-only counter
5+
class Counter < Metric
6+
def increment(tags, by: 1)
7+
values[tags] += by
8+
::Yabeda.adapters.each do |_, adapter|
9+
adapter.perform_counter_increment!(self, tags, by)
10+
end
11+
values[tags]
12+
end
13+
14+
def values
15+
@values ||= Concurrent::Hash.new(0)
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)