百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

ruby-metrics

> 编程语言
开源

metrics for ruby - 这是一个由 @coda 的 JVM metrics 所启发的 Ruby 实现的 metrics,适用于 Ruby 社区的用户

364 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

metrics for ruby - 这是一个由 @coda 的 JVM metrics 所启发的 Ruby 实现的 metrics,适用于 Ruby 社区的用户

What is this?

This is a Ruby version of performance metrics inspired by metrics developed by Coda Hale at Yammer. Currently this is under heavy development -- it needs Gem packaging, more features, validation of metrics, more functional testing, and a little better test coverage. Pull requests happily accepted, please include docs and tests where possible!

What needs to be done?

Among other important things, this needs to be made more thread-safe. I'm currently looking at Mr. Nutter's ruby-atomic gem for making this less tedious but any suggestions are welcome!

What's in this?

Right now, I have:

  • Counters
  • Meters
  • Gauges
  • Histograms w/ uniform sampling
  • Histograms w/ exponentially decaying sampling
  • Timers

Getting Started

The goal of ruby-metrics is to get up and running quickly. You start an agent, register some instruments, and they're exported over HTTP via JSON. For example, getting started with a counter would look like this:

@metrics = Metrics::Agent.new

counter = @metrics.counter :my_counter
counter.incr
counter.incr

puts @metrics.to_json
#=> {"my_counter":"2"}

Integration

Integrating ruby-metrics into existing applications is entirely up to your needs. Provided options include:

  • Embedded WEBrick listener:

    This runs a background thread and enables HTTP access to a local port (8001 by default) for a JSON representation of the current metrics.

ruby
require 'ruby-metrics/integration/webrick'
@agent = Metrics::Agent.new
@agent.start(:port => 8081)
  • Rack Middleware:

    This will add metrics such as requests (a timer) as well as counters for each class of HTTP status code (1xx, 2xx, etc). Also counts uncaught exceptions before reraising. Provides a configurable path option (:show) to trigger the return of the metrics (as JSON) when the request path matches exactly (a string), as a regular expression, or as any object that responds to call for custom logic (passed the whole env).

ruby
require 'ruby-metrics'
@agent = Metrics::Agent.new

use Metrics::Integration::Rack::Middleware, :agent => @agent, :show => '/stats'

run app
  • Rack Endpoint:

    Use this to expose an endpoint for external consumption for your metrics. Works best when used with a URLMap or mounted in addition to other routes, like Rails' mount route matcher.

ruby
require 'ruby-metrics'
@agent = Metrics::Agent.new

run Metrics::Integration::Rack::Endpoint.new(:agent => @agent)

or

ruby
# in config/router.rb
mount Metrics::Integration::Rack::Endpoint.new(:agent => @agent)

License

Copyright 2011-2014 John Ewart . Released under the MIT license. See the file LICENSE for further details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言