/
info.go
47 lines (41 loc) · 1.35 KB
/
info.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
package check
import (
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/klog/v2"
)
const (
versionLabel = "version"
buildLabel = "build"
apiVersionLabel = "api_version"
vCenterUUID = "uuid"
)
var (
vCenterInfoMetric = metrics.NewGaugeVec(
&metrics.GaugeOpts{
Name: "vsphere_vcenter_info",
Help: "Information about vSphere vCenter.",
StabilityLevel: metrics.ALPHA,
},
[]string{versionLabel, apiVersionLabel, vCenterUUID, buildLabel},
)
)
func init() {
legacyregistry.MustRegister(vCenterInfoMetric)
}
// CollectClusterInfo grabs information about vSphere cluster and updates corresponding metrics.
// It's not a vSphere check per se, just using the interface.
func CollectClusterInfo(ctx *CheckContext) error {
vCenterInfoMetric.Reset()
collectVCenterInfo(ctx)
return nil
}
func collectVCenterInfo(ctx *CheckContext) {
version := ctx.VMClient.ServiceContent.About.Version
apiVersion := ctx.VMClient.ServiceContent.About.ApiVersion
build := ctx.VMClient.ServiceContent.About.Build
uuid := ctx.VMClient.ServiceContent.About.InstanceUuid
klog.V(2).Infof("vCenter version is %s, apiVersion is %s and build is %s", version, apiVersion, build)
ctx.ClusterInfo.SetVCenterVersion(version, apiVersion)
vCenterInfoMetric.WithLabelValues(version, apiVersion, uuid, build).Set(1.0)
}