Skip to content

[9.0](backport #44205) capture extra vsphere metrics (cpu %, disk average, disk rate, disk n… #44496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Add new metricset network for the vSphere module. {pull}40559[40559]
- Add new metricset resourcepool for the vSphere module. {pull}40456[40456]
- Updated Meraki API endpoint for Channel Utilization data. Switched to `GetOrganizationWirelessDevicesChannelUtilizationByDevice`. {pull}43485[43485]
- Add new metrics to vSphere Virtual Machine dataset (CPU usage percentage, disk average usage, disk read/write rate, number of disk reads/writes, memory usage percentage). {pull}44205[44205]
- Added checks for the Resty response object in all Meraki module API calls to ensure proper handling of nil responses. {pull}44193[44193]
- Add latency config option to Azure Monitor module. {pull}44366[44366]

Expand Down
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12317,11 +12317,11 @@ SOFTWARE

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-libs
Version: v0.19.1
Version: v0.19.5
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.19.1/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.19.5/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ require (
github.com/elastic/bayeux v1.0.5
github.com/elastic/ebpfevents v0.6.0
github.com/elastic/elastic-agent-autodiscover v0.9.0
github.com/elastic/elastic-agent-libs v0.19.1
github.com/elastic/elastic-agent-libs v0.19.5
github.com/elastic/elastic-agent-system-metrics v0.11.10
github.com/elastic/go-elasticsearch/v8 v8.17.1
github.com/elastic/go-quark v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0
github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4=
github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE=
github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI=
github.com/elastic/elastic-agent-libs v0.19.1 h1:6jiH0SPB5RzoF3W8Ipk+mI/Xl6zXqVPZkKADuzeChw0=
github.com/elastic/elastic-agent-libs v0.19.1/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s=
github.com/elastic/elastic-agent-libs v0.19.5 h1:br0kvmwowHu4KQpPy5C4DjkFdiGafbp8BV4CeXR4wUs=
github.com/elastic/elastic-agent-libs v0.19.5/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s=
github.com/elastic/elastic-agent-system-metrics v0.11.10 h1:51u6roLaI0WhX1wbU4hPaervODegOxNFLcLouDAAi8A=
github.com/elastic/elastic-agent-system-metrics v0.11.10/go.mod h1:BlS6Fm/l/umAa9xKy7GxsSYtCfu/iqg551PULKSeCQM=
github.com/elastic/elastic-transport-go/v8 v8.6.1 h1:h2jQRqH6eLGiBSN4eZbQnJLtL4bC5b4lfVFRjw2R4e4=
Expand Down
105 changes: 105 additions & 0 deletions metricbeat/module/vsphere/client/mock_performance.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions metricbeat/module/vsphere/client/performance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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 client

import (
"context"
"fmt"
"strings"

"github.com/vmware/govmomi/performance"
"github.com/vmware/govmomi/vim25/types"

"github.com/elastic/elastic-agent-libs/logp"
)

type PerfManager interface {
AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (performance.MetricList, error)
Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error)
ToMetricSeries(ctx context.Context, series []types.BasePerfEntityMetricBase) ([]performance.EntityMetric, error)
}

type PerformanceDataFetcher struct {
perfManager PerfManager
logger *logp.Logger
}

func NewPerformanceDataFetcher(logger *logp.Logger, perfManager PerfManager) *PerformanceDataFetcher {
return &PerformanceDataFetcher{
logger: logger,
perfManager: perfManager,
}
}

func (p *PerformanceDataFetcher) GetPerfMetrics(ctx context.Context,
period int32,
objectType string,
objectName string,
objectReference types.ManagedObjectReference,
metrics map[string]*types.PerfCounterInfo,
metricSet map[string]struct{}) (metricMap map[string]interface{}, err error) {

metricMap = make(map[string]interface{})

availableMetric, err := p.perfManager.AvailableMetric(ctx, objectReference, period)
if err != nil {
return nil, fmt.Errorf("failed to get available metrics: %w", err)
}

availableMetricByKey := availableMetric.ByKey()

// Filter for required metrics
var metricIDs []types.PerfMetricId
for key, metric := range metricSet {
if counter, ok := metrics[key]; ok {
if _, exists := availableMetricByKey[counter.Key]; exists {
metricIDs = append(metricIDs, types.PerfMetricId{
CounterId: counter.Key,
Instance: "*",
})
}
} else {
p.logger.Warnf("Metric %s not found", metric)
}
}

spec := types.PerfQuerySpec{
Entity: objectReference,
MetricId: metricIDs,
MaxSample: 1,
IntervalId: period,
}

// Query performance data
samples, err := p.perfManager.Query(ctx, []types.PerfQuerySpec{spec})
if err != nil {
if strings.Contains(err.Error(), "ServerFaultCode: A specified parameter was not correct: querySpec.interval") {
return metricMap, fmt.Errorf("failed to query performance data: use one of the system's supported interval. consider adjusting period: %w", err)
}

return metricMap, fmt.Errorf("failed to query performance data: %w", err)
}

if len(samples) == 0 {
p.logger.Debug("No samples returned from performance manager")
return metricMap, nil
}

results, err := p.perfManager.ToMetricSeries(ctx, samples)
if err != nil {
return metricMap, fmt.Errorf("failed to convert performance data to metric series: %w", err)
}

if len(results) == 0 {
p.logger.Debug("No results returned from metric series conversion")
return metricMap, nil
}

for _, result := range results[0].Value {
if len(result.Value) > 0 {
value := result.Value[0]
if result.Unit == string(types.PerformanceManagerUnitPercent) {
metricMap[result.Name] = float64(value) / 100.0
} else {
metricMap[result.Name] = value
}
continue
}
p.logger.Debugf("For %s %s, Metric %s: No result found", objectType, objectName, result.Name)
}

return metricMap, nil
}
Loading
Loading