We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code
package main import ( "fmt" "io/ioutil" "net/http" "net/http/httptest" "time" "go.uber.org/net/metrics" ) func main() { // First, construct a root and add some metrics. root := metrics.New() h, err := root.Scope().Histogram(metrics.HistogramSpec{ Spec: metrics.Spec{ Name: "selects_latency_ms", // required, should indicate unit Help: "SELECT query latency.", // required }, Unit: time.Millisecond, // required Buckets: []int64{5, 10, 25, 50, 100, 200, 500}, // required }) if err != nil { panic(err) } h.IncBucket(5) h.IncBucket(501) // Expose the root on your HTTP server of choice. mux := http.NewServeMux() mux.Handle("/debug/net/metrics", root) srv := httptest.NewServer(mux) defer srv.Close() // Your metrics are now exposed via a Prometheus-compatible handler. This // example shows text output, but clients can also request the protocol // buffer binary format. res, err := http.Get(fmt.Sprintf("%v/debug/net/metrics", srv.URL)) if err != nil { panic(err) } text, err := ioutil.ReadAll(res.Body) res.Body.Close() if err != nil { panic(err) } fmt.Println(string(text)) }
output
# HELP selects_latency_ms SELECT query latency. # TYPE selects_latency_ms histogram selects_latency_ms_bucket{host="db01",table="trips",le="5"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="10"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="25"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="50"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="100"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="200"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="500"} 2 selects_latency_ms_bucket{host="db01",table="trips",le="+Inf"} 2 selects_latency_ms_sum{host="db01",table="trips"} 506 selects_latency_ms_count{host="db01",table="trips"} 2
system macos golang 1.15
The text was updated successfully, but these errors were encountered:
BUG on file go.uber.org/net/[email protected]/histogram.go:162
func (h *Histogram) metric() *promproto.Metric { n := uint64(0) promBuckets := make([]*promproto.Bucket, 0, len(h.buckets)-1) for _, b := range h.buckets { n += uint64(b.Load()) if b.upper == math.MaxInt64 { // Prometheus doesn't want us to export the final catch-all bucket. continue } upper := float64(b.upper) promBuckets = append(promBuckets, &promproto.Bucket{ CumulativeCount: &n, UpperBound: &upper, }) } sum := float64(h.sum.Load()) return &promproto.Metric{ Label: h.tagPairs, Histogram: &promproto.Histogram{ SampleCount: &n, SampleSum: &sum, Bucket: promBuckets, }, } }
Sorry, something went wrong.
No branches or pull requests
code
output
system macos
golang 1.15
The text was updated successfully, but these errors were encountered: