Codebase list golang-github-go-kit-kit / fe3c57e
metrics/pcp: add more comments and fix comment block widths Suyash 7 years ago
1 changed file(s) with 19 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1111 }
1212
1313 // 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.
1717 func NewReporter(appname string) (*Reporter, error) {
1818 c, err := speed.NewPCPClient(appname)
1919 if err != nil {
3838
3939 // NewCounter creates a new Counter.
4040 //
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.
4344 func (r *Reporter) NewCounter(name string, desc ...string) (*Counter, error) {
4445 c, err := speed.NewPCPCounter(0, name, desc...)
4546 if err != nil {
5455 func (c *Counter) With(labelValues ...string) metrics.Counter { return c }
5556
5657 // 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.
5961 func (c *Counter) Add(delta float64) { c.c.Inc(int64(delta)) }
6062
6163 // Gauge implements metrics.Gauge via a single dimensional speed.Gauge.
6567
6668 // NewGauge creates a new Gauge.
6769 //
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.
6972 func (r *Reporter) NewGauge(name string, desc ...string) (*Gauge, error) {
7073 g, err := speed.NewPCPGauge(0, name, desc...)
7174 if err != nil {
9194 }
9295
9396 // 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.
9699 //
97100 // The required parameters are a metric name,
98101 // the minimum and maximum observable values,
114117
115118 // Observe observes a value.
116119 //
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.
119124 func (h *Histogram) Observe(value float64) { h.h.MustRecord(int64(value)) }
120125
121126 // Mean returns the mean of the values observed so far by the Histogram.
122127 func (h *Histogram) Mean() float64 { return h.h.Mean() }
123128
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.
126131 func (h *Histogram) Percentile(p float64) int64 { return h.h.Percentile(p) }