@@ -44,7 +44,8 @@ def __init__(self, name, init_config, instances):
44
44
self .host = self .instance .get ("host" )
45
45
self .username = self .instance .get ("username" )
46
46
self .password = self .instance .get ("password" )
47
- self .use_guest_hostname = self .instance .get ("use_guest_hostname" , False )
47
+ self .use_guest_hostname = is_affirmative (self .instance .get ("use_guest_hostname" , False ))
48
+ self .use_configured_hostname = is_affirmative (self .instance .get ("use_configured_hostname" , False ))
48
49
self .excluded_host_tags = self ._validate_excluded_host_tags (self .instance .get ("excluded_host_tags" , []))
49
50
self .collect_per_instance_filters = self ._parse_metric_regex_filters (
50
51
self .instance .get ("collect_per_instance_filters" , {})
@@ -238,7 +239,7 @@ def get_available_metric_ids_for_entity(self, entity):
238
239
metric_ids = [vim .PerformanceManager .MetricId (counterId = counter , instance = "" ) for counter in counter_ids ]
239
240
return counter_keys_and_names , metric_ids
240
241
241
- def collect_metrics_for_entity (self , metric_ids , counter_keys_and_names , entity , entity_name , metric_tags ):
242
+ def collect_metrics_for_entity (self , metric_ids , counter_keys_and_names , entity , hostname , metric_tags ):
242
243
resource_type = type (entity )
243
244
resource_name = RESOURCE_TYPE_TO_NAME [resource_type ]
244
245
for metric_id in metric_ids :
@@ -297,7 +298,7 @@ def collect_metrics_for_entity(self, metric_ids, counter_keys_and_names, entity,
297
298
self .log .debug (
298
299
"Skipping metric %s for %s because no value was returned by the %s" ,
299
300
metric_name ,
300
- entity_name ,
301
+ hostname ,
301
302
resource_name ,
302
303
)
303
304
continue
@@ -308,7 +309,7 @@ def collect_metrics_for_entity(self, metric_ids, counter_keys_and_names, entity,
308
309
"Skipping metric %s for %s, because the value returned by the %s"
309
310
" is negative (i.e. the metric is not yet available). values: %s" ,
310
311
metric_name ,
311
- entity_name ,
312
+ hostname ,
312
313
resource_name ,
313
314
list (metric_result .value ),
314
315
)
@@ -321,10 +322,10 @@ def collect_metrics_for_entity(self, metric_ids, counter_keys_and_names, entity,
321
322
"Submit metric: name=`%s`, value=`%s`, hostname=`%s`, tags=`%s`" ,
322
323
metric_name ,
323
324
most_recent_val ,
324
- entity_name ,
325
+ hostname ,
325
326
all_tags ,
326
327
)
327
- self .gauge (metric_name , most_recent_val , hostname = entity_name , tags = all_tags )
328
+ self .gauge (metric_name , most_recent_val , hostname = hostname , tags = all_tags )
328
329
329
330
def set_version_metadata (self ):
330
331
esxi_version = self .content .about .version
@@ -388,6 +389,8 @@ def check(self, _):
388
389
}
389
390
390
391
for resource_obj , resource_props in all_resources_with_metrics .items ():
392
+ resource_type = type (resource_obj )
393
+ resource_type_name = RESOURCE_TYPE_TO_NAME [resource_type ]
391
394
392
395
if not is_resource_collected_by_filters (resource_obj , all_resources_with_metrics , self .resource_filters ):
393
396
self .log .debug (
@@ -397,16 +400,18 @@ def check(self, _):
397
400
398
401
hostname = resource_props .get ("name" )
399
402
400
- resource_type = RESOURCE_TYPE_TO_NAME [type (resource_obj )]
401
- if resource_type == "vm" and self .use_guest_hostname :
403
+ if resource_type == VM_RESOURCE and self .use_guest_hostname :
402
404
hostname = resource_props .get ("guest.hostName" , hostname )
403
405
406
+ if resource_type == HOST_RESOURCE and self .use_configured_hostname :
407
+ hostname = self .host
408
+
404
409
self .log .debug ("Collect metrics and host tags for hostname: %s, object: %s" , hostname , resource_obj )
405
410
406
411
tags = []
407
412
parent = resource_props .get ('parent' )
408
413
409
- if resource_type == "vm" :
414
+ if resource_type == VM_RESOURCE :
410
415
runtime_host = resource_props .get ('runtime.host' )
411
416
runtime_host_props = {}
412
417
if runtime_host :
@@ -430,7 +435,7 @@ def check(self, _):
430
435
if parent is not None :
431
436
tags .extend (get_tags_recursively (parent , resource_map ))
432
437
433
- tags .append ('esxi_type:{}' .format (resource_type ))
438
+ tags .append ('esxi_type:{}' .format (resource_type_name ))
434
439
435
440
metric_tags = self .tags
436
441
if self .excluded_host_tags :
@@ -444,7 +449,7 @@ def check(self, _):
444
449
else :
445
450
self .log .debug ("No host name found for %s; skipping external tag submission" , resource_obj )
446
451
447
- self .count (f"{ resource_type } .count" , 1 , tags = tags , hostname = None )
452
+ self .count (f"{ resource_type_name } .count" , 1 , tags = tags , hostname = None )
448
453
449
454
counter_keys_and_names , metric_ids = self .get_available_metric_ids_for_entity (resource_obj )
450
455
self .collect_metrics_for_entity (metric_ids , counter_keys_and_names , resource_obj , hostname , metric_tags )
0 commit comments