用于采集数据的工具——StatsD
StatsD 最早是 2008 年 Flickr 公司用 Perl 写的针对 Graphite、datadog 等监控数据后端存储开发的前端网络应用,2011 年 Etsy 公司用 node.js 重构。后来其他语言也开发了此功能,它收集数据时基于两大功能:Counting & Timing
StatsD 其实就是一个监听UDP(默认)或者TCP的守护程序,根据简单的协议收集statsd客户端发送来的数据,聚合之后,定时推送给后端,如graphite和influxdb等,再通过grafana等展示。
现在通常指StatsD系统,包括客户端(client)、服务器(server)和后端(backend)三部分。客户端植入于应用代码中,将相应的metrics上报给StatsD server。
下面是 105 实现的例子:
c, err := statsd.New() // Connect to the UDP port 8125 by default. if err != nil { // If nothing is listening on the target port, an error is returned and // the returned client does nothing but is still usable. So we can // just log the error and go on. log.Print(err) } defer c.Close() // Increment a counter. c.Increment("foo.counter") // Gauge something. c.Gauge("num_goroutine", runtime.NumGoroutine()) // Time something. t := c.NewTiming() ping("http://example.com/") t.Send("homepage.response_time") // It can also be used as a one-liner to easily time a function. pingHomepage := func() { defer c.NewTiming().Send("homepage.response_time") ping("http://example.com/") } pingHomepage() // Cloning a Client allows using different parameters while still using the // same connection. // This is way cheaper and more efficient than using New(). stat := c.Clone(statsd.Prefix("http"), statsd.SampleRate(0.2)) stat.Increment("view") // Increments http.view
下面几个是StatsD go 实现
-
105 (Alexcesaro) -- 推荐 38 (GoStatsd) -- 推荐 15 (Cactus) 1 (G2s) 3 (Quipo) 3 (Unix4ever)
上一篇:
Python 安装包管理工具 pip