Skip to content
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

[vSphere][virtualmachine] Add metrics to virtualmachine metricset #40485

Merged
merged 21 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -55,6 +55,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Allow metricsets to report their status via control v2 protocol. {pull}40025[40025]
- Remove fallback to the node limit for the `kubernetes.pod.cpu.usage.limit.pct` and `kubernetes.pod.memory.usage.limit.pct` metrics calculation
- Add support for Kibana status metricset in v8 format {pull}40275[40275]
- Add metrics for the vSphere Virtualmachine metricset. {pull}40485[40485]

*Osquerybeat*

Expand Down
74 changes: 37 additions & 37 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24491,6 +24491,43 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/exp
Version: v0.0.0-20240205201215-2c58cdc269a3
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/golang.org/x/[email protected]/LICENSE:

Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/mod
Version: v0.19.0
Expand Down Expand Up @@ -54754,43 +54791,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/exp
Version: v0.0.0-20240205201215-2c58cdc269a3
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/golang.org/x/[email protected]/LICENSE:

Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/term
Version: v0.22.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ require (
go.elastic.co/apm/module/apmhttp/v2 v2.6.0
go.elastic.co/apm/v2 v2.6.0
go.mongodb.org/mongo-driver v1.5.1
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)
Expand Down Expand Up @@ -371,7 +372,6 @@ require (
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect
Expand Down
30 changes: 30 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67163,6 +67163,36 @@ type: object
Network names


type: keyword

--

*`vsphere.virtualmachine.status`*::
+
--
Overall health and status of a virtual machine


type: keyword

--

*`vsphere.virtualmachine.uptime`*::
+
--
The uptime of the VM in seconds


type: long

--

*`vsphere.virtualmachine.datastore.names`*::
+
--
Datastore names associated with the virtual machine


type: keyword

--
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/vsphere/fields.go

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

67 changes: 39 additions & 28 deletions metricbeat/module/vsphere/virtualmachine/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"@timestamp": "2024-08-12T04:51:25.851Z",
"event": {
"dataset": "vsphere.virtualmachine",
"duration": 115000,
Expand All @@ -15,35 +15,46 @@
},
"vsphere": {
"virtualmachine": {
"cpu": {
"used": {
"mhz": 0
}
"os": "otherGuest",
"memory": {
"used": {
"guest": {
"bytes": 0
},
"host": {
"bytes": 0
}
},
"host.hostname": "localhost.localdomain",
"host.id": "ha-host",
"memory": {
"free": {
"guest": {
"bytes": 33554432
}
},
"total": {
"guest": {
"bytes": 33554432
}
},
"used": {
"guest": {
"bytes": 0
},
"host": {
"bytes": 0
}
}
"total": {
"guest": {
"bytes": 33554432
}
},
"name": "ha-host_VM0",
"os": "otherGuest"
"free": {
"guest": {
"bytes": 33554432
}
}
},
"name": "DC0_C0_RP0_VM1",
"uptime": 0,
"status": "green",
"host.hostname": "DC0_C0_H2",
"cpu": {
"used": {
"mhz": 0
},
"total": {
"mhz": 0
},
"free": {
"mhz": 0
}
},
"datastore_names": [
"LocalDS_0"
],
"host.id": "host-58"
}
}
}
14 changes: 14 additions & 0 deletions metricbeat/module/vsphere/virtualmachine/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@
type: keyword
description: >
Network names
- name: status
type: keyword
description: >
Overall health and status of a virtual machine
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
- name: uptime
type: long
description: >
The uptime of the VM in seconds
- name: datastore.names
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
type: keyword
description: >
Datastore names associated with the virtual machine


77 changes: 77 additions & 0 deletions metricbeat/module/vsphere/virtualmachine/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 virtualmachine

import (
"golang.org/x/exp/constraints"

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

func (m *MetricSet) eventMapping(data VMData) mapstr.M {

usedMemory := int64(data.VM.Summary.QuickStats.GuestMemoryUsage) * 1024 * 1024
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
usedCPU := data.VM.Summary.QuickStats.OverallCpuUsage
totalCPU := data.VM.Summary.Config.CpuReservation
totalMemory := int64(data.VM.Summary.Config.MemorySizeMB) * 1024 * 1024

freeCPU := max(0, totalCPU-usedCPU)
freeMemory := max(0, totalMemory-usedMemory)

event := mapstr.M{
"name": data.VM.Summary.Config.Name,
"os": data.VM.Summary.Config.GuestFullName,
"uptime": data.VM.Summary.QuickStats.UptimeSeconds,
"status": data.VM.Summary.OverallStatus,
"host.id": data.HostID,
"host.hostname": data.HostName,
"cpu": mapstr.M{
"used": mapstr.M{"mhz": usedCPU},
"total": mapstr.M{"mhz": totalCPU},
"free": mapstr.M{"mhz": freeCPU},
},
"memory": mapstr.M{
"used": mapstr.M{
"guest": mapstr.M{"bytes": usedMemory},
"host": mapstr.M{"bytes": int64(data.VM.Summary.QuickStats.HostMemoryUsage) * 1024 * 1024},
},
"total": mapstr.M{
"guest": mapstr.M{"bytes": totalMemory},
},
"free": mapstr.M{
"guest": mapstr.M{"bytes": freeMemory},
},
},
}
if len(data.CustomFields) > 0 {
event["custom_fields"] = data.CustomFields
}
if len(data.NetworkNames) > 0 {
event["network_names"] = data.NetworkNames
}
if len(data.DatastoreNames) > 0 {
event["datastore.names"] = data.DatastoreNames
}
return event
}
func max[T constraints.Ordered](a T, b T) T {
if a > b {
return a
}
return b
}
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading