@@ -13,6 +13,13 @@ import (
13
13
func createHostSamples (config * load.Config ) {
14
14
for _ , dc := range config .Datacenters {
15
15
for _ , host := range dc .Hosts {
16
+
17
+ if host .Summary .Hardware == nil {
18
+ continue
19
+ }
20
+ // bios uuid identifies the host unequivocally and is available from vcenter/host api
21
+ uuid := host .Summary .Hardware .Uuid
22
+
16
23
hostConfigName := host .Summary .Config .Name
17
24
entityName := hostConfigName
18
25
datacenterName := dc .Datacenter .Name
@@ -23,10 +30,11 @@ func createHostSamples(config *load.Config) {
23
30
24
31
entityName = sanitizeEntityName (config , entityName , datacenterName )
25
32
26
- // bios uuid identifies the host unequivocally and is available from vcenter/host api
27
- uuid := host .Summary .Hardware .Uuid
28
-
29
- ms := createNewEntityWithMetricSet (config , entityTypeHost , entityName , uuid )
33
+ ms , err := createNewEntityWithMetricSet (config , entityTypeHost , entityName , uuid )
34
+ if err != nil {
35
+ config .Logrus .WithError (err ).WithField ("hostName" , entityName ).WithField ("uuid" , uuid ).Error ("failed to create metricSet" )
36
+ continue
37
+ }
30
38
31
39
if cluster , ok := dc .Clusters [host .Parent .Reference ()]; ok {
32
40
checkError (config , ms .SetMetric ("clusterName" , cluster .Name , metric .ATTRIBUTE ))
@@ -52,7 +60,6 @@ func createHostSamples(config *load.Config) {
52
60
checkError (config , ms .SetMetric ("datacenterLocation" , config .Args .DatacenterLocation , metric .ATTRIBUTE ))
53
61
}
54
62
checkError (config , ms .SetMetric ("hypervisorHostname" , hostConfigName , metric .ATTRIBUTE ))
55
- checkError (config , ms .SetMetric ("uuid" , host .Summary .Hardware .Uuid , metric .ATTRIBUTE ))
56
63
57
64
checkError (config , ms .SetMetric ("vmCount" , len (host .Vm ), metric .GAUGE ))
58
65
@@ -74,6 +81,8 @@ func createHostSamples(config *load.Config) {
74
81
}
75
82
checkError (config , ms .SetMetric ("networkNameList" , networkList , metric .ATTRIBUTE ))
76
83
84
+ checkError (config , ms .SetMetric ("uuid" , host .Summary .Hardware .Uuid , metric .ATTRIBUTE ))
85
+
77
86
// memory
78
87
memoryTotal := host .Summary .Hardware .MemorySize / (1 << 20 )
79
88
checkError (config , ms .SetMetric ("mem.size" , memoryTotal , metric .GAUGE ))
@@ -97,8 +106,11 @@ func createHostSamples(config *load.Config) {
97
106
TotalMHz := float64 (CPUMhz ) * float64 (CPUCores )
98
107
checkError (config , ms .SetMetric ("cpu.totalMHz" , TotalMHz , metric .GAUGE ))
99
108
100
- cpuPercent := (float64 (host .Summary .QuickStats .OverallCpuUsage ) / TotalMHz ) * 100
101
- checkError (config , ms .SetMetric ("cpu.percent" , cpuPercent , metric .GAUGE ))
109
+ if TotalMHz != 0 {
110
+ cpuPercent := (float64 (host .Summary .QuickStats .OverallCpuUsage ) / TotalMHz ) * 100
111
+ checkError (config , ms .SetMetric ("cpu.percent" , cpuPercent , metric .GAUGE ))
112
+ }
113
+
102
114
checkError (config , ms .SetMetric ("cpu.overallUsage" , host .Summary .QuickStats .OverallCpuUsage , metric .GAUGE ))
103
115
104
116
CPUAvailable := TotalMHz - float64 (host .Summary .QuickStats .OverallCpuUsage )
@@ -109,8 +121,10 @@ func createHostSamples(config *load.Config) {
109
121
if host .Config != nil {
110
122
if host .Config .FileSystemVolume != nil {
111
123
for _ , mount := range host .Config .FileSystemVolume .MountInfo {
112
- capacity := mount .Volume .GetHostFileSystemVolume ().Capacity
113
- diskTotalMiB += capacity / (1 << 20 )
124
+ hostFileSystemVolume := mount .Volume .GetHostFileSystemVolume ()
125
+ if hostFileSystemVolume != nil {
126
+ diskTotalMiB += hostFileSystemVolume .Capacity / (1 << 20 )
127
+ }
114
128
}
115
129
}
116
130
}
0 commit comments