@@ -101,6 +101,7 @@ def __init__(
101
101
'datastores' : ['ds_name' , 'dc_name' , 'ds_cluster' ],
102
102
'hosts' : ['host_name' , 'dc_name' , 'cluster_name' ],
103
103
'host_perf' : ['host_name' , 'dc_name' , 'cluster_name' ],
104
+ 'volumes' : ['datastore' , 'volume' , 'backing_file_path' ],
104
105
}
105
106
106
107
# if tags are gonna be fetched 'tags' will be a label too
@@ -295,6 +296,23 @@ def _create_metric_containers(self):
295
296
'VMWare sensor redundancy value (1=ok / 0=ko) labeled by sensor name from the host.' ,
296
297
labels = self ._labelNames ['hosts' ] + ['name' ]),
297
298
}
299
+ metric_list ['volumes' ] = {
300
+ 'vmware_volume_snapshots' : GaugeMetricFamily (
301
+ 'vmware_volume_snapshots' ,
302
+ 'Number of snaphots for the volume' ,
303
+ labels = self ._labelNames ['volumes' ],
304
+ ),
305
+ 'vmware_volume_capacity_bytes' : GaugeMetricFamily (
306
+ 'vmware_volume_capacity_bytes' ,
307
+ 'The configured capacity of the volume' ,
308
+ labels = self ._labelNames ['volumes' ],
309
+ ),
310
+ 'vmware_volume_snapshot_createtime' : GaugeMetricFamily (
311
+ 'vmware_volume_snapshot_createtime' ,
312
+ 'Create time of snapshot as a unix timestamp' ,
313
+ labels = self ._labelNames ['volumes' ] + ['snapshot_id' ],
314
+ )
315
+ }
298
316
299
317
"""
300
318
if alarms are being retrieved, metrics have to been created here
@@ -427,6 +445,9 @@ def collect(self):
427
445
tasks .append (self ._vmware_get_hosts (metrics ))
428
446
tasks .append (self ._vmware_get_host_perf_manager_metrics (metrics ))
429
447
448
+ if collect_only ['volumes' ] is True :
449
+ tasks .append (self ._vmware_get_volumes (metrics ))
450
+
430
451
yield parallelize (* tasks )
431
452
432
453
yield self ._vmware_disconnect ()
@@ -534,7 +555,7 @@ def tags(self):
534
555
and linked to object moid
535
556
"""
536
557
logging .info ("Fetching tags" )
537
- start = datetime .datetime .utcnow ( )
558
+ start = datetime .datetime .now ( datetime . UTC )
538
559
539
560
attachedObjs = yield self ._attachedObjectsOnTags
540
561
tagNames = yield self ._tagNames
@@ -556,7 +577,7 @@ def tags(self):
556
577
else :
557
578
tags [section ][obj .get ('id' )].append (tagName )
558
579
559
- fetch_time = datetime .datetime .utcnow ( ) - start
580
+ fetch_time = datetime .datetime .now ( datetime . UTC ) - start
560
581
logging .info ("Fetched tags ({fetch_time})" .format (fetch_time = fetch_time ))
561
582
562
583
return tags
@@ -612,7 +633,7 @@ def batch_fetch_properties(self, objtype, properties):
612
633
@defer .inlineCallbacks
613
634
def datastore_inventory (self ):
614
635
logging .info ("Fetching vim.Datastore inventory" )
615
- start = datetime .datetime .utcnow ( )
636
+ start = datetime .datetime .now ( datetime . UTC )
616
637
properties = [
617
638
'name' ,
618
639
'summary.capacity' ,
@@ -657,7 +678,7 @@ def datastore_inventory(self):
657
678
]
658
679
)
659
680
660
- fetch_time = datetime .datetime .utcnow ( ) - start
681
+ fetch_time = datetime .datetime .now ( datetime . UTC ) - start
661
682
logging .info ("Fetched vim.Datastore inventory ({fetch_time})" .format (fetch_time = fetch_time ))
662
683
663
684
return datastores
@@ -666,7 +687,7 @@ def datastore_inventory(self):
666
687
@defer .inlineCallbacks
667
688
def host_system_inventory (self ):
668
689
logging .info ("Fetching vim.HostSystem inventory" )
669
- start = datetime .datetime .utcnow ( )
690
+ start = datetime .datetime .now ( datetime . UTC )
670
691
properties = [
671
692
'name' ,
672
693
'parent' ,
@@ -723,7 +744,7 @@ def host_system_inventory(self):
723
744
]
724
745
)
725
746
726
- fetch_time = datetime .datetime .utcnow ( ) - start
747
+ fetch_time = datetime .datetime .now ( datetime . UTC ) - start
727
748
logging .info ("Fetched vim.HostSystem inventory ({fetch_time})" .format (fetch_time = fetch_time ))
728
749
729
750
return host_systems
@@ -732,7 +753,7 @@ def host_system_inventory(self):
732
753
@defer .inlineCallbacks
733
754
def vm_inventory (self ):
734
755
logging .info ("Fetching vim.VirtualMachine inventory" )
735
- start = datetime .datetime .utcnow ( )
756
+ start = datetime .datetime .now ( datetime . UTC )
736
757
properties = [
737
758
'name' ,
738
759
'runtime.host' ,
@@ -792,7 +813,7 @@ def vm_inventory(self):
792
813
]
793
814
)
794
815
795
- fetch_time = datetime .datetime .utcnow ( ) - start
816
+ fetch_time = datetime .datetime .now ( datetime . UTC ) - start
796
817
logging .info ("Fetched vim.VirtualMachine inventory ({fetch_time})" .format (fetch_time = fetch_time ))
797
818
798
819
return virtual_machines
@@ -1701,8 +1722,8 @@ def _vmware_get_hosts(self, host_metrics):
1701
1722
1702
1723
# Numeric Sensor Info
1703
1724
sensors = host .get ('runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo' , '' ).split (',' ) + \
1704
- host .get ('runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo' , '' ).split (',' ) + \
1705
- host .get ('runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo' , '' ).split (',' )
1725
+ host .get ('runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo' , '' ).split (',' ) + \
1726
+ host .get ('runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo' , '' ).split (',' )
1706
1727
1707
1728
sensors = [s for s in sensors if ':' in s ]
1708
1729
@@ -1847,6 +1868,50 @@ def _vmware_get_hosts(self, host_metrics):
1847
1868
logging .info ("Finished host metrics collection" )
1848
1869
return results
1849
1870
1871
+ @defer .inlineCallbacks
1872
+ def _vmware_get_volumes (self , vol_metrics ):
1873
+ """
1874
+ Get Volume information
1875
+ """
1876
+
1877
+ datastores = yield parallelize (self .datastore_inventory )
1878
+ content = yield self .content
1879
+
1880
+ for datastore_id , datastore in datastores [0 ].items ():
1881
+ volumes = content .vStorageObjectManager .ListVStorageObject (datastore ['obj' ])
1882
+ for volume_ref in volumes :
1883
+ try :
1884
+ volume = content .vStorageObjectManager .RetrieveVStorageObject (volume_ref , datastore ['obj' ])
1885
+ except vim .fault .NotFound :
1886
+ logging .error ("Volume %s was listed in the datastore, but the storage object could not be found" ,
1887
+ volume_ref .id )
1888
+ except Exception as error :
1889
+ logging .error ("Error fetching volume information for volume %s: %s" , volume_ref .id , error )
1890
+ try :
1891
+ snapshot_info = content .vStorageObjectManager .RetrieveSnapshotInfo (volume_ref , datastore ['obj' ])
1892
+ vol_metrics ['vmware_volume_snapshots' ].add_metric ([
1893
+ datastore ['name' ],
1894
+ volume .config .name ,
1895
+ volume .config .backing .filePath
1896
+ ], len (snapshot_info .snapshots ))
1897
+
1898
+ vol_metrics ['vmware_volume_capacity_bytes' ].add_metric ([
1899
+ datastore ['name' ],
1900
+ volume .config .name ,
1901
+ volume .config .backing .filePath
1902
+ ], volume .config .capacityInMB * 1024 * 1024 )
1903
+
1904
+ for snapshot in snapshot_info .snapshots :
1905
+ vol_metrics ['vmware_volume_snapshot_createtime' ].add_metric ([
1906
+ datastore ['name' ],
1907
+ volume .config .name ,
1908
+ volume .config .backing .filePath ,
1909
+ snapshot .id .id ,
1910
+ ], int (snapshot .createTime .timestamp ()))
1911
+ except vim .fault .NotFound :
1912
+ logging .error ("Snapshot info for volume %s not found" ,volume_ref .id )
1913
+ except Exception as error :
1914
+ logging .error ("Error fetching snapshot information for volume: %s" , volume_ref .id , error )
1850
1915
1851
1916
class ListCollector (object ):
1852
1917
@@ -1896,6 +1961,7 @@ def configure(self, args):
1896
1961
'datastores' : get_bool_env ('VSPHERE_COLLECT_DATASTORES' , True ),
1897
1962
'hosts' : get_bool_env ('VSPHERE_COLLECT_HOSTS' , True ),
1898
1963
'snapshots' : get_bool_env ('VSPHERE_COLLECT_SNAPSHOTS' , True ),
1964
+ 'volumes' : get_bool_env ('VSPHERE_COLLECT_VOLUMES' , False ),
1899
1965
}
1900
1966
}
1901
1967
}
@@ -1923,6 +1989,7 @@ def configure(self, args):
1923
1989
'datastores' : get_bool_env ('VSPHERE_{}_COLLECT_DATASTORES' .format (section ), True ),
1924
1990
'hosts' : get_bool_env ('VSPHERE_{}_COLLECT_HOSTS' .format (section ), True ),
1925
1991
'snapshots' : get_bool_env ('VSPHERE_{}_COLLECT_SNAPSHOTS' .format (section ), True ),
1992
+ 'volumes' : get_bool_env ('VSPHERE_COLLECT_VOLUMES' , False ),
1926
1993
}
1927
1994
}
1928
1995
0 commit comments