Skip to content

Commit c0bb862

Browse files
prydindanielnelson
authored andcommitted
Add resource path based filtering to vsphere input (#5165)
1 parent ddf35dd commit c0bb862

File tree

7 files changed

+641
-116
lines changed

7 files changed

+641
-116
lines changed

plugins/inputs/vsphere/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ vm_metric_exclude = [ "*" ]
2727
2828
## VMs
2929
## Typical VM metrics (if omitted or empty, all metrics are collected)
30+
# vm_include = [ "/*/vm/**"] # Inventory path to VMs to collect (by default all are collected)
3031
vm_metric_include = [
3132
"cpu.demand.average",
3233
"cpu.idle.summation",
@@ -68,6 +69,7 @@ vm_metric_exclude = [ "*" ]
6869
6970
## Hosts
7071
## Typical host metrics (if omitted or empty, all metrics are collected)
72+
# host_include = [ "/*/host/**"] # Inventory path to hosts to collect (by default all are collected)
7173
host_metric_include = [
7274
"cpu.coreUtilization.average",
7375
"cpu.costop.summation",
@@ -120,16 +122,19 @@ vm_metric_exclude = [ "*" ]
120122
# host_instances = true ## true by default
121123
122124
## Clusters
125+
# cluster_include = [ "/*/host/**"] # Inventory path to clusters to collect (by default all are collected)
123126
# cluster_metric_include = [] ## if omitted or empty, all metrics are collected
124127
# cluster_metric_exclude = [] ## Nothing excluded by default
125128
# cluster_instances = false ## false by default
126129
127130
## Datastores
131+
# cluster_include = [ "/*/datastore/**"] # Inventory path to datastores to collect (by default all are collected)
128132
# datastore_metric_include = [] ## if omitted or empty, all metrics are collected
129133
# datastore_metric_exclude = [] ## Nothing excluded by default
130134
# datastore_instances = false ## false by default
131135
132136
## Datacenters
137+
# datacenter_include = [ "/*/host/**"] # Inventory path to clusters to collect (by default all are collected)
133138
datacenter_metric_include = [] ## if omitted or empty, all metrics are collected
134139
datacenter_metric_exclude = [ "*" ] ## Datacenters are not collected by default.
135140
# datacenter_instances = false ## false by default
@@ -196,6 +201,48 @@ For setting up concurrency, modify `collect_concurrency` and `discover_concurren
196201
# discover_concurrency = 1
197202
```
198203

204+
### Inventory Paths
205+
Resources to be monitored can be selected using Inventory Paths. This treats the vSphere inventory as a tree structure similar
206+
to a file system. A vSphere inventory has a structure similar to this:
207+
208+
```
209+
<root>
210+
+-DC0 # Virtual datacenter
211+
+-datastore # Datastore folder (created by system)
212+
| +-Datastore1
213+
+-host # Host folder (created by system)
214+
| +-Cluster1
215+
| | +-Host1
216+
| | | +-VM1
217+
| | | +-VM2
218+
| | | +-hadoop1
219+
| +-Host2 # Dummy cluster created for non-clustered host
220+
| | +-Host2
221+
| | | +-VM3
222+
| | | +-VM4
223+
+-vm # VM folder (created by system)
224+
| +-VM1
225+
| +-VM2
226+
| +-Folder1
227+
| | +-hadoop1
228+
| | +-NestedFolder1
229+
| | | +-VM3
230+
| | | +-VM4
231+
```
232+
233+
#### Using Inventory Paths
234+
Using familiar UNIX-style paths, one could select e.g. VM2 with the path ```/DC0/vm/VM2```.
235+
236+
Often, we want to select a group of resource, such as all the VMs in a folder. We could use the path ```/DC0/vm/Folder1/*``` for that.
237+
238+
Another possibility is to select objects using a partial name, such as ```/DC0/vm/Folder1/hadoop*``` yielding all vms in Folder1 with a name starting with "hadoop".
239+
240+
Finally, due to the arbitrary nesting of the folder structure, we need a "recursive wildcard" for traversing multiple folders. We use the "**" symbol for that. If we want to look for a VM with a name starting with "hadoop" in any folder, we could use the following path: ```/DC0/vm/**/hadoop*```
241+
242+
#### Multiple paths to VMs
243+
As we can see from the example tree above, VMs appear both in its on folder under the datacenter, as well as under the hosts. This is useful when you like to select VMs on a specific host. For example, ```/DC0/host/Cluster1/Host1/hadoop*``` selects all VMs with a name starting with "hadoop" that are running on Host1.
244+
245+
We can extend this to looking at a cluster level: ```/DC0/host/Cluster1/*/hadoop*```. This selects any VM matching "hadoop*" on any host in Cluster1.
199246
## Performance Considerations
200247

201248
### Realtime vs. historical metrics

plugins/inputs/vsphere/client.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (cf *ClientFactory) GetClient(ctx context.Context) (*Client, error) {
7474
ctx1, cancel1 := context.WithTimeout(ctx, cf.parent.Timeout.Duration)
7575
defer cancel1()
7676
if _, err := methods.GetCurrentTime(ctx1, cf.client.Client); err != nil {
77-
log.Printf("I! [input.vsphere]: Client session seems to have time out. Reauthenticating!")
77+
log.Printf("I! [inputs.vsphere]: Client session seems to have time out. Reauthenticating!")
7878
ctx2, cancel2 := context.WithTimeout(ctx, cf.parent.Timeout.Duration)
7979
defer cancel2()
8080
if cf.client.Client.SessionManager.Login(ctx2, url.UserPassword(cf.parent.Username, cf.parent.Password)) != nil {
@@ -102,7 +102,7 @@ func NewClient(ctx context.Context, u *url.URL, vs *VSphere) (*Client, error) {
102102
u.User = url.UserPassword(vs.Username, vs.Password)
103103
}
104104

105-
log.Printf("D! [input.vsphere]: Creating client: %s", u.Host)
105+
log.Printf("D! [inputs.vsphere]: Creating client: %s", u.Host)
106106
soapClient := soap.NewClient(u, tlsCfg.InsecureSkipVerify)
107107

108108
// Add certificate if we have it. Use it to log us in.
@@ -173,9 +173,9 @@ func NewClient(ctx context.Context, u *url.URL, vs *VSphere) (*Client, error) {
173173
if err != nil {
174174
return nil, err
175175
}
176-
log.Printf("D! [input.vsphere] vCenter says max_query_metrics should be %d", n)
176+
log.Printf("D! [inputs.vsphere] vCenter says max_query_metrics should be %d", n)
177177
if n < vs.MaxQueryMetrics {
178-
log.Printf("W! [input.vsphere] Configured max_query_metrics is %d, but server limits it to %d. Reducing.", vs.MaxQueryMetrics, n)
178+
log.Printf("W! [inputs.vsphere] Configured max_query_metrics is %d, but server limits it to %d. Reducing.", vs.MaxQueryMetrics, n)
179179
vs.MaxQueryMetrics = n
180180
}
181181
return client, nil
@@ -199,7 +199,7 @@ func (c *Client) close() {
199199
defer cancel()
200200
if c.Client != nil {
201201
if err := c.Client.Logout(ctx); err != nil {
202-
log.Printf("E! [input.vsphere]: Error during logout: %s", err)
202+
log.Printf("E! [inputs.vsphere]: Error during logout: %s", err)
203203
}
204204
}
205205
})
@@ -228,7 +228,7 @@ func (c *Client) GetMaxQueryMetrics(ctx context.Context) (int, error) {
228228
if s, ok := res[0].GetOptionValue().Value.(string); ok {
229229
v, err := strconv.Atoi(s)
230230
if err == nil {
231-
log.Printf("D! [input.vsphere] vCenter maxQueryMetrics is defined: %d", v)
231+
log.Printf("D! [inputs.vsphere] vCenter maxQueryMetrics is defined: %d", v)
232232
if v == -1 {
233233
// Whatever the server says, we never ask for more metrics than this.
234234
return absoluteMaxMetrics, nil
@@ -239,17 +239,17 @@ func (c *Client) GetMaxQueryMetrics(ctx context.Context) (int, error) {
239239
// Fall through version-based inference if value isn't usable
240240
}
241241
} else {
242-
log.Println("D! [input.vsphere] Option query for maxQueryMetrics failed. Using default")
242+
log.Println("D! [inputs.vsphere] Option query for maxQueryMetrics failed. Using default")
243243
}
244244

245245
// No usable maxQueryMetrics setting. Infer based on version
246246
ver := c.Client.Client.ServiceContent.About.Version
247247
parts := strings.Split(ver, ".")
248248
if len(parts) < 2 {
249-
log.Printf("W! [input.vsphere] vCenter returned an invalid version string: %s. Using default query size=64", ver)
249+
log.Printf("W! [inputs.vsphere] vCenter returned an invalid version string: %s. Using default query size=64", ver)
250250
return 64, nil
251251
}
252-
log.Printf("D! [input.vsphere] vCenter version is: %s", ver)
252+
log.Printf("D! [inputs.vsphere] vCenter version is: %s", ver)
253253
major, err := strconv.Atoi(parts[0])
254254
if err != nil {
255255
return 0, err

0 commit comments

Comments
 (0)