-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
metrics.go
88 lines (78 loc) · 2.6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package cmd
import (
"fmt"
"github.com/go-openapi/runtime/middleware"
restapi "github.com/cilium/cilium/api/v1/server/restapi/metrics"
"github.com/cilium/cilium/pkg/api"
"github.com/cilium/cilium/pkg/metrics"
"github.com/cilium/cilium/pkg/spanstat"
"github.com/cilium/cilium/pkg/time"
)
func getMetricsHandler(_ *Daemon, params restapi.GetMetricsParams) middleware.Responder {
metrics, err := metrics.DumpMetrics()
if err != nil {
return api.Error(
restapi.GetMetricsInternalServerErrorCode,
fmt.Errorf("Cannot gather metrics from daemon"))
}
return restapi.NewGetMetricsOK().WithPayload(metrics)
}
type bootstrapStatistics struct {
overall spanstat.SpanStat
earlyInit spanstat.SpanStat
k8sInit spanstat.SpanStat
restore spanstat.SpanStat
healthCheck spanstat.SpanStat
ingressIPAM spanstat.SpanStat
initAPI spanstat.SpanStat
initDaemon spanstat.SpanStat
cleanup spanstat.SpanStat
bpfBase spanstat.SpanStat
clusterMeshInit spanstat.SpanStat
ipam spanstat.SpanStat
daemonInit spanstat.SpanStat
mapsInit spanstat.SpanStat
workloadsInit spanstat.SpanStat
fqdn spanstat.SpanStat
enableConntrack spanstat.SpanStat
kvstore spanstat.SpanStat
deleteQueue spanstat.SpanStat
}
func (b *bootstrapStatistics) updateMetrics() {
if !metrics.BootstrapTimes.IsEnabled() {
return
}
for scope, stat := range b.getMap() {
if stat.SuccessTotal() != time.Duration(0) {
metrics.BootstrapTimes.WithLabelValues(scope, metrics.LabelValueOutcomeSuccess).Observe(stat.SuccessTotal().Seconds())
}
if stat.FailureTotal() != time.Duration(0) {
metrics.BootstrapTimes.WithLabelValues(scope, metrics.LabelValueOutcomeFail).Observe(stat.FailureTotal().Seconds())
}
}
}
func (b *bootstrapStatistics) getMap() map[string]*spanstat.SpanStat {
return map[string]*spanstat.SpanStat{
"overall": &b.overall,
"earlyInit": &b.earlyInit,
"k8sInit": &b.k8sInit,
"restore": &b.restore,
"healthCheck": &b.healthCheck,
"ingressIPAM": &b.ingressIPAM,
"initAPI": &b.initAPI,
"initDaemon": &b.initDaemon,
"cleanup": &b.cleanup,
"bpfBase": &b.bpfBase,
"clusterMeshInit": &b.clusterMeshInit,
"ipam": &b.ipam,
"daemonInit": &b.daemonInit,
"mapsInit": &b.mapsInit,
"workloadsInit": &b.workloadsInit,
"fqdn": &b.fqdn,
"enableConntrack": &b.enableConntrack,
"kvstore": &b.kvstore,
"deleteQueue": &b.deleteQueue,
}
}