2021-04-10 10:35:38 +02:00
|
|
|
package sched
|
2021-04-10 04:59:43 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2021-04-10 11:07:02 +02:00
|
|
|
|
|
|
|
"github.com/uber-go/tally"
|
2021-04-10 04:59:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type metrics struct {
|
2021-04-10 14:06:34 +02:00
|
|
|
up tally.Gauge
|
|
|
|
runs tally.Counter
|
|
|
|
overlappingCount tally.Counter
|
|
|
|
runActualElapsed tally.Timer
|
|
|
|
runTotalElapsed tally.Timer
|
|
|
|
runErrors tally.Counter
|
|
|
|
runExceedExpected tally.Counter
|
2021-04-10 04:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func newMetrics(name string, metricsScope tally.Scope) *metrics {
|
|
|
|
subScope := metricsScope.SubScope("sched")
|
|
|
|
return &metrics{
|
2021-04-10 15:07:11 +02:00
|
|
|
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"),
|
2021-04-10 04:59:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|