This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
metrics.go
69 lines (62 loc) · 2.14 KB
/
metrics.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
package controllers
import (
v1beta1 "github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)
var (
// same as requestLatency in
// "sigs.k8s.io/controller-runtime/pkg/metrics"
// its not exported, yet we want to remove it
// so we copy it here
requestLatencyCollector = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Subsystem: metrics.RestClientSubsystem,
Name: metrics.LatencyKey,
Help: "Request latency in seconds. Broken down by verb and URL.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 10),
}, []string{"verb", "url"})
milvusStatusCollector = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Subsystem: "milvus",
Name: "status",
Help: "Recording the changing status of each milvus",
}, []string{"milvus_namespace", "milvus_name"})
milvusTotalCountCollector = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Subsystem: "milvus",
Name: "total_count",
Help: "Total count of milvus in different status",
}, []string{"status"})
)
// MilvusStatusCode for milvusStatusCollector
const (
MilvusStatusCodePending = float64(0)
MilvusStatusCodeHealthy = float64(1)
MilvusStatusCodeUnHealthy = float64(2)
MilvusStatusCodeDeleting = float64(3)
MilvusStautsCodeStopped = float64(4)
MilvusStautsCodeMaintaining = float64(5)
)
func MilvusStatusToCode(status v1beta1.MilvusHealthStatus, isMaintaining bool) float64 {
if isMaintaining {
return MilvusStautsCodeMaintaining
}
switch status {
case v1beta1.StatusHealthy:
return MilvusStatusCodeHealthy
case v1beta1.StatusUnhealthy:
return MilvusStatusCodeUnHealthy
case v1beta1.StatusDeleting:
return MilvusStatusCodeDeleting
case v1beta1.StatusStopped:
return MilvusStautsCodeStopped
default:
return MilvusStatusCodePending
}
}
// InitializeMetrics for controllers
func InitializeMetrics() {
// unregister the defaults which we don't need
metrics.Registry.Unregister(requestLatencyCollector)
// register our own
metrics.Registry.MustRegister(milvusStatusCollector)
metrics.Registry.MustRegister(milvusTotalCountCollector)
}