44 lines
1.2 KiB
Go
Executable File
44 lines
1.2 KiB
Go
Executable File
// Package beacon spawns a goroutine that posts a version
|
|
// beacon as a statsD counter increment every hour.
|
|
package beacon
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitlab-app.eng.qops.net/golang/metrics"
|
|
)
|
|
|
|
const (
|
|
// MetricsPrefix is the standard qmp prefix when using the version beacon.
|
|
MetricsPrefix = "telegraf.qmp-client"
|
|
)
|
|
|
|
// Register starts a goroutine that emits a version beacon hourly detaling the given
|
|
// application name, library name, and library version using the given prefix.
|
|
func Register(appName, libName, libVersion, metricPrefix string) {
|
|
go func() {
|
|
// If this returns an error, then the reporter sends metrics nowhere.
|
|
// Does not interfere with program execution.
|
|
reporter, _ := metrics.NewReporter(metricPrefix)
|
|
hostname := os.Getenv("HOSTNAME")
|
|
if hostname == "" {
|
|
hostname = "unknown"
|
|
}
|
|
reporter.IncCounter(strings.Join([]string{"beacon", "go", libName}, "."),
|
|
metrics.Tag("ver", libVersion),
|
|
metrics.Tag("app", appName),
|
|
metrics.Tag("host", hostname),
|
|
)
|
|
ticker := time.NewTicker(time.Hour)
|
|
for range ticker.C {
|
|
reporter.IncCounter(strings.Join([]string{"beacon", "go", libName}, "."),
|
|
metrics.Tag("ver", libVersion),
|
|
metrics.Tag("app", appName),
|
|
metrics.Tag("host", hostname),
|
|
)
|
|
}
|
|
}()
|
|
}
|