-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsink.go
59 lines (51 loc) · 1.56 KB
/
sink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package stats
// MetricsSnapshot represents the metrics snapshot in a particular time.
type MetricsSnapshot interface {
// Gauges returns all known guages.
Gauges() []*Gauge
// Counters returns all known counters.
Counters() []*Counter
// Histograms returns all known histograms.
Histograms() []*Histogram
}
var _ MetricsSnapshot = new(metricsSnapshot)
type metricsSnapshot struct {
gauges []*Gauge
counters []*Counter
histograms []*Histogram
}
func newMetricsSnapshot(gauges []*Gauge, counters []*Counter, histograms []*Histogram) *metricsSnapshot {
snap := &metricsSnapshot{
gauges: gauges,
counters: counters,
histograms: histograms,
}
// refresh counter interval value.
for _, counter := range snap.counters {
counter.Latch()
}
// refresh histogram interval stattistic.
for _, histogram := range snap.histograms {
histogram.RefreshIntervalStatistics()
}
return snap
}
func (snap *metricsSnapshot) Gauges() []*Gauge {
return snap.gauges
}
func (snap *metricsSnapshot) Counters() []*Counter {
return snap.counters
}
func (snap *metricsSnapshot) Histograms() []*Histogram {
return snap.histograms
}
// Sink is a sink for stats. Each Sink is responsible for writing stats
// to a backing store.
type Sink interface {
// Flush flushes periodic metrics to the backing store.
Flush(MetricsSnapshot) error
// WriteHistogram writes a single histogram sample to the backing store directly.
// It is only used to be compatible with the TSDB which doesn't support
// pre-aggreated histogram data.
WriteHistogramSample(h *Histogram, val uint64) error
}