Merge pull request #46462 from vmware/vsphere-storage-metrics
Automatic merge from submit-queue (batch tested with PRs 41563, 45251, 46265, 46462, 46721) Add metric collections for vSphere cloud provider operations **What this PR does / why we need it**: This PR adds metric collections for vSphere Cloud Provider Operations. **Which issue this PR fixes** fixes # **Special notes for your reviewer**: Verified Prometheus pod is able to scrape vSphere metrics from Kubernetes Controller’s URL. `providers/vsphere/vsphere.go` file is intentionally kept not formatted with gofmt, to keep diff review-able. After review is complete, I will apply the formatting. **Release note**: ```release-note None ``` @BaluDontu @tusharnt @gnufied Verified with executing various operations on the Kubernetes Cluster deployed using this change. ``` $ curl -s 10.160.18.128:10252/metrics | grep "cloudprovider_vsphere" # HELP cloudprovider_vsphere_api_request_duration_seconds Latency of vsphere api call # TYPE cloudprovider_vsphere_api_request_duration_seconds histogram cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.005"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.01"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.025"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.05"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.1"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.25"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="0.5"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="1"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="2.5"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="5"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="10"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="AttachVolume",le="+Inf"} 3 cloudprovider_vsphere_api_request_duration_seconds_sum{request="AttachVolume"} 3.9742241939999996 cloudprovider_vsphere_api_request_duration_seconds_count{request="AttachVolume"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.005"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.01"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.025"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.05"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.1"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.25"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="0.5"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="1"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="2.5"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="5"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="10"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="CreateVolume",le="+Inf"} 1 cloudprovider_vsphere_api_request_duration_seconds_sum{request="CreateVolume"} 0.920856776 cloudprovider_vsphere_api_request_duration_seconds_count{request="CreateVolume"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.005"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.01"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.025"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.05"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.1"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.25"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="0.5"} 2 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="1"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="2.5"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="5"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="10"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DeleteVolume",le="+Inf"} 3 cloudprovider_vsphere_api_request_duration_seconds_sum{request="DeleteVolume"} 1.3301585450000002 cloudprovider_vsphere_api_request_duration_seconds_count{request="DeleteVolume"} 3 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.005"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.01"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.025"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.05"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.1"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.25"} 0 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="0.5"} 1 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="1"} 4 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="2.5"} 6 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="5"} 6 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="10"} 6 cloudprovider_vsphere_api_request_duration_seconds_bucket{request="DetachVolume",le="+Inf"} 6 cloudprovider_vsphere_api_request_duration_seconds_sum{request="DetachVolume"} 5.350829375 cloudprovider_vsphere_api_request_duration_seconds_count{request="DetachVolume"} 6 # HELP cloudprovider_vsphere_api_request_errors vsphere Api errors # TYPE cloudprovider_vsphere_api_request_errors counter cloudprovider_vsphere_api_request_errors{request="DeleteVolume"} 4 # HELP cloudprovider_vsphere_operation_duration_seconds Latency of vsphere operation call # TYPE cloudprovider_vsphere_operation_duration_seconds histogram cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.25"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="0.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="1"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="2.5"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="5"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="10"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="AttachVolumeOperation",le="+Inf"} 3 cloudprovider_vsphere_operation_duration_seconds_sum{operation="AttachVolumeOperation"} 4.732579923 cloudprovider_vsphere_operation_duration_seconds_count{operation="AttachVolumeOperation"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.25"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="0.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="2.5"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="5"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="10"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeOperation",le="+Inf"} 1 cloudprovider_vsphere_operation_duration_seconds_sum{operation="CreateVolumeOperation"} 1.2753096990000001 cloudprovider_vsphere_operation_duration_seconds_count{operation="CreateVolumeOperation"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.25"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="0.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="2.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="10"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithPolicyOperation",le="+Inf"} 1 cloudprovider_vsphere_operation_duration_seconds_sum{operation="CreateVolumeWithPolicyOperation"} 15.066558008 cloudprovider_vsphere_operation_duration_seconds_count{operation="CreateVolumeWithPolicyOperation"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.25"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="0.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="2.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="10"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="CreateVolumeWithRawVSANPolicyOperation",le="+Inf"} 2 cloudprovider_vsphere_operation_duration_seconds_sum{operation="CreateVolumeWithRawVSANPolicyOperation"} 21.805354686 cloudprovider_vsphere_operation_duration_seconds_count{operation="CreateVolumeWithRawVSANPolicyOperation"} 2 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.25"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="0.5"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="1"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="2.5"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="5"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="10"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DeleteVolumeOperation",le="+Inf"} 3 cloudprovider_vsphere_operation_duration_seconds_sum{operation="DeleteVolumeOperation"} 1.4869503179999999 cloudprovider_vsphere_operation_duration_seconds_count{operation="DeleteVolumeOperation"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.25"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="0.5"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="1"} 2 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="2.5"} 6 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="5"} 6 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="10"} 6 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DetachVolumeOperation",le="+Inf"} 6 cloudprovider_vsphere_operation_duration_seconds_sum{operation="DetachVolumeOperation"} 7.15601343 cloudprovider_vsphere_operation_duration_seconds_count{operation="DetachVolumeOperation"} 6 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.25"} 1 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="0.5"} 2 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="1"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="2.5"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="5"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="10"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DiskIsAttachedOperation",le="+Inf"} 3 cloudprovider_vsphere_operation_duration_seconds_sum{operation="DiskIsAttachedOperation"} 1.0603705730000001 cloudprovider_vsphere_operation_duration_seconds_count{operation="DiskIsAttachedOperation"} 3 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.005"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.01"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.025"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.05"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.1"} 0 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.25"} 4 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="0.5"} 12 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="1"} 12 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="2.5"} 12 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="5"} 12 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="10"} 12 cloudprovider_vsphere_operation_duration_seconds_bucket{operation="DisksAreAttachedOperation",le="+Inf"} 12 cloudprovider_vsphere_operation_duration_seconds_sum{operation="DisksAreAttachedOperation"} 3.282661207 cloudprovider_vsphere_operation_duration_seconds_count{operation="DisksAreAttachedOperation"} 12 # HELP cloudprovider_vsphere_operation_errors vsphere operation errors # TYPE cloudprovider_vsphere_operation_errors counter cloudprovider_vsphere_operation_errors{operation="DeleteVolumeOperation"} 4 ```
This commit is contained in:
@@ -12,6 +12,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"vsphere.go",
|
"vsphere.go",
|
||||||
|
"vsphere_metrics.go",
|
||||||
"vsphere_util.go",
|
"vsphere_util.go",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
@@ -21,6 +22,7 @@ go_library(
|
|||||||
"//pkg/cloudprovider:go_default_library",
|
"//pkg/cloudprovider:go_default_library",
|
||||||
"//pkg/controller:go_default_library",
|
"//pkg/controller:go_default_library",
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
|
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||||
"//vendor/github.com/vmware/govmomi:go_default_library",
|
"//vendor/github.com/vmware/govmomi:go_default_library",
|
||||||
"//vendor/github.com/vmware/govmomi/find:go_default_library",
|
"//vendor/github.com/vmware/govmomi/find:go_default_library",
|
||||||
"//vendor/github.com/vmware/govmomi/object:go_default_library",
|
"//vendor/github.com/vmware/govmomi/object:go_default_library",
|
||||||
|
File diff suppressed because it is too large
Load Diff
127
pkg/cloudprovider/providers/vsphere/vsphere_metrics.go
Normal file
127
pkg/cloudprovider/providers/vsphere/vsphere_metrics.go
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package vsphere
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
api_createvolume = "CreateVolume"
|
||||||
|
api_deletevolume = "DeleteVolume"
|
||||||
|
api_attachvolume = "AttachVolume"
|
||||||
|
api_detachvolume = "DetachVolume"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
operation_deletevolume = "DeleteVolumeOperation"
|
||||||
|
operation_attachvolume = "AttachVolumeOperation"
|
||||||
|
operation_detachvolume = "DetachVolumeOperation"
|
||||||
|
operation_diskIsAttached = "DiskIsAttachedOperation"
|
||||||
|
operation_disksAreAttached = "DisksAreAttachedOperation"
|
||||||
|
operation_createvolume = "CreateVolumeOperation"
|
||||||
|
operation_createvolume_with_policy = "CreateVolumeWithPolicyOperation"
|
||||||
|
operation_createvolume_with_raw_vsan_policy = "CreateVolumeWithRawVSANPolicyOperation"
|
||||||
|
)
|
||||||
|
|
||||||
|
// vsphereApiMetric is for recording latency of Single API Call.
|
||||||
|
var vsphereApiMetric = prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "cloudprovider_vsphere_api_request_duration_seconds",
|
||||||
|
Help: "Latency of vsphere api call",
|
||||||
|
},
|
||||||
|
[]string{"request"},
|
||||||
|
)
|
||||||
|
|
||||||
|
var vsphereApiErrorMetric = prometheus.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "cloudprovider_vsphere_api_request_errors",
|
||||||
|
Help: "vsphere Api errors",
|
||||||
|
},
|
||||||
|
[]string{"request"},
|
||||||
|
)
|
||||||
|
|
||||||
|
// vsphereOperationMetric is for recording latency of vSphere Operation which invokes multiple APIs to get the task done.
|
||||||
|
var vsphereOperationMetric = prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "cloudprovider_vsphere_operation_duration_seconds",
|
||||||
|
Help: "Latency of vsphere operation call",
|
||||||
|
},
|
||||||
|
[]string{"operation"},
|
||||||
|
)
|
||||||
|
|
||||||
|
var vsphereOperationErrorMetric = prometheus.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "cloudprovider_vsphere_operation_errors",
|
||||||
|
Help: "vsphere operation errors",
|
||||||
|
},
|
||||||
|
[]string{"operation"},
|
||||||
|
)
|
||||||
|
|
||||||
|
func registerMetrics() {
|
||||||
|
prometheus.MustRegister(vsphereApiMetric)
|
||||||
|
prometheus.MustRegister(vsphereApiErrorMetric)
|
||||||
|
prometheus.MustRegister(vsphereOperationMetric)
|
||||||
|
prometheus.MustRegister(vsphereOperationErrorMetric)
|
||||||
|
}
|
||||||
|
|
||||||
|
func recordvSphereMetric(actionName string, requestTime time.Time, err error) {
|
||||||
|
switch actionName {
|
||||||
|
case api_createvolume, api_deletevolume, api_attachvolume, api_detachvolume:
|
||||||
|
recordvSphereAPIMetric(actionName, requestTime, err)
|
||||||
|
default:
|
||||||
|
recordvSphereOperationMetric(actionName, requestTime, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func recordvSphereAPIMetric(actionName string, requestTime time.Time, err error) {
|
||||||
|
if err != nil {
|
||||||
|
vsphereApiErrorMetric.With(prometheus.Labels{"request": actionName}).Inc()
|
||||||
|
} else {
|
||||||
|
vsphereApiMetric.With(prometheus.Labels{"request": actionName}).Observe(calculateTimeTaken(requestTime))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func recordvSphereOperationMetric(actionName string, requestTime time.Time, err error) {
|
||||||
|
if err != nil {
|
||||||
|
vsphereOperationErrorMetric.With(prometheus.Labels{"operation": actionName}).Inc()
|
||||||
|
} else {
|
||||||
|
vsphereOperationMetric.With(prometheus.Labels{"operation": actionName}).Observe(calculateTimeTaken(requestTime))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func recordCreateVolumeMetric(volumeOptions *VolumeOptions, requestTime time.Time, err error) {
|
||||||
|
var actionName string
|
||||||
|
if volumeOptions.StoragePolicyName != "" {
|
||||||
|
actionName = operation_createvolume_with_policy
|
||||||
|
} else if volumeOptions.VSANStorageProfileData != "" {
|
||||||
|
actionName = operation_createvolume_with_raw_vsan_policy
|
||||||
|
} else {
|
||||||
|
actionName = operation_createvolume
|
||||||
|
}
|
||||||
|
recordvSphereMetric(actionName, requestTime, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateTimeTaken(requestBeginTime time.Time) (timeTaken float64) {
|
||||||
|
if !requestBeginTime.IsZero() {
|
||||||
|
timeTaken = time.Since(requestBeginTime).Seconds()
|
||||||
|
} else {
|
||||||
|
timeTaken = 0
|
||||||
|
}
|
||||||
|
return timeTaken
|
||||||
|
}
|
Reference in New Issue
Block a user