分享 如何持续监控 Unicorn 的性能指标

rubyist518 · April 20, 2016 · Last by assyer replied at April 28, 2016 · 6773 hits
Topic has been selected as the excellent topic by the admin.

背景介绍

最近用 Grape 重写了一份 API,马上要上线了,突然接到 boss 通知,需要做好应用服务器监控,以便上线遇到突发情况。于是乎从万能的 github 上找到了这个开源的代码:unicron_metrics。用起来还不错,下面给大家介绍一下认识。

是什么

unicorn_metrics是采集基于 Rack 应用服务性能数据的工具,尤其针对类似 Unicorn 的多进程服务器,并提供一个对外查看数据的接口。

如何监控

通过 raindrops 来采集Uincorn指标数据,同时通过构建Middleware统计应用中 HTTP 指标数据。

监控指标

unicorn_metrics监控指标分 2 部分:http 指标和 raindrops 指标,下面介绍各方面的指标:

指标名称 指标类型 说明
request.GET timer GET 请求的消耗时间 (ms)
request.POST timer POST 请求的消耗时间 (ms)
request.PUT timer PUT 请求的消耗时间 (ms)
request.DELETE timer DELETE 请求的消耗时间 (ms)
request.HEAD timer HEAD 请求的消耗时间 (ms)
responses.2xx counter 响应状态为 2xx 的次数
responses.3xx counter 响应状态为 3xx 的次数
responses.4xx counter 响应状态为 4xx 的次数
responses.5xx counter 响应状态为 5xx 的次数
raindrops.calling gauge 应用服务器调度的数量
raindrops.writing gauge 被写入数据的客户端的数量
raindrops.active gauge 所有进程中已连接并尚未关闭的 sockets 的连接数
raindrops.queued gauge 等待连接 sockets 的请求数

监控步骤

1.安装

$ gem 'unicorn_metrics', github: 'superiorlu/unicorn_metrics'
$ bundle

2.配置 unincor_metric.rb

#config/initializers/unicorn_metrics.rb

if defined?(UnicornMetrics)
  UnicornMetrics.configure do |c|
    c.app_name = 'app_name'
  end
end

3.配置 config.ru (Rails 无需配置)

# config.ru

 require 'unicorn_metrics/middleware'
 use UnicornMetrics::Middleware
 # other middleware...
 run N::Application

4.visit http://localhost:3000/metrics, 返回 unicorn 的各方面的指标。

实时监控和报警

由于unicorn_metrics只提供了查看unicorn性能指标的接口,根据业务的需求我们对其进行了修改,使其可以在装有我们 CloudInsight 探针 的服务器上使用 Cloud Insight Ruby SDK 进行实时回传性能数据,形成 dashboard 图表同时在服务器出现问题时及时报警。具体数据图表 见下图:

数据图表组成仪表盘示例:http://superiorlu.github.io/dashboards.html

源码见:https://github.com/superiorlu/unicorn_metrics

小结

本文介绍了使用unicorn_metrisUnicorn进行持续监控。使用Cloud Insight Ruby SDK,不但可以传输性能数据,还可以传输自定义的业务数据,将数据以图表的展示出来,并根据需求添加相应的报警服务。

有保 JSON API 给出指标数据,那就可以用 Telegraf 的 httpjson 插件直接收集到 InfluxDB 啦!

相关:https://ruby-china.org/topics/23470

@huacnlee 恩呢 已经拜读过了🙏

回头我试试,看起来用的人不多呢

Cool, 结合Zabbix去绘图统一监控!

graphite+grafana 不过需要把日志配置的完善一些

You need to Sign in before reply, if you don't have an account, please Sign up first.