Skip to content

Commit

Permalink
Changed location of api call + added helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BominRahmani committed Jun 19, 2024
1 parent a397374 commit 6de60f2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
3 changes: 3 additions & 0 deletions receiver/vcenterreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ The full list of settings exposed for this receiver are documented [here](./conf
Details about the metrics produced by this receiver can be found in [metadata.yaml](./metadata.yaml) with further documentation in [documentation.md](./documentation.md)
Additionally some metrics are only available to certain vSphere API versions.
- [vcenter.vm.cpu.readiness](https://dp-downloads.broadcom.com/api-content/apis/API_VMA_001/8.0U2/html/vim.vm.Summary.QuickStats.html)
### Feature gates
20 changes: 13 additions & 7 deletions receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (

// vcenterClient is a client that collects data from a vCenter endpoint.
type vcenterClient struct {
moClient *govmomi.Client
vimDriver *vim25.Client
finder *find.Finder
pc *property.Collector
pm *performance.Manager
vm *view.Manager
cfg *Config
moClient *govmomi.Client
vimDriver *vim25.Client
finder *find.Finder
pc *property.Collector
pm *performance.Manager
vm *view.Manager
cfg *Config
apiVersion string
}

var newVcenterClient = defaultNewVcenterClient
Expand Down Expand Up @@ -74,6 +75,7 @@ func (vc *vcenterClient) EnsureConnection(ctx context.Context) error {
vc.finder = find.NewFinder(vc.vimDriver)
vc.pm = performance.NewManager(vc.vimDriver)
vc.vm = view.NewManager(vc.vimDriver)
vc.refreshVsphereAPIVersion()
return nil
}

Expand Down Expand Up @@ -103,6 +105,10 @@ func (vc *vcenterClient) Datacenters(ctx context.Context) ([]mo.Datacenter, erro
return datacenters, nil
}

func (vc *vcenterClient) refreshVsphereAPIVersion() {
vc.apiVersion = vc.getVsphereAPIVersion()
}

func (vc *vcenterClient) getVsphereAPIVersion() string {
return vc.vimDriver.ServiceContent.About.ApiVersion
}
Expand Down
22 changes: 13 additions & 9 deletions receiver/vcenterreceiver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,25 @@ func (v *vcenterMetricScraper) recordVMStats(
v.mb.RecordVcenterVMCPUUtilizationDataPoint(ts, 100*float64(cpuUsage)/float64(cpuLimit))

// OverallCpuReadiness is only available in vSphere API 7.0
// https://vdc-repo.vmware.com/vmwb-repository/dcr-public/d1902b0e-d479-46bf-8ac9-cee0e31e8ec0/07ce8dbd-db48-4261-9b8f-c6d3ad8ba472/vim.vm.Summary.QuickStats.html
vsphereAPIVersion, err := version.NewVersion(v.scrapeData.apiVersion)
if err != nil {
return
// https://dp-downloads.broadcom.com/api-content/apis/API_VMA_001/8.0U2/html/vim.vm.Summary.QuickStats.html
if v.vsphereAPIVersionMeetsMin("7.0.0") {
cpuReadiness := vm.Summary.QuickStats.OverallCpuReadiness
v.mb.RecordVcenterVMCPUReadinessDataPoint(ts, int64(cpuReadiness))
}
}

minVersionRequirement, err := version.NewVersion("7.0.0")
func (v *vcenterMetricScraper) vsphereAPIVersionMeetsMin(minVsphereAPIVersion string) bool {
apiVersion, err := version.NewVersion(v.client.apiVersion)
if err != nil {
return
return false
}

if vsphereAPIVersion.GreaterThan(minVersionRequirement) {
cpuReadiness := vm.Summary.QuickStats.OverallCpuReadiness
v.mb.RecordVcenterVMCPUReadinessDataPoint(ts, int64(cpuReadiness))
minAPIVersion, err := version.NewVersion(minVsphereAPIVersion)
if err != nil {
return false
}

return apiVersion.GreaterThan(minAPIVersion)
}

var hostPerfMetricList = []string{
Expand Down
3 changes: 0 additions & 3 deletions receiver/vcenterreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type vmGroupInfo struct {
}

type vcenterScrapeData struct {
apiVersion string
datacenters []*mo.Datacenter
datastores []*mo.Datastore
rPoolIPathsByRef map[string]*string
Expand Down Expand Up @@ -67,7 +66,6 @@ func newVmwareVcenterScraper(

func newVcenterScrapeData() *vcenterScrapeData {
return &vcenterScrapeData{
apiVersion: "",
datacenters: make([]*mo.Datacenter, 0),
datastores: make([]*mo.Datastore, 0),
rPoolIPathsByRef: make(map[string]*string),
Expand Down Expand Up @@ -110,7 +108,6 @@ func (v *vcenterMetricScraper) scrape(ctx context.Context) (pmetric.Metrics, err
// scrapeAndProcessAllMetrics collects & converts all relevant resources managed by vCenter to OTEL resources & metrics
func (v *vcenterMetricScraper) scrapeAndProcessAllMetrics(ctx context.Context, errs *scrapererror.ScrapeErrors) error {
v.scrapeData = newVcenterScrapeData()
v.scrapeData.apiVersion = v.client.getVsphereAPIVersion()
v.scrapeResourcePoolInventoryListObjects(ctx, errs)
v.scrapeVAppInventoryListObjects(ctx, errs)
v.scrapeDatacenters(ctx, errs)
Expand Down

0 comments on commit 6de60f2

Please sign in to comment.