Skip to content

capture extra vsphere metrics (cpu %, disk average, disk rate, disk n… #44205

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 28 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9534dfa
capture extra vsphere metrics (cpu %, disk average, disk rate, disk n…
stefans-elastic May 5, 2025
ff0e032
Merge branch 'main' into vsphere-metrics
stefans-elastic May 5, 2025
4249986
add missing license headers
stefans-elastic May 5, 2025
247cd5a
mage fmt
stefans-elastic May 5, 2025
04eb69d
Merge branch 'main' into vsphere-metrics
stefans-elastic May 6, 2025
fc31132
convert percentage values from fixed point integers
stefans-elastic May 6, 2025
5cad1e3
add CHANGELOG.next.asciidoc entry
stefans-elastic May 6, 2025
ea0be4f
refactor performance data fetching for datastore
stefans-elastic May 6, 2025
00135e3
document new fields
stefans-elastic May 6, 2025
af410f9
remove unused function
stefans-elastic May 6, 2025
0357c15
remove debug log
stefans-elastic May 6, 2025
35614f0
Merge branch 'main' into vsphere-metrics
stefans-elastic May 7, 2025
a728e24
add unit tests
stefans-elastic May 7, 2025
5273df4
mage fmt
stefans-elastic May 7, 2025
c769e74
Merge branch 'main' into vsphere-metrics
stefans-elastic May 15, 2025
f6b3bf8
Merge branch 'main' of github.com:stefans-elastic/beats into vsphere-…
stefans-elastic May 19, 2025
764c34a
fixed precision issue for percentage performance manager values
stefans-elastic May 22, 2025
ce7e055
correct percentage property names
stefans-elastic May 22, 2025
ab81503
converts kilobytes per sec to bytes per sec
stefans-elastic May 22, 2025
26d9f49
update fields.go
stefans-elastic May 22, 2025
17a459d
fix linter
stefans-elastic May 22, 2025
c366bf9
fix type assertion pabic
stefans-elastic May 22, 2025
cf2ae15
fix unit test failure
stefans-elastic May 22, 2025
fe58854
Merge branch 'main' into vsphere-metrics
ishleenk17 May 23, 2025
09ff7ab
address PR comments
stefans-elastic May 23, 2025
b86c4ab
Merge branch 'vsphere-metrics' of github.com:stefans-elastic/beats in…
stefans-elastic May 23, 2025
b53555f
changed percentage fields to scaled_float type
stefans-elastic May 23, 2025
8e3a69b
make field names same between fields.go and fields.yml
stefans-elastic May 23, 2025
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 @@ -495,6 +495,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403]
- Updated Meraki API endpoint for Channel Utilization data. Switched to `GetOrganizationWirelessDevicesChannelUtilizationByDevice`. {pull}43485[43485]
- Upgrade Prometheus Library to v0.300.1. {pull}43540[43540]
- Add GCP Dataproc metadata collector in GCP module. {pull}43518[43518]
- 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]

*Metricbeat*
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.

126 changes: 126 additions & 0 deletions metricbeat/module/vsphere/client/performance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// 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 := float64(result.Value[0])
if result.Unit == string(types.PerformanceManagerUnitPercent) {
value = value / 100.0
}
metricMap[result.Name] = value
continue
}
p.logger.Debugf("For %s %s, Metric %s: No result found", objectType, objectName, result.Name)
}

return metricMap, nil
}
Loading