Trên GitHub, netdata/go-statsd đã đạt 62 sao, nhóm Backend, ngôn ngữ Go. A simple, efficient StatsD Client for Go.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
statsd is a simple, efficient StatsD client written in Go.
Features
Works great with netdata
Supports Counting, Sampling, Timing, Gauges, Sets and Histograms out of the box
Extendable: Ability to send custom metric values and types
It is blazing fast and does not allocate unnecessary memory. Metrics are sent based on a customized packet size, manual flushing of buffered metrics is also an option
Beautiful, easy to learn API
Easy to test
Protocol-agnostic
Installation
The only requirement is the Go Programming Language.
$ go get -u github.com/netdata/statsd
Quick start
statsd is simple, it won't take more than 10 minutes of your time to read all of its documentation via godocs.
API
// NewClient returns a new StatsD client.
// The first input argument, "writeCloser", should be a value which implements
// the `io.WriteCloser` interface.
// It can be a UDP connection or a string buffer or even STDOUT for testing.
// The second input argument, "prefix" can be empty
// but it is usually the app's name and a single dot.
NewClient(writeCloser io.WriteCloser, prefix string) *Client
Client {
SetMaxPackageSize(maxPacketSize int)
SetFormatter(fmt func(metricName string) string)
FlushEvery(dur time.Duration)
IsClosed() bool
Close() error
WriteMetric(metricName, value, typ string, rate float32) error
Flush(n int) error
Count(metricName string, value int) error
Increment(metricName string) error
Gauge(metricName string, value int) error
Unique(metricName string, value int) error
Time(metricName string, value time.Duration) error
Record(metricName string, rate float32) func() error
Histogram(metricName string, value int) error
}
const (
// Count is the "c" Counting statsd metric type.
Count string = "c"
// Gauge is the "g" Gauges statsd metric type.
Gauge string = "g"
// Unique is the "s" Sets statsd metric type.
Unique string = "s"
// Set is an alias for "Unique"
Set = Unique
// Time is the "ms" Timing statsd metric type.
Time string = "ms"
// Histogram is the "h" metric type,
// difference from `Time` metric type is that `Time` writes milleseconds.
// Read more at: https://docs.netdata.cloud/collectors/statsd.plugin/
Histogram string = "h"
)
Read more at: https://github.com/etsy/statsd/blob/master/docs/metric_types.md
Example
Assuming you have a statsd server running at :8125 (default port).
# assume the following codes in example.go file
$ cat example.go
package main
import (
"fmt"
"net/http"
"strings"
"time"
"github.com/netdata/statsd"
)
// statusCodeReporter is a compatible `http.ResponseWriter`
// which stores the `statusCode` for further reporting.
type statusCodeReporter struct {
http.ResponseWriter
written bool
statusCode int
}
func (w *statusCodeReporter) WriteHeader(statusCode int) {
if w.written {
return
}
w.statusCode = statusCode
w.ResponseWriter.WriteHeader(statusCode)
}
func (w *statusCodeReporter) Write(b []byte) (int, error) {
w.written = true
return w.ResponseWriter.Write(b)
}
func main() {
statsWriter, err := statsd.UDP(":8125")
if err != nil {
panic(err)
}
statsD := statsd.NewClient(statsWriter, "prefix.")
statsD.FlushEvery(5 * time.Second)
statsDMiddleware := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if len(path) == 1 {
path = "index" // for root.
} else if path == "/favicon.ico" {
next.ServeHTTP(w, r)
return
} else {
path = path[1:]
path = strings.Replace(path, "/", ".", -1)
}
statsD.Increment(fmt.Sprintf("%s.request", path))
newResponseWriter := &statusCodeReporter{ResponseWriter: w, statusCode: http.StatusOK}
stop := statsD.Record(fmt.Sprintf("%s.time", path), 1)
next.ServeHTTP(newResponseWriter, r)
stop()
statsD.Increment(fmt.Sprintf("%s.response.%d", path, newResponseWriter.statusCode))
})
}
mux := http.DefaultServeMux
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello from index")
})
mux.HandleFunc("/other", func(w http.ResponseWriter, r *http.Request) {
statsD.Unique("other.unique", 1)
fmt.Fprintln(w, "Hello from other page")
})
http.ListenAndServe(":8080", statsDMiddleware(mux))
}
# run example.go and visit http://localhost:8080/other
$ go run example.go
Navigate here to see more examples.
License
The go-statsd library is licensed under the MIT License.
netdata/go-statsd thuộc nhóm Backend trên TopGit, cùng 3 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về netdata/go-statsd ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/netdata/go-statsd là nguồn chính thức.
netdata/go-statsd có bao nhiêu sao?
netdata/go-statsd có 62 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/netdata/go-statsd. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
netdata/go-statsd có phải mã nguồn mở không?
Có — netdata/go-statsd phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/netdata/go-statsd.
netdata/go-statsd có trang demo không?
Dự án có trang chủ ở https://godoc.org/github.com/netdata/statsd. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
netdata/go-statsd là gì?
netdata/go-statsd (netdata/go-statsd) là dự án Go trên GitHub. Theo mô tả gốc: A simple, efficient StatsD Client for Go.
netdata/go-statsd so với các dự án Backend khác thế nào?
netdata/go-statsd được TopGit xếp vào nhóm Backend, với 62 sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
go-statsd có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về go-statsd.