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,
下面是 GitHub - alexcesaro/statsd: An efficient Statsd Go client.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 實作
- https://github.com/alexcesaro/statsd/105 (Alexcesaro) -- 推薦
- https://github.com/smira/go-statsd38 (GoStatsd) -- 推薦
- https://github.com/cactus/go-statsd-client15 (Cactus)
- https://github.com/peterbourgon/g2s1 (G2s)
- https://github.com/quipo/statsd3 (Quipo)
- https://github.com/Unix4ever/statsd3 (Unix4ever)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/339128.html
標籤:其他
上一篇:Nmap
下一篇:史上最全 IT 類學習資源
