Skip to content

Commit 26ce6f2

Browse files
mergify[bot]stefans-elasticishleenk17
authored
[9.0](backport #44205) capture extra vsphere metrics (cpu %, disk average, disk rate, disk n… (#44496)
* capture extra vsphere metrics (cpu %, disk average, disk rate, disk n… (#44205) * capture extra vsphere metrics (cpu %, disk average, disk rate, disk number, memory usage %) * add missing license headers * mage fmt * convert percentage values from fixed point integers * add CHANGELOG.next.asciidoc entry * refactor performance data fetching for datastore * document new fields * remove unused function * remove debug log * add unit tests * mage fmt * fixed precision issue for percentage performance manager values * correct percentage property names * converts kilobytes per sec to bytes per sec * update fields.go * fix linter * fix type assertion pabic * fix unit test failure * address PR comments * changed percentage fields to scaled_float type * make field names same between fields.go and fields.yml --------- Co-authored-by: Ishleen Kaur <102962586+ishleenk17@users.noreply.github.com> (cherry picked from commit 14ac057) * clean up changelog * go mod tidy * update NOTICE.txt --------- Co-authored-by: stefans-elastic <stefan.stas@elastic.co> Co-authored-by: Ishleen Kaur <102962586+ishleenk17@users.noreply.github.com>
1 parent 336915d commit 26ce6f2

File tree

13 files changed

+585
-146
lines changed

13 files changed

+585
-146
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
260260
- Add new metricset network for the vSphere module. {pull}40559[40559]
261261
- Add new metricset resourcepool for the vSphere module. {pull}40456[40456]
262262
- Updated Meraki API endpoint for Channel Utilization data. Switched to `GetOrganizationWirelessDevicesChannelUtilizationByDevice`. {pull}43485[43485]
263+
- 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]
263264
- Added checks for the Resty response object in all Meraki module API calls to ensure proper handling of nil responses. {pull}44193[44193]
264265
- Add latency config option to Azure Monitor module. {pull}44366[44366]
265266

NOTICE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12317,11 +12317,11 @@ SOFTWARE
1231712317

1231812318
--------------------------------------------------------------------------------
1231912319
Dependency : github.com/elastic/elastic-agent-libs
12320-
Version: v0.19.1
12320+
Version: v0.19.5
1232112321
Licence type (autodetected): Apache-2.0
1232212322
--------------------------------------------------------------------------------
1232312323

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

1232612326
Apache License
1232712327
Version 2.0, January 2004

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ require (
176176
github.com/elastic/bayeux v1.0.5
177177
github.com/elastic/ebpfevents v0.6.0
178178
github.com/elastic/elastic-agent-autodiscover v0.9.0
179-
github.com/elastic/elastic-agent-libs v0.19.1
179+
github.com/elastic/elastic-agent-libs v0.19.5
180180
github.com/elastic/elastic-agent-system-metrics v0.11.10
181181
github.com/elastic/go-elasticsearch/v8 v8.17.1
182182
github.com/elastic/go-quark v0.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0
342342
github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4=
343343
github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE=
344344
github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI=
345-
github.com/elastic/elastic-agent-libs v0.19.1 h1:6jiH0SPB5RzoF3W8Ipk+mI/Xl6zXqVPZkKADuzeChw0=
346-
github.com/elastic/elastic-agent-libs v0.19.1/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s=
345+
github.com/elastic/elastic-agent-libs v0.19.5 h1:br0kvmwowHu4KQpPy5C4DjkFdiGafbp8BV4CeXR4wUs=
346+
github.com/elastic/elastic-agent-libs v0.19.5/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s=
347347
github.com/elastic/elastic-agent-system-metrics v0.11.10 h1:51u6roLaI0WhX1wbU4hPaervODegOxNFLcLouDAAi8A=
348348
github.com/elastic/elastic-agent-system-metrics v0.11.10/go.mod h1:BlS6Fm/l/umAa9xKy7GxsSYtCfu/iqg551PULKSeCQM=
349349
github.com/elastic/elastic-transport-go/v8 v8.6.1 h1:h2jQRqH6eLGiBSN4eZbQnJLtL4bC5b4lfVFRjw2R4e4=

metricbeat/module/vsphere/client/mock_performance.go

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package client
19+
20+
import (
21+
"context"
22+
"fmt"
23+
"strings"
24+
25+
"github.com/vmware/govmomi/performance"
26+
"github.com/vmware/govmomi/vim25/types"
27+
28+
"github.com/elastic/elastic-agent-libs/logp"
29+
)
30+
31+
type PerfManager interface {
32+
AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (performance.MetricList, error)
33+
Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error)
34+
ToMetricSeries(ctx context.Context, series []types.BasePerfEntityMetricBase) ([]performance.EntityMetric, error)
35+
}
36+
37+
type PerformanceDataFetcher struct {
38+
perfManager PerfManager
39+
logger *logp.Logger
40+
}
41+
42+
func NewPerformanceDataFetcher(logger *logp.Logger, perfManager PerfManager) *PerformanceDataFetcher {
43+
return &PerformanceDataFetcher{
44+
logger: logger,
45+
perfManager: perfManager,
46+
}
47+
}
48+
49+
func (p *PerformanceDataFetcher) GetPerfMetrics(ctx context.Context,
50+
period int32,
51+
objectType string,
52+
objectName string,
53+
objectReference types.ManagedObjectReference,
54+
metrics map[string]*types.PerfCounterInfo,
55+
metricSet map[string]struct{}) (metricMap map[string]interface{}, err error) {
56+
57+
metricMap = make(map[string]interface{})
58+
59+
availableMetric, err := p.perfManager.AvailableMetric(ctx, objectReference, period)
60+
if err != nil {
61+
return nil, fmt.Errorf("failed to get available metrics: %w", err)
62+
}
63+
64+
availableMetricByKey := availableMetric.ByKey()
65+
66+
// Filter for required metrics
67+
var metricIDs []types.PerfMetricId
68+
for key, metric := range metricSet {
69+
if counter, ok := metrics[key]; ok {
70+
if _, exists := availableMetricByKey[counter.Key]; exists {
71+
metricIDs = append(metricIDs, types.PerfMetricId{
72+
CounterId: counter.Key,
73+
Instance: "*",
74+
})
75+
}
76+
} else {
77+
p.logger.Warnf("Metric %s not found", metric)
78+
}
79+
}
80+
81+
spec := types.PerfQuerySpec{
82+
Entity: objectReference,
83+
MetricId: metricIDs,
84+
MaxSample: 1,
85+
IntervalId: period,
86+
}
87+
88+
// Query performance data
89+
samples, err := p.perfManager.Query(ctx, []types.PerfQuerySpec{spec})
90+
if err != nil {
91+
if strings.Contains(err.Error(), "ServerFaultCode: A specified parameter was not correct: querySpec.interval") {
92+
return metricMap, fmt.Errorf("failed to query performance data: use one of the system's supported interval. consider adjusting period: %w", err)
93+
}
94+
95+
return metricMap, fmt.Errorf("failed to query performance data: %w", err)
96+
}
97+
98+
if len(samples) == 0 {
99+
p.logger.Debug("No samples returned from performance manager")
100+
return metricMap, nil
101+
}
102+
103+
results, err := p.perfManager.ToMetricSeries(ctx, samples)
104+
if err != nil {
105+
return metricMap, fmt.Errorf("failed to convert performance data to metric series: %w", err)
106+
}
107+
108+
if len(results) == 0 {
109+
p.logger.Debug("No results returned from metric series conversion")
110+
return metricMap, nil
111+
}
112+
113+
for _, result := range results[0].Value {
114+
if len(result.Value) > 0 {
115+
value := result.Value[0]
116+
if result.Unit == string(types.PerformanceManagerUnitPercent) {
117+
metricMap[result.Name] = float64(value) / 100.0
118+
} else {
119+
metricMap[result.Name] = value
120+
}
121+
continue
122+
}
123+
p.logger.Debugf("For %s %s, Metric %s: No result found", objectType, objectName, result.Name)
124+
}
125+
126+
return metricMap, nil
127+
}

0 commit comments

Comments
 (0)