From ae13065875fe34da3246c9d8dc67a65b29b49e1b Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Wed, 2 Feb 2022 17:22:36 +0100 Subject: [PATCH 1/9] Collect Resource Pool metrics; Add rpname tag on VM metrics --- plugins/inputs/vsphere/METRICS.md | 52 +++++++++++++++++++++ plugins/inputs/vsphere/endpoint.go | 68 ++++++++++++++++++++++++++++ plugins/inputs/vsphere/finder.go | 6 ++- plugins/inputs/vsphere/vsphere.go | 73 ++++++++++++++++-------------- 4 files changed, 163 insertions(+), 36 deletions(-) diff --git a/plugins/inputs/vsphere/METRICS.md b/plugins/inputs/vsphere/METRICS.md index 6e21ca0c8af6f..411161c0ade91 100644 --- a/plugins/inputs/vsphere/METRICS.md +++ b/plugins/inputs/vsphere/METRICS.md @@ -193,6 +193,58 @@ vmop.numSVMotion.latest vmop.numXVMotion.latest ``` +## Resource Pool Metrics +``` +cpu.usagemhz.average +cpu.cpuentitlement.latest +cpu.usagemhz.minimum +cpu.usagemhz.maximum +cpu.capacity.entitlement.average +cpu.capacity.usage.average +cpu.capacity.demand.average +cpu.capacity.contention.average +cpu.corecount.provisioned.average +cpu.corecount.contention.average +disk.throughput.usage.average +disk.throughput.contention.average +mem.capacity.contention.average +mem.overhead.average +mem.consumed.average +mem.granted.average +mem.active.average +mem.shared.average +mem.zero.average +mem.swapped.average +mem.vmmemctl.average +mem.capacity.provisioned.average +mem.capacity.entitlement.average +mem.capacity.usage.average +mem.mementitlement.latest +mem.compressed.average +mem.compressionRate.average +mem.decompressionRate.average +mem.overhead.minimum +mem.consumed.minimum +mem.granted.minimum +mem.active.minimum +mem.shared.minimum +mem.zero.minimum +mem.swapped.minimum +mem.vmmemctl.maximum +mem.overhead.maximum +mem.consumed.maximum +mem.granted.maximum +mem.active.maximum +mem.shared.maximum +mem.zero.maximum +mem.swapped.maximum +mem.vmmemctl.minimum +net.throughput.usage.average +net.throughput.contention.summation +power.power.average +power.energy.summation +``` + ## Cluster Metrics ```metrics diff --git a/plugins/inputs/vsphere/endpoint.go b/plugins/inputs/vsphere/endpoint.go index b0aab7dfdd637..3078b43fcbd06 100644 --- a/plugins/inputs/vsphere/endpoint.go +++ b/plugins/inputs/vsphere/endpoint.go @@ -100,6 +100,7 @@ type objectRef struct { parentRef *types.ManagedObjectReference //Pointer because it must be nillable guest string dcname string + rpname string customValues map[string]string lookup map[string]string } @@ -165,6 +166,24 @@ func NewEndpoint(ctx context.Context, parent *VSphere, address *url.URL, log tel getObjects: getClusters, parent: "datacenter", }, + "resourcepool": { + name: "resourcepool", + vcName: "ResourcePool", + pKey: "rpname", + parentTag: "clustername", + enabled: anythingEnabled(parent.ResourcePoolMetricExclude), + realTime: false, + sampling: int32(time.Duration(parent.HistoricalInterval).Seconds()), + objects: make(objectMap), + filters: newFilterOrPanic(parent.ResourcePoolMetricInclude, parent.ResourcePoolMetricExclude), + paths: parent.ResourcePoolInclude, + excludePaths: parent.ResourcePoolExclude, + simple: isSimple(parent.ResourcePoolMetricInclude, parent.ResourcePoolMetricExclude), + include: parent.ResourcePoolMetricInclude, + collectInstances: parent.ResourcePoolInstances, + getObjects: getResourcePools, + parent: "cluster", + }, "host": { name: "host", vcName: "HostSystem", @@ -653,6 +672,35 @@ func getClusters(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilte return m, nil } +//noinspection GoUnusedParameter +func getResourcePools(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) { + var resources []mo.ResourcePool + err := filter.FindAll(ctx, &resources) + if err != nil { + return nil, err + } + m := make(objectMap) + for _, r := range resources { + m[r.ExtensibleManagedObject.Reference().Value] = &objectRef{ + name: r.Name, + ref: r.ExtensibleManagedObject.Reference(), + parentRef: r.Parent, + customValues: e.loadCustomAttributes(&r.ManagedEntity), + } + } + return m, nil +} + +func getResourcePoolName(ctx context.Context, e *Endpoint, rp types.ManagedObjectReference, rps objectMap) string { + //Loop through the Resource Pools objectmap to find the corresponding one + for _, r := range rps { + if r.ref == rp { + return r.name + } + } + return "Resources" +} + //noinspection GoUnusedParameter func getHosts(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) { var resources []mo.HostSystem @@ -681,6 +729,20 @@ func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (o return nil, err } m := make(objectMap) + client, err := e.clientFactory.GetClient(ctx) + if err != nil { + return nil, err + } + //Create a ResourcePool Filter and get the list of Resource Pools + rprf := ResourceFilter{ + finder: &Finder{client}, + resType: "ResourcePool", + paths: []string{"/*/host/**"}, + excludePaths: nil} + resourcePools, err := getResourcePools(ctx, e, &rprf) + if err != nil { + return nil, err + } for _, r := range resources { if r.Runtime.PowerState != "poweredOn" { continue @@ -688,6 +750,8 @@ func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (o guest := "unknown" uuid := "" lookup := make(map[string]string) + // Get the name of the VM resource pool + rpname := getResourcePoolName(ctx, e, *r.ResourcePool, resourcePools) // Extract host name if r.Guest != nil && r.Guest.HostName != "" { @@ -755,6 +819,7 @@ func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (o parentRef: r.Runtime.Host, guest: guest, altID: uuid, + rpname: rpname, customValues: e.loadCustomAttributes(&r.ManagedEntity), lookup: lookup, } @@ -1191,6 +1256,9 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou if resourceType == "vm" && objectRef.altID != "" { t["uuid"] = objectRef.altID } + if resourceType == "vm" && objectRef.rpname != "" { + t["rpname"] = objectRef.rpname + } // Map parent reference parent, found := e.getParent(objectRef, resource) diff --git a/plugins/inputs/vsphere/finder.go b/plugins/inputs/vsphere/finder.go index 0af9ef91268de..93150b683d55f 100644 --- a/plugins/inputs/vsphere/finder.go +++ b/plugins/inputs/vsphere/finder.go @@ -246,6 +246,7 @@ func matchName(f property.Filter, props []types.DynamicProperty) bool { func init() { childTypes = map[string][]string{ "HostSystem": {"VirtualMachine"}, + "ResourcePool": {"VirtualMachine"}, "ComputeResource": {"HostSystem", "ResourcePool", "VirtualApp"}, "ClusterComputeResource": {"HostSystem", "ResourcePool", "VirtualApp"}, "Datacenter": {"Folder"}, @@ -260,9 +261,10 @@ func init() { } addFields = map[string][]string{ - "HostSystem": {"parent", "summary.customValue", "customValue"}, + "HostSystem": {"parent", "summary.customValue", "customValue"}, + "ResourcePool": {"parent", "customValue"}, "VirtualMachine": {"runtime.host", "config.guestId", "config.uuid", "runtime.powerState", - "summary.customValue", "guest.net", "guest.hostName", "customValue"}, + "summary.customValue", "guest.net", "guest.hostName", "resourcePool", "customValue"}, "Datastore": {"parent", "info", "customValue"}, "ClusterComputeResource": {"parent", "customValue"}, "Datacenter": {"parent", "customValue"}, diff --git a/plugins/inputs/vsphere/vsphere.go b/plugins/inputs/vsphere/vsphere.go index f587ab6aaba95..a8505727dd402 100644 --- a/plugins/inputs/vsphere/vsphere.go +++ b/plugins/inputs/vsphere/vsphere.go @@ -15,40 +15,45 @@ import ( // VSphere is the top level type for the vSphere input plugin. It contains all the configuration // and a list of connected vSphere endpoints type VSphere struct { - Vcenters []string - Username string - Password string - DatacenterInstances bool - DatacenterMetricInclude []string - DatacenterMetricExclude []string - DatacenterInclude []string - DatacenterExclude []string - ClusterInstances bool - ClusterMetricInclude []string - ClusterMetricExclude []string - ClusterInclude []string - ClusterExclude []string - HostInstances bool - HostMetricInclude []string - HostMetricExclude []string - HostInclude []string - HostExclude []string - VMInstances bool `toml:"vm_instances"` - VMMetricInclude []string `toml:"vm_metric_include"` - VMMetricExclude []string `toml:"vm_metric_exclude"` - VMInclude []string `toml:"vm_include"` - VMExclude []string `toml:"vm_exclude"` - DatastoreInstances bool - DatastoreMetricInclude []string - DatastoreMetricExclude []string - DatastoreInclude []string - DatastoreExclude []string - Separator string - CustomAttributeInclude []string - CustomAttributeExclude []string - UseIntSamples bool - IPAddresses []string - MetricLookback int + Vcenters []string + Username string + Password string + DatacenterInstances bool + DatacenterMetricInclude []string + DatacenterMetricExclude []string + DatacenterInclude []string + DatacenterExclude []string + ClusterInstances bool + ClusterMetricInclude []string + ClusterMetricExclude []string + ClusterInclude []string + ClusterExclude []string + ResourcePoolInstances bool + ResourcePoolMetricInclude []string + ResourcePoolMetricExclude []string + ResourcePoolInclude []string + ResourcePoolExclude []string + HostInstances bool + HostMetricInclude []string + HostMetricExclude []string + HostInclude []string + HostExclude []string + VMInstances bool `toml:"vm_instances"` + VMMetricInclude []string `toml:"vm_metric_include"` + VMMetricExclude []string `toml:"vm_metric_exclude"` + VMInclude []string `toml:"vm_include"` + VMExclude []string `toml:"vm_exclude"` + DatastoreInstances bool + DatastoreMetricInclude []string + DatastoreMetricExclude []string + DatastoreInclude []string + DatastoreExclude []string + Separator string + CustomAttributeInclude []string + CustomAttributeExclude []string + UseIntSamples bool + IPAddresses []string + MetricLookback int MaxQueryObjects int MaxQueryMetrics int From 35a27a792d87f24da5be30917861e0e86dceb95f Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Wed, 2 Feb 2022 17:47:20 +0100 Subject: [PATCH 2/9] Update vSphere readme file --- plugins/inputs/vsphere/README.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/vsphere/README.md b/plugins/inputs/vsphere/README.md index 5b5fdaf22fd4a..4ff74b024d6a6 100644 --- a/plugins/inputs/vsphere/README.md +++ b/plugins/inputs/vsphere/README.md @@ -4,6 +4,7 @@ The VMware vSphere plugin uses the vSphere API to gather metrics from multiple v * Clusters * Hosts +* Resource Pools * VMs * Datastores @@ -140,7 +141,14 @@ vm_metric_exclude = [ "*" ] # cluster_metric_exclude = [] ## Nothing excluded by default # cluster_instances = false ## false by default - ## Datastores + ## Resource Pools + # datastore_include = [ "/*/host/**"] # Inventory path to datastores to collect (by default all are collected) + # datastore_exclude = [] # Inventory paths to exclude + # datastore_metric_include = [] ## if omitted or empty, all metrics are collected + # datastore_metric_exclude = [] ## Nothing excluded by default + # datastore_instances = false ## false by default + + ## Datastores # datastore_include = [ "/*/datastore/**"] # Inventory path to datastores to collect (by default all are collected) # datastore_exclude = [] # Inventory paths to exclude # datastore_metric_include = [] ## if omitted or empty, all metrics are collected @@ -252,10 +260,13 @@ to a file system. A vSphere inventory has a structure similar to this: | | | +-VM1 | | | +-VM2 | | | +-hadoop1 - | +-Host2 # Dummy cluster created for non-clustered host - | | +-Host2 + | | +-ResourcePool1 | | | +-VM3 | | | +-VM4 + | +-Host2 # Dummy cluster created for non-clustered host + | | +-Host2 + | | | +-VM5 + | | | +-VM6 +-vm # VM folder (created by system) | +-VM1 | +-VM2 @@ -289,7 +300,7 @@ We can extend this to looking at a cluster level: ```/DC0/host/Cluster1/*/hadoop vCenter keeps two different kinds of metrics, known as realtime and historical metrics. * Realtime metrics: Available at a 20 second granularity. These metrics are stored in memory and are very fast and cheap to query. Our tests have shown that a complete set of realtime metrics for 7000 virtual machines can be obtained in less than 20 seconds. Realtime metrics are only available on **ESXi hosts** and **virtual machine** resources. Realtime metrics are only stored for 1 hour in vCenter. -* Historical metrics: Available at a (default) 5 minute, 30 minutes, 2 hours and 24 hours rollup levels. The vSphere Telegraf plugin only uses the most granular rollup which defaults to 5 minutes but can be changed in vCenter to other interval durations. These metrics are stored in the vCenter database and can be expensive and slow to query. Historical metrics are the only type of metrics available for **clusters**, **datastores** and **datacenters**. +* Historical metrics: Available at a (default) 5 minute, 30 minutes, 2 hours and 24 hours rollup levels. The vSphere Telegraf plugin only uses the most granular rollup which defaults to 5 minutes but can be changed in vCenter to other interval durations. These metrics are stored in the vCenter database and can be expensive and slow to query. Historical metrics are the only type of metrics available for **clusters**, **datastores**, **resource pools** and **datacenters**. For more information, refer to the vSphere documentation here: @@ -314,6 +325,7 @@ This will disrupt the metric collection and can result in missed samples. The be datastore_metric_exclude = ["*"] cluster_metric_exclude = ["*"] datacenter_metric_exclude = ["*"] + resourcepool_metric_exclude = ["*"] collect_concurrency = 5 discover_concurrency = 5 @@ -400,6 +412,12 @@ When the vSphere plugin queries vCenter for historical statistics it queries for * Res CPU: active, max, running * System: operating system uptime, uptime * Virtual Disk: seeks, # reads/writes, latency, load +* Resource Pools stats: + * Memory: total, usage, active, latency, swap, shared, vmmemctl + * CPU: capacity, usage, corecount + * Disk: throughput + * Network: throughput + * Power: energy, usage * Datastore stats: * Disk: Capacity, provisioned, used @@ -415,6 +433,7 @@ For a detailed list of commonly available metrics, please refer to [METRICS.md]( * cluster (vcenter cluster) * esxhost (name of ESXi host) * guest (guest operating system id) + * resource pool name (guest operating system id) * cpu stats for Host and VM * cpu (cpu core - not all CPU fields will have this tag) * datastore stats for Host and VM From e2b0f16be373bddbf5670743af3817ab631176ad Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Wed, 2 Feb 2022 17:47:20 +0100 Subject: [PATCH 3/9] Update vSphere readme file --- plugins/inputs/vsphere/README.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/vsphere/README.md b/plugins/inputs/vsphere/README.md index 5b5fdaf22fd4a..51011b9390c35 100644 --- a/plugins/inputs/vsphere/README.md +++ b/plugins/inputs/vsphere/README.md @@ -4,6 +4,7 @@ The VMware vSphere plugin uses the vSphere API to gather metrics from multiple v * Clusters * Hosts +* Resource Pools * VMs * Datastores @@ -140,7 +141,14 @@ vm_metric_exclude = [ "*" ] # cluster_metric_exclude = [] ## Nothing excluded by default # cluster_instances = false ## false by default - ## Datastores + ## Resource Pools + # datastore_include = [ "/*/host/**"] # Inventory path to datastores to collect (by default all are collected) + # datastore_exclude = [] # Inventory paths to exclude + # datastore_metric_include = [] ## if omitted or empty, all metrics are collected + # datastore_metric_exclude = [] ## Nothing excluded by default + # datastore_instances = false ## false by default + + ## Datastores # datastore_include = [ "/*/datastore/**"] # Inventory path to datastores to collect (by default all are collected) # datastore_exclude = [] # Inventory paths to exclude # datastore_metric_include = [] ## if omitted or empty, all metrics are collected @@ -252,10 +260,13 @@ to a file system. A vSphere inventory has a structure similar to this: | | | +-VM1 | | | +-VM2 | | | +-hadoop1 - | +-Host2 # Dummy cluster created for non-clustered host - | | +-Host2 + | | +-ResourcePool1 | | | +-VM3 | | | +-VM4 + | +-Host2 # Dummy cluster created for non-clustered host + | | +-Host2 + | | | +-VM5 + | | | +-VM6 +-vm # VM folder (created by system) | +-VM1 | +-VM2 @@ -289,7 +300,7 @@ We can extend this to looking at a cluster level: ```/DC0/host/Cluster1/*/hadoop vCenter keeps two different kinds of metrics, known as realtime and historical metrics. * Realtime metrics: Available at a 20 second granularity. These metrics are stored in memory and are very fast and cheap to query. Our tests have shown that a complete set of realtime metrics for 7000 virtual machines can be obtained in less than 20 seconds. Realtime metrics are only available on **ESXi hosts** and **virtual machine** resources. Realtime metrics are only stored for 1 hour in vCenter. -* Historical metrics: Available at a (default) 5 minute, 30 minutes, 2 hours and 24 hours rollup levels. The vSphere Telegraf plugin only uses the most granular rollup which defaults to 5 minutes but can be changed in vCenter to other interval durations. These metrics are stored in the vCenter database and can be expensive and slow to query. Historical metrics are the only type of metrics available for **clusters**, **datastores** and **datacenters**. +* Historical metrics: Available at a (default) 5 minute, 30 minutes, 2 hours and 24 hours rollup levels. The vSphere Telegraf plugin only uses the most granular rollup which defaults to 5 minutes but can be changed in vCenter to other interval durations. These metrics are stored in the vCenter database and can be expensive and slow to query. Historical metrics are the only type of metrics available for **clusters**, **datastores**, **resource pools** and **datacenters**. For more information, refer to the vSphere documentation here: @@ -314,6 +325,7 @@ This will disrupt the metric collection and can result in missed samples. The be datastore_metric_exclude = ["*"] cluster_metric_exclude = ["*"] datacenter_metric_exclude = ["*"] + resourcepool_metric_exclude = ["*"] collect_concurrency = 5 discover_concurrency = 5 @@ -400,6 +412,12 @@ When the vSphere plugin queries vCenter for historical statistics it queries for * Res CPU: active, max, running * System: operating system uptime, uptime * Virtual Disk: seeks, # reads/writes, latency, load +* Resource Pools stats: + * Memory: total, usage, active, latency, swap, shared, vmmemctl + * CPU: capacity, usage, corecount + * Disk: throughput + * Network: throughput + * Power: energy, usage * Datastore stats: * Disk: Capacity, provisioned, used @@ -415,6 +433,7 @@ For a detailed list of commonly available metrics, please refer to [METRICS.md]( * cluster (vcenter cluster) * esxhost (name of ESXi host) * guest (guest operating system id) + * resource pool (name of resource pool) * cpu stats for Host and VM * cpu (cpu core - not all CPU fields will have this tag) * datastore stats for Host and VM From e56e85e3cbad2efd18681f95ad93c97955a43cfb Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Wed, 2 Feb 2022 18:00:19 +0100 Subject: [PATCH 4/9] Correct typo in vSphere Readme --- plugins/inputs/vsphere/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inputs/vsphere/README.md b/plugins/inputs/vsphere/README.md index 9d0dc00e5da40..51011b9390c35 100644 --- a/plugins/inputs/vsphere/README.md +++ b/plugins/inputs/vsphere/README.md @@ -434,7 +434,6 @@ For a detailed list of commonly available metrics, please refer to [METRICS.md]( * esxhost (name of ESXi host) * guest (guest operating system id) * resource pool (name of resource pool) - * resource pool name (guest operating system id) * cpu stats for Host and VM * cpu (cpu core - not all CPU fields will have this tag) * datastore stats for Host and VM From 7d90bbde5ec505dec4a7233e1993e28341e21622 Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Thu, 3 Feb 2022 09:26:25 +0100 Subject: [PATCH 5/9] Correct Markdown of metrics.md --- plugins/inputs/vsphere/METRICS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/inputs/vsphere/METRICS.md b/plugins/inputs/vsphere/METRICS.md index 411161c0ade91..e39c5b2df3111 100644 --- a/plugins/inputs/vsphere/METRICS.md +++ b/plugins/inputs/vsphere/METRICS.md @@ -194,7 +194,12 @@ vmop.numXVMotion.latest ``` ## Resource Pool Metrics + +<<<<<<< HEAD +```metrics +======= ``` +>>>>>>> 696e8df5... Correct Markdown of metrics.md cpu.usagemhz.average cpu.cpuentitlement.latest cpu.usagemhz.minimum From 0b49f2910f2841ddc69eeb06ce5a7ccbf10fdb34 Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Thu, 3 Feb 2022 09:37:30 +0100 Subject: [PATCH 6/9] Fix metrics file --- plugins/inputs/vsphere/METRICS.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/inputs/vsphere/METRICS.md b/plugins/inputs/vsphere/METRICS.md index e39c5b2df3111..584ac8cc744a9 100644 --- a/plugins/inputs/vsphere/METRICS.md +++ b/plugins/inputs/vsphere/METRICS.md @@ -195,11 +195,7 @@ vmop.numXVMotion.latest ## Resource Pool Metrics -<<<<<<< HEAD ```metrics -======= -``` ->>>>>>> 696e8df5... Correct Markdown of metrics.md cpu.usagemhz.average cpu.cpuentitlement.latest cpu.usagemhz.minimum From bb23af73f9b7cbc7828b7ff564a478779bfadf9f Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Thu, 3 Feb 2022 17:43:21 +0100 Subject: [PATCH 7/9] Fix code in endpoint (filter); add some tests --- plugins/inputs/vsphere/endpoint.go | 4 +- plugins/inputs/vsphere/vsphere.go | 54 ++++++++++++++------------ plugins/inputs/vsphere/vsphere_test.go | 23 ++++++++--- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/plugins/inputs/vsphere/endpoint.go b/plugins/inputs/vsphere/endpoint.go index 3078b43fcbd06..f528d8a02d27b 100644 --- a/plugins/inputs/vsphere/endpoint.go +++ b/plugins/inputs/vsphere/endpoint.go @@ -673,9 +673,9 @@ func getClusters(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilte } //noinspection GoUnusedParameter -func getResourcePools(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) { +func getResourcePools(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) { var resources []mo.ResourcePool - err := filter.FindAll(ctx, &resources) + err := resourceFilter.FindAll(ctx, &resources) if err != nil { return nil, err } diff --git a/plugins/inputs/vsphere/vsphere.go b/plugins/inputs/vsphere/vsphere.go index a8505727dd402..736b43657bb78 100644 --- a/plugins/inputs/vsphere/vsphere.go +++ b/plugins/inputs/vsphere/vsphere.go @@ -350,31 +350,35 @@ func init() { return &VSphere{ Vcenters: []string{}, - DatacenterInstances: false, - DatacenterMetricInclude: nil, - DatacenterMetricExclude: nil, - DatacenterInclude: []string{"/*"}, - ClusterInstances: false, - ClusterMetricInclude: nil, - ClusterMetricExclude: nil, - ClusterInclude: []string{"/*/host/**"}, - HostInstances: true, - HostMetricInclude: nil, - HostMetricExclude: nil, - HostInclude: []string{"/*/host/**"}, - VMInstances: true, - VMMetricInclude: nil, - VMMetricExclude: nil, - VMInclude: []string{"/*/vm/**"}, - DatastoreInstances: false, - DatastoreMetricInclude: nil, - DatastoreMetricExclude: nil, - DatastoreInclude: []string{"/*/datastore/**"}, - Separator: "_", - CustomAttributeInclude: []string{}, - CustomAttributeExclude: []string{"*"}, - UseIntSamples: true, - IPAddresses: []string{}, + DatacenterInstances: false, + DatacenterMetricInclude: nil, + DatacenterMetricExclude: nil, + DatacenterInclude: []string{"/*"}, + ClusterInstances: false, + ClusterMetricInclude: nil, + ClusterMetricExclude: nil, + ClusterInclude: []string{"/*/host/**"}, + HostInstances: true, + HostMetricInclude: nil, + HostMetricExclude: nil, + HostInclude: []string{"/*/host/**"}, + ResourcePoolInstances: false, + ResourcePoolMetricInclude: nil, + ResourcePoolMetricExclude: nil, + ResourcePoolInclude: []string{"/*/host/**"}, + VMInstances: true, + VMMetricInclude: nil, + VMMetricExclude: nil, + VMInclude: []string{"/*/vm/**"}, + DatastoreInstances: false, + DatastoreMetricInclude: nil, + DatastoreMetricExclude: nil, + DatastoreInclude: []string{"/*/datastore/**"}, + Separator: "_", + CustomAttributeInclude: []string{}, + CustomAttributeExclude: []string{"*"}, + UseIntSamples: true, + IPAddresses: []string{}, MaxQueryObjects: 256, MaxQueryMetrics: 256, diff --git a/plugins/inputs/vsphere/vsphere_test.go b/plugins/inputs/vsphere/vsphere_test.go index 2e8654efcd6c6..427eb26bbfdf3 100644 --- a/plugins/inputs/vsphere/vsphere_test.go +++ b/plugins/inputs/vsphere/vsphere_test.go @@ -139,12 +139,17 @@ func defaultVSphere() *VSphere { DatastoreMetricInclude: []string{ "disk.used.*", "disk.provisioned.*"}, - DatastoreMetricExclude: nil, - DatastoreInclude: []string{"/**"}, - DatacenterMetricInclude: nil, - DatacenterMetricExclude: nil, - DatacenterInclude: []string{"/**"}, - ClientConfig: itls.ClientConfig{InsecureSkipVerify: true}, + DatastoreMetricExclude: nil, + DatastoreInclude: []string{"/**"}, + ResourcePoolMetricInclude: []string{ + "cpu.capacity.*", + "mem.capacity.*"}, + ResourcePoolMetricExclude: nil, + ResourcePoolInclude: []string{"/**"}, + DatacenterMetricInclude: nil, + DatacenterMetricExclude: nil, + DatacenterInclude: []string{"/**"}, + ClientConfig: itls.ClientConfig{InsecureSkipVerify: true}, MaxQueryObjects: 256, MaxQueryMetrics: 256, @@ -335,6 +340,12 @@ func TestFinder(t *testing.T) { require.Equal(t, 1, len(host)) require.Equal(t, "DC0_C0_H0", host[0].Name) + var resourcepool = []mo.ResourcePool{} + err = f.Find(ctx, "ResourcePool", "/DC0/host/DC0_C0/Resources/DC0_C0_RP0", &resourcepool) + require.NoError(t, err) + require.Equal(t, 1, len(host)) + require.Equal(t, "DC0_C0_H0", host[0].Name) + host = []mo.HostSystem{} err = f.Find(ctx, "HostSystem", "/DC0/host/DC0_C0/*", &host) require.NoError(t, err) From a9b35eadf9fbf22af494f7ff56e966f1c7b53ac3 Mon Sep 17 00:00:00 2001 From: 6monlambert <32525162+6monlambert@users.noreply.github.com> Date: Fri, 4 Feb 2022 09:47:34 +0100 Subject: [PATCH 8/9] Update plugins/inputs/vsphere/endpoint.go That's true I commit this suggestion Co-authored-by: Sebastian Spaink <3441183+sspaink@users.noreply.github.com> --- plugins/inputs/vsphere/endpoint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/vsphere/endpoint.go b/plugins/inputs/vsphere/endpoint.go index f528d8a02d27b..38bae270b01f4 100644 --- a/plugins/inputs/vsphere/endpoint.go +++ b/plugins/inputs/vsphere/endpoint.go @@ -691,7 +691,7 @@ func getResourcePools(ctx context.Context, e *Endpoint, resourceFilter *Resource return m, nil } -func getResourcePoolName(ctx context.Context, e *Endpoint, rp types.ManagedObjectReference, rps objectMap) string { +func getResourcePoolName(rp types.ManagedObjectReference, rps objectMap) string { //Loop through the Resource Pools objectmap to find the corresponding one for _, r := range rps { if r.ref == rp { From 04be44e89fc3c62457d29ef619b86369f9bc4d04 Mon Sep 17 00:00:00 2001 From: Simon LAMBERT Date: Fri, 4 Feb 2022 09:54:51 +0100 Subject: [PATCH 9/9] Removed Context and Endpoint from getResourcePoolName func --- plugins/inputs/vsphere/endpoint.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/vsphere/endpoint.go b/plugins/inputs/vsphere/endpoint.go index f528d8a02d27b..c6a7f29c63789 100644 --- a/plugins/inputs/vsphere/endpoint.go +++ b/plugins/inputs/vsphere/endpoint.go @@ -691,14 +691,14 @@ func getResourcePools(ctx context.Context, e *Endpoint, resourceFilter *Resource return m, nil } -func getResourcePoolName(ctx context.Context, e *Endpoint, rp types.ManagedObjectReference, rps objectMap) string { +func getResourcePoolName(rp types.ManagedObjectReference, rps objectMap) string { //Loop through the Resource Pools objectmap to find the corresponding one for _, r := range rps { if r.ref == rp { return r.name } } - return "Resources" + return "Resources" //Default value } //noinspection GoUnusedParameter @@ -751,7 +751,7 @@ func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (o uuid := "" lookup := make(map[string]string) // Get the name of the VM resource pool - rpname := getResourcePoolName(ctx, e, *r.ResourcePool, resourcePools) + rpname := getResourcePoolName(*r.ResourcePool, resourcePools) // Extract host name if r.Guest != nil && r.Guest.HostName != "" {