-
Notifications
You must be signed in to change notification settings - Fork 3
/
metric.go
113 lines (98 loc) · 2.84 KB
/
metric.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package sched
import (
"fmt"
"time"
"github.com/uber-go/tally"
)
type metrics struct {
up tally.Gauge
runs tally.Counter
overlappingCount tally.Counter
runActualElapsed tally.Timer
runTotalElapsed tally.Timer
runErrors tally.Counter
runExceedExpected tally.Counter
}
func newMetrics(name string, metricsScope tally.Scope) *metrics {
subScope := metricsScope.SubScope("sched")
return &metrics{
up: subScope.Tagged(map[string]string{"id": name}).Gauge("up"),
runs: subScope.Tagged(map[string]string{"id": name}).Counter("runs"),
overlappingCount: subScope.Tagged(map[string]string{"id": name}).Counter("runs_overlapping"),
runActualElapsed: subScope.Tagged(map[string]string{"id": name}).Timer("run_actual_elapsed_time"),
runTotalElapsed: subScope.Tagged(map[string]string{"id": name}).Timer("run_total_elapsed_time"),
runErrors: subScope.Tagged(map[string]string{"id": name}).Counter("run_errors"),
runExceedExpected: subScope.Tagged(map[string]string{"id": name}).Counter("run_exceed_expected_time"),
}
}
type consoleStatsReporter struct {
logger Logger
}
func newConsoleStatsReporter(logger Logger) *consoleStatsReporter {
return &consoleStatsReporter{logger: logger}
}
func (r *consoleStatsReporter) ReportCounter(name string, tags map[string]string, value int64) {
r.logger.Infow(fmt.Sprintf("counter %s", name), "name", name, "value", value, "tags", tags)
}
func (r *consoleStatsReporter) ReportGauge(name string, tags map[string]string, value float64) {
r.logger.Infow(fmt.Sprintf("gauge %s", name), "name", name, "value", value, "tags", tags)
}
func (r *consoleStatsReporter) ReportTimer(name string, tags map[string]string, interval time.Duration) {
r.logger.Infow(fmt.Sprintf("timer %s", name), "name", name, "interval", interval, "tags", tags)
}
func (r *consoleStatsReporter) ReportHistogramValueSamples(
name string,
tags map[string]string,
_ tally.Buckets,
bucketLowerBound,
bucketUpperBound float64,
samples int64,
) {
r.logger.Infow(
fmt.Sprintf("histogram %s bucket", name),
"name",
name,
"tags",
tags,
"lower",
bucketLowerBound,
"upper",
bucketUpperBound,
"samples",
samples,
)
}
func (r *consoleStatsReporter) ReportHistogramDurationSamples(
name string,
tags map[string]string,
_ tally.Buckets,
bucketLowerBound,
bucketUpperBound time.Duration,
samples int64,
) {
r.logger.Infow(
fmt.Sprintf("histogram %s bucket", name),
"name",
name,
"tags",
tags,
"lower",
bucketLowerBound,
"upper",
bucketUpperBound,
"samples",
samples,
)
}
func (r *consoleStatsReporter) Capabilities() tally.Capabilities {
return r
}
func (r *consoleStatsReporter) Reporting() bool {
return true
}
func (r *consoleStatsReporter) Tagging() bool {
return true
}
func (r *consoleStatsReporter) Flush() {
_ = r.logger.Sync()
}