Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kush-elastic committed Sep 30, 2024
2 parents 3dd9ecf + f3f562b commit 9ac1d95
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 155 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Add SSL support for aerospike module {pull}38126[38126]
- Add new metricset network for the vSphere module. {pull}40559[40559]
- Add new metricset resourcepool for the vSphere module. {pull}40456[40456]
- Log the total time taken for GCP `ListTimeSeries` and `AggregatedList` requests {pull}40661[40661]
- Add metrics for the vSphere Virtualmachine metricset. {pull}40485[40485]
- Add support for snapshot in vSphere virtualmachine metricset {pull}40683[40683]
- Update fields to use mapstr in vSphere virtualmachine metricset {pull}40707[40707]
Expand Down
4 changes: 0 additions & 4 deletions metricbeat/module/vsphere/fields.go

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

220 changes: 82 additions & 138 deletions metricbeat/module/vsphere/virtualmachine/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,149 +1,93 @@
{
"@timestamp": "2024-08-12T04:51:25.851Z",
"event": {
"dataset": "vsphere.virtualmachine",
"duration": 115000,
"module": "vsphere"
},
"metricset": {
"name": "virtualmachine",
"period": 10000
},
"service": {
"address": "127.0.0.1:39149",
"type": "vsphere"
},
"vsphere": {
<<<<<<< HEAD
"virtualmachine": {
"network.names": [
"PROD_VCF"
],
"os": "Microsoft Windows 10 (64-bit)",
"datastore": {
"count": 1
},
"memory": {
"used": {
"guest": {
"bytes": 0
},
"host": {
"bytes": 0
}
},
"total": {
"guest": {
"bytes": 4294967296
}
},
"free": {
"guest": {
"bytes": 4294967296
}
}
},
"network": {
"count": 1
},
"host.hostname": "phx-w1c1",
"name": "phx-14",
"cpu": {
"free": {
"mhz": 0
},
"used": {
"mhz": 0
},
"total": {
"mhz": 0
}
},
"uptime": 0,
"status": "green",
"network_names": [
"PROD_VCF"
],
"datastore.names": [
"VxRailtec-Virtual-SAN-Datastore-247df-bc1d-5aad2"
],
"host.id": "host-20"
=======
"virtualmachine": {
"name": "xt0nmfpv9",
"uptime": 5348978,
"status": "green",
"host": {
"id": "host-32",
"hostname": "phx-w1c1-esxi04.com"
"@timestamp": "2024-08-12T04:51:25.851Z",
"event": {
"dataset": "vsphere.virtualmachine",
"duration": 115000,
"module": "vsphere"
},
"metricset": {
"name": "virtualmachine",
"period": 10000
},
"service": {
"address": "127.0.0.1:39149",
"type": "vsphere"
},
"vsphere": {
"virtualmachine": {
"name": "xt0nmfpv9",
"uptime": 5348978,
"status": "green",
"host": {
"id": "host-32",
"hostname": "phx-w1c1-esxi04.com"
},
"cpu": {
"free": {
"mhz": 0
},
"cpu": {
"free": {
"mhz": 0
},
"used": {
"mhz": 161
"used": {
"mhz": 161
},
"total": {
"mhz": 0
}
},
"network": {
"names": [
"PROD_VCF_VMS"
],
"count": 1
},
"memory": {
"used": {
"guest": {
"bytes": 686817280
},
"total": {
"mhz": 0
>>>>>>> e7637c08b2 (Update fields to use mapstr in vSphere virtualmachine metricset (#40707))
"host": {
"bytes": 29027729408
}
},
"network": {
"names": [
"PROD_VCF_VMS"
],
"count": 1
"total": {
"guest": {
"bytes": 68719476736
}
},
"memory": {
"used": {
"guest": {
"bytes": 686817280
},
"host": {
"bytes": 29027729408
}
},
"total": {
"guest": {
"bytes": 68719476736
}
"free": {
"guest": {
"bytes": 68032659456
}
}
},
"network_names": [
"PROD_VCF_VMS"
],
"datastore": {
"count": 1,
"names": [
"VxRailtoup-Virtual-Datastore-bc1d-5aa310fb"
]
},
"os": "CentOS 4/5/6/7 (64-bit)",
"snapshot": {
"info": [
{
"id": 123,
"name": "Snapshot_1",
"description": "Test snapshot 1",
"createtime": "2024-09-01T12:34:56Z",
"state": "PoweredOff"
},
"free": {
"guest": {
"bytes": 68032659456
}
{
"id": 745,
"name": "Snapshot_2",
"description": "Test snapshot 2",
"createtime": "2024-09-03T2:34:56Z",
"state": "PoweredOn"
}
},
"network_names": [
"PROD_VCF_VMS"
],
"datastore": {
"count": 1,
"names": [
"VxRailtoup-Virtual-Datastore-bc1d-5aa310fb"
]
},
"os": "CentOS 4/5/6/7 (64-bit)",
"snapshot": {
"info": [
{
"id": 123,
"name": "Snapshot_1",
"description": "Test snapshot 1",
"createtime": "2024-09-01T12:34:56Z",
"state": "PoweredOff"
},
{
"id": 745,
"name": "Snapshot_2",
"description": "Test snapshot 2",
"createtime": "2024-09-03T2:34:56Z",
"state": "PoweredOn"
}
],
"count": 2
}
}
"count": 2
}
}
}
}
3 changes: 0 additions & 3 deletions metricbeat/module/vsphere/virtualmachine/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,10 @@ func (m *MetricSet) mapEvent(data VMData) mapstr.M {
event.Put("datastore.count", len(data.DatastoreNames))
event.Put("datastore.names", data.DatastoreNames)
}
<<<<<<< HEAD
=======
if len(data.Snapshots) > 0 {
event.Put("snapshot.count", len(data.Snapshots))
event.Put("snapshot.info", data.Snapshots)
}

>>>>>>> e7637c08b2 (Update fields to use mapstr in vSphere virtualmachine metricset (#40707))
return event
}
23 changes: 17 additions & 6 deletions metricbeat/module/vsphere/virtualmachine/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package virtualmachine

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/vmware/govmomi/vim25/mo"
Expand Down Expand Up @@ -58,6 +59,22 @@ func TestEventMapping(t *testing.T) {
"customField1": "value1",
"customField2": "value2",
},
Snapshots: []VMSnapshotData{
{
ID: 123,
Name: "Snapshot_1",
Description: "Test snapshot 1",
CreateTime: time.Time{},
State: types.VirtualMachinePowerStatePoweredOff,
},
{
ID: 745,
Name: "Snapshot_2",
Description: "Test snapshot 2",
CreateTime: time.Time{},
State: types.VirtualMachinePowerStatePoweredOn,
},
},
}

event := m.mapEvent(data)
Expand Down Expand Up @@ -109,11 +126,6 @@ func TestEventMapping(t *testing.T) {
"customField1": "value1",
"customField2": "value2",
},
<<<<<<< HEAD
"network.names": []string{"network-1", "network-2"},
"network_names": []string{"network-1", "network-2"},
"datastore.names": []string{"ds1", "ds2"},
=======
"network_names": []string{"network-1", "network-2"},
"snapshot": mapstr.M{
"info": []VMSnapshotData{
Expand All @@ -134,7 +146,6 @@ func TestEventMapping(t *testing.T) {
},
"count": 2,
},
>>>>>>> e7637c08b2 (Update fields to use mapstr in vSphere virtualmachine metricset (#40707))
}

// Assert that the output event matches the expected event
Expand Down
29 changes: 26 additions & 3 deletions metricbeat/module/vsphere/virtualmachine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"strings"
"time"

"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/beats/v7/metricbeat/module/vsphere"
Expand Down Expand Up @@ -56,8 +57,6 @@ type VMData struct {
NetworkNames []string
DatastoreNames []string
CustomFields mapstr.M
<<<<<<< HEAD
=======
Snapshots []VMSnapshotData
}

Expand All @@ -67,7 +66,6 @@ type VMSnapshotData struct {
Description string `json:"description"`
CreateTime time.Time `json:"createtime"`
State types.VirtualMachinePowerState `json:"state"`
>>>>>>> e7637c08b2 (Update fields to use mapstr in vSphere virtualmachine metricset (#40707))
}

// New creates a new instance of the MetricSet.
Expand Down Expand Up @@ -148,6 +146,7 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error {
var hostID, hostName string
var networkNames, datastoreNames []string
var customFields mapstr.M
var snapshots []VMSnapshotData

if host := vm.Summary.Runtime.Host; host != nil {
hostID = host.Value
Expand Down Expand Up @@ -191,13 +190,18 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error {
}
}

if vm.Snapshot != nil {
snapshots = fetchSnapshots(vm.Snapshot.RootSnapshotList)
}

data := VMData{
VM: vm,
HostID: hostID,
HostName: hostName,
NetworkNames: networkNames,
DatastoreNames: datastoreNames,
CustomFields: customFields,
Snapshots: snapshots,
}

reporter.Event(mb.Event{
Expand Down Expand Up @@ -282,3 +286,22 @@ func getHostSystem(ctx context.Context, c *vim25.Client, ref types.ManagedObject
}
return &hs, nil
}

func fetchSnapshots(snapshotTree []types.VirtualMachineSnapshotTree) []VMSnapshotData {
snapshots := make([]VMSnapshotData, 0, len(snapshotTree))
for _, snapshot := range snapshotTree {
snapshots = append(snapshots, VMSnapshotData{
ID: snapshot.Id,
Name: snapshot.Name,
Description: snapshot.Description,
CreateTime: snapshot.CreateTime,
State: snapshot.State,
})

// Recursively add child snapshots
if len(snapshot.ChildSnapshotList) > 0 {
snapshots = append(snapshots, fetchSnapshots(snapshot.ChildSnapshotList)...)
}
}
return snapshots
}

0 comments on commit 9ac1d95

Please sign in to comment.