MetricsMonitor is dynamic monitoring tool for ruby application.
- Monitor multi process ruby application
- Monitor basic metrics by builtin collector
- Monitor custom metrics
- Save monitoring result to single html file
Add this line to your application's Gemfile:
gem "metrics_monitor", require: "metrics_monitor/setup"
If you want to customize, add this line to your application's Gemfile:
gem "metrics_monitor"
and configure like this:
require_relative "metrics_monitor"
MetricsMonitor::Collector::ObjectStatCollector.configure do |options|
options[:interval] = 5_000
options[:memsize_threshold] = 5000
end
MetricsMonitor.configure do |config|
config.collectors << MetricsMonitor::Collector::ObjectStatCollector
config.exclude_main_process = true
end
collectors
: Array of collector classexclude_main_process
: Exclude main process from monitoring (when using multi process application)
enabled
: Enable or disable collector when startinginterval
: Interval of collecting metrics (ms)- other options: Depends on collector
MetricsMonitor can monitor multi process application.
When using multi process application, you should start MetricsMonitor in each processes.
If you use unicorn
, you can start MetricsMonitor like this:
after_fork do |_server, worker|
MetricsMonitor.monitor.watch(worker.nr)
end
You could set exclude_main_process
to true
in MetricsMonitor config to exclude main process from monitoring.
Basic metrics collector like cpu, memory and etc.
Garbage collection statistics collector.
Object statistics collector.
Object tracing data collector.
You can create custom collector by referring to lib/metrics_monitor/collector.
Below is an example of a custom collector.
class RandomCollector < MetricsMonitor::Collector::CollectorBase
def self.default_options
{ enabled: true, interval: 5_000 }
end
def meta_data
{
title: "Random",
monitors: [
{ key: :random, title: "Random values", type: :chart, mode: :line },
],
data: {
random: { mode: "append" },
},
}
end
def data
{
random: rand,
}
end
end
This collector generates random values and displays them in a chart.
Bug reports and pull requests are welcome on GitHub at https://github.com/hogelog/metrics_monitor.
The gem is available as open source under the terms of the MIT License.