mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #94526 from Danil-Grigorev/metrics-vcenter-version
Add vCenter info metric
This commit is contained in:
commit
0f6d1ed59c
@ -65,6 +65,7 @@ func (connection *VSphereConnection) Connect(ctx context.Context) error {
|
|||||||
klog.Errorf("Failed to create govmomi client. err: %+v", err)
|
klog.Errorf("Failed to create govmomi client. err: %+v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
setVCenterInfoMetric(connection)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m := session.NewManager(connection.Client)
|
m := session.NewManager(connection.Client)
|
||||||
@ -83,6 +84,7 @@ func (connection *VSphereConnection) Connect(ctx context.Context) error {
|
|||||||
klog.Errorf("Failed to create govmomi client. err: %+v", err)
|
klog.Errorf("Failed to create govmomi client. err: %+v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
setVCenterInfoMetric(connection)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,10 @@ limitations under the License.
|
|||||||
package vclib
|
package vclib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
"k8s.io/component-base/metrics"
|
"k8s.io/component-base/metrics"
|
||||||
"k8s.io/component-base/metrics/legacyregistry"
|
"k8s.io/component-base/metrics/legacyregistry"
|
||||||
)
|
)
|
||||||
@ -43,6 +45,15 @@ const (
|
|||||||
OperationCreateVolumeWithRawVSANPolicy = "CreateVolumeWithRawVSANPolicyOperation"
|
OperationCreateVolumeWithRawVSANPolicy = "CreateVolumeWithRawVSANPolicyOperation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var vCenterMetric *vcenterMetric
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
vCenterMetric = &vcenterMetric{
|
||||||
|
vCenterInfos: make(map[string]types.AboutInfo),
|
||||||
|
mux: sync.Mutex{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// vsphereAPIMetric is for recording latency of Single API Call.
|
// vsphereAPIMetric is for recording latency of Single API Call.
|
||||||
var vsphereAPIMetric = metrics.NewHistogramVec(
|
var vsphereAPIMetric = metrics.NewHistogramVec(
|
||||||
&metrics.HistogramOpts{
|
&metrics.HistogramOpts{
|
||||||
@ -81,12 +92,55 @@ var vsphereOperationErrorMetric = metrics.NewCounterVec(
|
|||||||
[]string{"operation"},
|
[]string{"operation"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var vsphereVersion = metrics.NewDesc(
|
||||||
|
"cloudprovider_vsphere_vcenter_versions",
|
||||||
|
"Versions for connected vSphere vCenters",
|
||||||
|
[]string{"hostname", "version", "build"}, nil,
|
||||||
|
metrics.ALPHA, "")
|
||||||
|
|
||||||
// RegisterMetrics registers all the API and Operation metrics
|
// RegisterMetrics registers all the API and Operation metrics
|
||||||
func RegisterMetrics() {
|
func RegisterMetrics() {
|
||||||
legacyregistry.MustRegister(vsphereAPIMetric)
|
legacyregistry.MustRegister(vsphereAPIMetric)
|
||||||
legacyregistry.MustRegister(vsphereAPIErrorMetric)
|
legacyregistry.MustRegister(vsphereAPIErrorMetric)
|
||||||
legacyregistry.MustRegister(vsphereOperationMetric)
|
legacyregistry.MustRegister(vsphereOperationMetric)
|
||||||
legacyregistry.MustRegister(vsphereOperationErrorMetric)
|
legacyregistry.MustRegister(vsphereOperationErrorMetric)
|
||||||
|
legacyregistry.CustomMustRegister(vCenterMetric)
|
||||||
|
}
|
||||||
|
|
||||||
|
type vcenterMetric struct {
|
||||||
|
metrics.BaseStableCollector
|
||||||
|
|
||||||
|
mux sync.Mutex
|
||||||
|
vCenterInfos map[string]types.AboutInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func (collector *vcenterMetric) DescribeWithStability(ch chan<- *metrics.Desc) {
|
||||||
|
ch <- vsphereVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (collector *vcenterMetric) CollectWithStability(ch chan<- metrics.Metric) {
|
||||||
|
collector.mux.Lock()
|
||||||
|
defer collector.mux.Unlock()
|
||||||
|
|
||||||
|
for vCenter, info := range collector.vCenterInfos {
|
||||||
|
ch <- metrics.NewLazyMetricWithTimestamp(time.Now(),
|
||||||
|
metrics.NewLazyConstMetric(vsphereVersion,
|
||||||
|
metrics.GaugeValue,
|
||||||
|
float64(1),
|
||||||
|
vCenter,
|
||||||
|
info.Version,
|
||||||
|
info.Build))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (collector *vcenterMetric) setAbout(server string, info types.AboutInfo) {
|
||||||
|
collector.mux.Lock()
|
||||||
|
defer collector.mux.Unlock()
|
||||||
|
collector.vCenterInfos[server] = info
|
||||||
|
}
|
||||||
|
|
||||||
|
func setVCenterInfoMetric(connection *VSphereConnection) {
|
||||||
|
vCenterMetric.setAbout(connection.Hostname, connection.Client.ServiceContent.About)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordvSphereMetric records the vSphere API and Operation metrics
|
// RecordvSphereMetric records the vSphere API and Operation metrics
|
||||||
|
Loading…
Reference in New Issue
Block a user