metrics/pcp: add more comments and fix comment block widths
Suyash
7 years ago
11 | 11 | } |
12 | 12 | |
13 | 13 | // NewReporter creates a new Reporter instance. |
14 | // The first parameter is the application name and is used to create the speed client. | |
15 | // Hence it should be a valid speed parameter name and should not contain spaces or the path separator | |
16 | // for your operating system. | |
14 | // The first parameter is the application name and is used to create | |
15 | // the speed client. Hence it should be a valid speed parameter name and | |
16 | // should not contain spaces or the path separator for your operating system. | |
17 | 17 | func NewReporter(appname string) (*Reporter, error) { |
18 | 18 | c, err := speed.NewPCPClient(appname) |
19 | 19 | if err != nil { |
38 | 38 | |
39 | 39 | // NewCounter creates a new Counter. |
40 | 40 | // |
41 | // This requires a name parameter and can optionally take a couple of description | |
42 | // strings, that are used to create the underlying speed.Counter and are reported by PCP. | |
41 | // This requires a name parameter and can optionally take a couple of | |
42 | // description strings, that are used to create the underlying speed.Counter | |
43 | // and are reported by PCP. | |
43 | 44 | func (r *Reporter) NewCounter(name string, desc ...string) (*Counter, error) { |
44 | 45 | c, err := speed.NewPCPCounter(0, name, desc...) |
45 | 46 | if err != nil { |
54 | 55 | func (c *Counter) With(labelValues ...string) metrics.Counter { return c } |
55 | 56 | |
56 | 57 | // Add implements Counter. |
57 | // speed Counters only take int64. | |
58 | // speed Gauges can take float64 and Add(float64) is implemented by metrics.Gauge. | |
58 | // speed Counters only take int64, so delta is converted to int64 before | |
59 | // observation. speed Gauges can take float64 and Add(float64) | |
60 | // is implemented by metrics.Gauge. | |
59 | 61 | func (c *Counter) Add(delta float64) { c.c.Inc(int64(delta)) } |
60 | 62 | |
61 | 63 | // Gauge implements metrics.Gauge via a single dimensional speed.Gauge. |
65 | 67 | |
66 | 68 | // NewGauge creates a new Gauge. |
67 | 69 | // |
68 | // This requires a name parameter, and again, can take a couple of optional description strings. | |
70 | // This requires a name parameter, and again, can take a couple of | |
71 | // optional description strings. | |
69 | 72 | func (r *Reporter) NewGauge(name string, desc ...string) (*Gauge, error) { |
70 | 73 | g, err := speed.NewPCPGauge(0, name, desc...) |
71 | 74 | if err != nil { |
91 | 94 | } |
92 | 95 | |
93 | 96 | // NewHistogram creates a new Histogram. |
94 | // minimum observeable value is 0. | |
95 | // maximum observeable value is 3600000000. | |
97 | // Minimum observeable value is 0. | |
98 | // Maximum observeable value is 3600000000. | |
96 | 99 | // |
97 | 100 | // The required parameters are a metric name, |
98 | 101 | // the minimum and maximum observable values, |
114 | 117 | |
115 | 118 | // Observe observes a value. |
116 | 119 | // |
117 | // this converts float64 value to int64, as the Histogram in speed | |
118 | // is backed using codahale/hdrhistogram, which only observes int64 values. | |
120 | // this converts float64 value to int64 before observation, as the Histogram in | |
121 | // speed is backed using codahale/hdrhistogram, which only observes int64 | |
122 | // values. Additionally, the value is interpreted in the metric unit used to | |
123 | // construct the histogram. | |
119 | 124 | func (h *Histogram) Observe(value float64) { h.h.MustRecord(int64(value)) } |
120 | 125 | |
121 | 126 | // Mean returns the mean of the values observed so far by the Histogram. |
122 | 127 | func (h *Histogram) Mean() float64 { return h.h.Mean() } |
123 | 128 | |
124 | // Percentile returns a percentile value for the given percentile between 0 and 100 | |
125 | // for all values observed by the histogram. | |
129 | // Percentile returns a percentile value for the given percentile | |
130 | // between 0 and 100 for all values observed by the histogram. | |
126 | 131 | func (h *Histogram) Percentile(p float64) int64 { return h.h.Percentile(p) } |