-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.go
37 lines (31 loc) · 1.01 KB
/
stats.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package stats
import (
"net/http"
"time"
"github.com/VictoriaMetrics/metrics"
"golang.org/x/exp/slog"
)
// ForNerds captures metrics from various bifrost processes
var ForNerds = metrics.NewSet()
// MaybePushMetrics pushes metrics to url if url is not empty.
// If interval is zero, a one minute interval is used
// Panics if there is an error pushing metrics.
func MaybePushMetrics(url string, interval time.Duration) {
if url == "" {
return
}
if interval == 0 {
interval = time.Minute
}
slog.Info("pushing metrics", "url", url, "interval", interval)
if err := ForNerds.InitPush(url, interval, ""); err != nil {
panic(err)
}
}
// MetricsHandler is a HTTP handler that returns metrics from the ForNerds MetricsSet
func MetricsHandler(w http.ResponseWriter, _ *http.Request) {
ForNerds.WritePrometheus(w)
}