17 | 17 |
"time"
|
18 | 18 |
|
19 | 19 |
"github.com/codahale/hdrhistogram"
|
|
20 |
|
20 | 21 |
"github.com/go-kit/kit/log"
|
21 | 22 |
"github.com/go-kit/kit/metrics"
|
22 | 23 |
)
|
23 | 24 |
|
24 | |
// Newcounter will return a metrics.counter with the given name and a base
|
25 | |
// value of 0.
|
26 | 25 |
func newCounter(name string) *counter {
|
27 | 26 |
return &counter{name, 0}
|
28 | 27 |
}
|
29 | 28 |
|
30 | |
// Newgauge will return a metrics.gauge with the given name and a starting
|
31 | |
// value of 0.
|
32 | 29 |
func newGauge(name string) *gauge {
|
33 | 30 |
return &gauge{name, 0}
|
34 | 31 |
}
|
|
52 | 49 |
|
53 | 50 |
// flush will emit the current counter value in the Graphite plaintext
|
54 | 51 |
// protocol to the given io.Writer.
|
55 | |
func (c *counter) flush(conn io.Writer, prefix string) {
|
56 | |
fmt.Fprintf(conn, "%s.count %d %d\n", prefix+c.Name(), c.get(), time.Now().Unix())
|
|
52 |
func (c *counter) flush(w io.Writer, prefix string) {
|
|
53 |
fmt.Fprintf(w, "%s.count %d %d\n", prefix+c.Name(), c.get(), time.Now().Unix())
|
57 | 54 |
}
|
58 | 55 |
|
59 | 56 |
// gauge implements the metrics.gauge interface but also provides a
|
|
89 | 86 |
|
90 | 87 |
// Flush will emit the current gauge value in the Graphite plaintext
|
91 | 88 |
// protocol to the given io.Writer.
|
92 | |
func (g *gauge) flush(conn io.Writer, prefix string) {
|
93 | |
fmt.Fprintf(conn, "%s %.2f %d\n", prefix+g.Name(), g.Get(), time.Now().Unix())
|
|
89 |
func (g *gauge) flush(w io.Writer, prefix string) {
|
|
90 |
fmt.Fprintf(w, "%s %.2f %d\n", prefix+g.Name(), g.Get(), time.Now().Unix())
|
94 | 91 |
}
|
95 | 92 |
|
96 | 93 |
// windowedHistogram is taken from http://github.com/codahale/metrics. It
|
|
162 | 159 |
return buckets, quantiles
|
163 | 160 |
}
|
164 | 161 |
|
165 | |
func (h *windowedHistogram) flush(conn io.Writer, prefix string) {
|
|
162 |
func (h *windowedHistogram) flush(w io.Writer, prefix string) {
|
166 | 163 |
name := prefix + h.Name()
|
167 | 164 |
hist := h.hist.Merge()
|
168 | 165 |
now := time.Now().Unix()
|
169 | |
fmt.Fprintf(conn, "%s.count %d %d\n", name, hist.TotalCount(), now)
|
170 | |
fmt.Fprintf(conn, "%s.min %d %d\n", name, hist.Min(), now)
|
171 | |
fmt.Fprintf(conn, "%s.max %d %d\n", name, hist.Max(), now)
|
172 | |
fmt.Fprintf(conn, "%s.mean %.2f %d\n", name, hist.Mean(), now)
|
173 | |
fmt.Fprintf(conn, "%s.std-dev %.2f %d\n", name, hist.StdDev(), now)
|
|
166 |
fmt.Fprintf(w, "%s.count %d %d\n", name, hist.TotalCount(), now)
|
|
167 |
fmt.Fprintf(w, "%s.min %d %d\n", name, hist.Min(), now)
|
|
168 |
fmt.Fprintf(w, "%s.max %d %d\n", name, hist.Max(), now)
|
|
169 |
fmt.Fprintf(w, "%s.mean %.2f %d\n", name, hist.Mean(), now)
|
|
170 |
fmt.Fprintf(w, "%s.std-dev %.2f %d\n", name, hist.StdDev(), now)
|
174 | 171 |
}
|
175 | 172 |
|
176 | 173 |
func (h *windowedHistogram) rotateLoop(d time.Duration) {
|