-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (33 loc) · 996 Bytes
/
main.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
package main
import (
"log"
"net/http"
"github.com/megaease/metrics-go/metricshub"
)
func main() {
config := &metricshub.MetricsHubConfig{
ServiceName: "vm-operator",
HostName: "sprite-run-serverless-01",
}
// Initialize MetricsHub
mHub := metricshub.NewMetricsHub(config)
mHub.RegisterMetric(&metricshub.MetricRegistration{
Name: "example_gauge",
Help: "An example gauge metric",
Type: metricshub.MetricTypeGaugeVec,
LabelKeys: []string{"label_1"},
})
mHub.RegisterMetric(&metricshub.MetricRegistration{
Name: "example_counter",
Help: "An example counter metric",
Type: metricshub.MetricTypeCounterVec,
LabelKeys: []string{"label_2"},
})
// Update metrics dynamically
mHub.UpdateMetrics("example_gauge", 42.5, nil)
mHub.UpdateMetrics("example_counter", 1, nil)
// Serve metrics
http.Handle("/metrics", mHub.HTTPHandler())
log.Println("Serving metrics at :8080/metrics")
log.Fatal(http.ListenAndServe(":8080", nil))
}