|
| 1 | +# Evil::Metrics |
| 2 | + |
| 3 | +**This software is Work in Progress: features will appear and disappear, API will be changed, your feedback is always welcome!** |
| 4 | + |
| 5 | +Extensible solution for easy setup of monitoring in your Ruby apps. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Most of the time you don't need to add this gem to your Gemfile directly (unless you're only collecting your custom metrics): |
| 10 | + |
| 11 | +```ruby |
| 12 | +gem 'evil-metrics' |
| 13 | +# Then add monitoring system adapter, e.g.: |
| 14 | +# gem 'evil-metrics-prometheus' |
| 15 | +``` |
| 16 | + |
| 17 | +And then execute: |
| 18 | + |
| 19 | + $ bundle |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | + 1. Declare your metrics: |
| 24 | + |
| 25 | + ```ruby |
| 26 | + Evil::Metrics.configure do |
| 27 | + group :your_app |
| 28 | + |
| 29 | + counter :bells_rang_count, "Total number of bells being rang" |
| 30 | + gauge :whistles_active, "Number of whistles ready to whistle" |
| 31 | + histogram :whistle_runtime, "How long whistles are being active", unit: :seconds |
| 32 | + end |
| 33 | + ``` |
| 34 | + |
| 35 | + 2. Access metric in your app and use it! |
| 36 | + |
| 37 | + ```ruby |
| 38 | + def ring_the_bell(id) |
| 39 | + bell = Bell.find(id) |
| 40 | + bell.ring! |
| 41 | + Evil::Metrics.your_app_bells_rang_count.increment({bell_size: bell.size}, by: 1) |
| 42 | + end |
| 43 | +
|
| 44 | + def whistle! |
| 45 | + Evil::Metrics.your_app_whistle_runtime.measure do |
| 46 | + # Run your code |
| 47 | + end |
| 48 | + end |
| 49 | + ``` |
| 50 | + |
| 51 | + 3. Setup collecting of metrics that do not tied to specific events in you application. E.g.: reporting your app's current state |
| 52 | + ```ruby |
| 53 | + Evil::Metrics.configure do |
| 54 | + # This block will be executed periodically few times in a minute |
| 55 | + # (by timer or external request depending on adapter you're using) |
| 56 | + # Keep it fast and simple! |
| 57 | + collect do |
| 58 | + your_app_whistles_active.set({}, Whistle.where(state: :active).count |
| 59 | + end |
| 60 | + end |
| 61 | + ``` |
| 62 | + |
| 63 | + 4. See the docs for the adapter you're using |
| 64 | + 5. Enjoy! |
| 65 | +
|
| 66 | +## Roadmap (aka TODO or Help wanted) |
| 67 | +
|
| 68 | + - Ability to change metric settings for individual adapters |
| 69 | + |
| 70 | + ```rb |
| 71 | + histogram :foo, comment: "say what?" do |
| 72 | + adapter :prometheus do |
| 73 | + buckets [0.01, 0.5, …, 60, 300, 3600] |
| 74 | + end |
| 75 | + end |
| 76 | + ``` |
| 77 | + |
| 78 | + - Ability to route some metrics only for given adapter: |
| 79 | + |
| 80 | + ```rb |
| 81 | + adapter :prometheus do |
| 82 | + include_group :sidekiq |
| 83 | + end |
| 84 | + ``` |
| 85 | +
|
| 86 | +
|
| 87 | +
|
| 88 | +## Development |
| 89 | +
|
| 90 | +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. |
| 91 | +
|
| 92 | +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
| 93 | +
|
| 94 | +## Contributing |
| 95 | +
|
| 96 | +Bug reports and pull requests are welcome on GitHub at https://github.com/evil-metrics/evil-metrics. |
| 97 | +
|
| 98 | +## License |
| 99 | +
|
| 100 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments