-
Notifications
You must be signed in to change notification settings - Fork 5k
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
stefans-elastic
merged 28 commits into
elastic:main
from
stefans-elastic:vsphere-metrics
May 26, 2025
Merged
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 ff0e032
Merge branch 'main' into vsphere-metrics
stefans-elastic 4249986
add missing license headers
stefans-elastic 247cd5a
mage fmt
stefans-elastic 04eb69d
Merge branch 'main' into vsphere-metrics
stefans-elastic fc31132
convert percentage values from fixed point integers
stefans-elastic 5cad1e3
add CHANGELOG.next.asciidoc entry
stefans-elastic ea0be4f
refactor performance data fetching for datastore
stefans-elastic 00135e3
document new fields
stefans-elastic af410f9
remove unused function
stefans-elastic 0357c15
remove debug log
stefans-elastic 35614f0
Merge branch 'main' into vsphere-metrics
stefans-elastic a728e24
add unit tests
stefans-elastic 5273df4
mage fmt
stefans-elastic c769e74
Merge branch 'main' into vsphere-metrics
stefans-elastic f6b3bf8
Merge branch 'main' of github.com:stefans-elastic/beats into vsphere-…
stefans-elastic 764c34a
fixed precision issue for percentage performance manager values
stefans-elastic ce7e055
correct percentage property names
stefans-elastic ab81503
converts kilobytes per sec to bytes per sec
stefans-elastic 26d9f49
update fields.go
stefans-elastic 17a459d
fix linter
stefans-elastic c366bf9
fix type assertion pabic
stefans-elastic cf2ae15
fix unit test failure
stefans-elastic fe58854
Merge branch 'main' into vsphere-metrics
ishleenk17 09ff7ab
address PR comments
stefans-elastic b86c4ab
Merge branch 'vsphere-metrics' of github.com:stefans-elastic/beats in…
stefans-elastic b53555f
changed percentage fields to scaled_float type
stefans-elastic 8e3a69b
make field names same between fields.go and fields.yml
stefans-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.