Package list golang-github-go-kit-kit / c023ab7
code review cleanup JP Robinson 5 years ago
2 changed file(s) with 14 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
1717 "time"
1818
1919 "github.com/codahale/hdrhistogram"
20
2021 "github.com/go-kit/kit/log"
2122 "github.com/go-kit/kit/metrics"
2223 )
2324
24 // Newcounter will return a metrics.counter with the given name and a base
25 // value of 0.
2625 func newCounter(name string) *counter {
2726 return &counter{name, 0}
2827 }
2928
30 // Newgauge will return a metrics.gauge with the given name and a starting
31 // value of 0.
3229 func newGauge(name string) *gauge {
3330 return &gauge{name, 0}
3431 }
5249
5350 // flush will emit the current counter value in the Graphite plaintext
5451 // 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())
5754 }
5855
5956 // gauge implements the metrics.gauge interface but also provides a
8986
9087 // Flush will emit the current gauge value in the Graphite plaintext
9188 // 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())
9491 }
9592
9693 // windowedHistogram is taken from http://github.com/codahale/metrics. It
162159 return buckets, quantiles
163160 }
164161
165 func (h *windowedHistogram) flush(conn io.Writer, prefix string) {
162 func (h *windowedHistogram) flush(w io.Writer, prefix string) {
166163 name := prefix + h.Name()
167164 hist := h.hist.Merge()
168165 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)
174171 }
175172
176173 func (h *windowedHistogram) rotateLoop(d time.Duration) {
1010 type Dialer func(network, address string) (net.Conn, error)
1111
1212 // time.After is a good default afterFunc.
13 type afterFunc func(time.Duration) <-chan time.Time
13 type AfterFunc func(time.Duration) <-chan time.Time
1414
1515 // Manager manages a net.Conn. Clients should take the conn when they want to
1616 // use it, and put back whatever error they receive from an e.g. Write. When a
2020 dial Dialer
2121 network string
2222 address string
23 after afterFunc
23 after AfterFunc
2424 logger log.Logger
2525
2626 takec chan net.Conn
2727 putc chan error
2828 }
2929
30 func NewManager(d Dialer, network, address string, after afterFunc, logger log.Logger) *Manager {
30 func NewManager(d Dialer, network, address string, after AfterFunc, logger log.Logger) *Manager {
3131 m := &Manager{
3232 dial: d,
3333 network: network,