netdata/go-statsd is a Backend project on GitHub, written primarily in Go. It has 62 stars. A simple, efficient StatsD Client for Go.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
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.
How does netdata/go-statsd compare to other Backend projects?
netdata/go-statsd is tracked by TopGit in the Backend category, with 62 GitHub stars and written in Go. Browse the Backend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does netdata/go-statsd have?
netdata/go-statsd has 62 GitHub stars — refresh the page for the live number, or check github.com/netdata/go-statsd. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is netdata/go-statsd open source?
Yes — netdata/go-statsd ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/netdata/go-statsd.
What else is in the Backend space?
netdata/go-statsd is tracked by TopGit under the Backend category, alongside 3 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What is netdata/go-statsd?
netdata/go-statsd (netdata/go-statsd) is a Go project on GitHub. From the project's own README: A simple, efficient StatsD Client for Go.
Where can I see netdata/go-statsd in action?
The project maintains a homepage at https://godoc.org/github.com/netdata/statsd. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about netdata/go-statsd?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/netdata/go-statsd is the definitive source.
Read full README in the tab above.
Want a second opinion on go-statsd?
Ask an AI that can read this page — one click and you get its take on go-statsd.