16 | 16 |
if err != nil {
|
17 | 17 |
panic(err)
|
18 | 18 |
}
|
|
19 |
|
|
20 |
registry.AddMetric(c)
|
|
21 |
if err != nil {
|
|
22 |
panic(err)
|
|
23 |
}
|
|
24 |
|
19 | 25 |
return &Counter{c}
|
20 | 26 |
}
|
21 | 27 |
|
|
42 | 48 |
if err != nil {
|
43 | 49 |
panic(err)
|
44 | 50 |
}
|
|
51 |
|
|
52 |
err = registry.AddMetric(g)
|
|
53 |
if err != nil {
|
|
54 |
panic(err)
|
|
55 |
}
|
|
56 |
|
45 | 57 |
return &Gauge{g}
|
46 | 58 |
}
|
47 | 59 |
|
|
64 | 76 |
// NewHistogram creates a new Histogram
|
65 | 77 |
// minimum observeable value is 0
|
66 | 78 |
// maximum observeable value is 3600000000
|
67 | |
func NewHistogram(name string, min, max int64) *Histogram {
|
68 | |
h, err := speed.NewPCPHistogram(name, min, max, 5)
|
|
79 |
func NewHistogram(name string) *Histogram {
|
|
80 |
h, err := speed.NewPCPHistogram(name, 0, 3600000000, 5)
|
69 | 81 |
if err != nil {
|
70 | 82 |
panic(err)
|
71 | 83 |
}
|
|
84 |
|
|
85 |
err = registry.AddMetric(h)
|
|
86 |
if err != nil {
|
|
87 |
panic(err)
|
|
88 |
}
|
|
89 |
|
72 | 90 |
return &Histogram{h}
|
73 | 91 |
}
|
74 | 92 |
|
|
86 | 104 |
|
87 | 105 |
// Percentile returns a percentile between 0 and 100
|
88 | 106 |
func (h *Histogram) Percentile(p float64) int64 { return h.h.Percentile(p) }
|
|
107 |
|
|
108 |
////////////////////////////////////////////////////////////////////////////
|
|
109 |
|
|
110 |
var registry *speed.PCPRegistry
|
|
111 |
var client *speed.PCPClient
|
|
112 |
|
|
113 |
func init() {
|
|
114 |
registry = speed.NewPCPRegistry()
|
|
115 |
}
|
|
116 |
|
|
117 |
// StartReporting starts reporting currently registered metrics to the PCP backend
|
|
118 |
func StartReporting(appname string) {
|
|
119 |
if client != nil {
|
|
120 |
panic("reporting is already enabled")
|
|
121 |
}
|
|
122 |
|
|
123 |
var err error
|
|
124 |
client, err = speed.NewPCPClientWithRegistry(appname, registry)
|
|
125 |
if err != nil {
|
|
126 |
panic(err)
|
|
127 |
}
|
|
128 |
|
|
129 |
client.MustStart()
|
|
130 |
}
|
|
131 |
|
|
132 |
// StopReporting stops all reporting
|
|
133 |
func StopReporting() {
|
|
134 |
if client == nil {
|
|
135 |
panic("reporting is not active")
|
|
136 |
}
|
|
137 |
|
|
138 |
client.MustStop()
|
|
139 |
client = nil
|
|
140 |
}
|