-
Notifications
You must be signed in to change notification settings - Fork 62
/
chassis_collector.go
executable file
·435 lines (389 loc) · 19.5 KB
/
chassis_collector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
package collector
import (
"fmt"
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/stmcginnis/gofish"
"github.com/stmcginnis/gofish/redfish"
)
// A ChassisCollector implements the prometheus.Collector.
var (
ChassisSubsystem = "chassis"
ChassisLabelNames = []string{"resource", "chassis_id"}
ChassisTemperatureLabelNames = []string{"resource", "chassis_id", "sensor", "sensor_id"}
ChassisFanLabelNames = []string{"resource", "chassis_id", "fan", "fan_id"}
ChassisPowerVotageLabelNames = []string{"resource", "chassis_id", "power_votage", "power_votage_id"}
ChassisPowerSupplyLabelNames = []string{"resource", "chassis_id", "power_supply", "power_supply_id"}
ChassisNetworkAdapterLabelNames = []string{"resource", "chassis_id", "network_adapter", "network_adapter_id"}
ChassisNetworkPortLabelNames = []string{"resource", "chassis_id", "network_adapter", "network_adapter_id", "network_port", "network_port_id", "network_port_type", "network_port_speed"}
chassisMetrics = map[string]chassisMetric{
"chassis_health": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "health"),
"health of chassis, 1(OK),2(Warning),3(Critical)",
ChassisLabelNames,
nil,
),
},
"chassis_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "state"),
"state of chassis,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisLabelNames,
nil,
),
},
"chassis_temperature_sensor_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "temperature_sensor_state"),
"status state of temperature on this chassis component,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisTemperatureLabelNames,
nil,
),
},
"chassis_temperature_celsius": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "temperature_celsius"),
"celsius of temperature on this chassis component",
ChassisTemperatureLabelNames,
nil,
),
},
"chassis_fan_health": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "fan_health"),
"fan health on this chassis component,1(OK),2(Warning),3(Critical)",
ChassisFanLabelNames,
nil,
),
},
"chassis_fan_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "fan_state"),
"fan state on this chassis component,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisFanLabelNames,
nil,
),
},
"chassis_fan_rpm": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "fan_rpm_percentage"),
"fan rpm percentage on this chassis component",
ChassisFanLabelNames,
nil,
),
},
"chassis_power_voltage_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_voltage_state"),
"power voltage state of chassis component,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisPowerVotageLabelNames,
nil,
),
},
"chassis_power_voltage_volts": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_voltage_volts"),
"power voltage volts number of chassis component",
ChassisPowerVotageLabelNames,
nil,
),
},
"chassis_power_average_consumed_watts": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_average_consumed_watts"),
"power wattage watts number of chassis component",
ChassisPowerVotageLabelNames,
nil,
),
},
"chassis_power_powersupply_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_powersupply_state"),
"powersupply state of chassis component,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisPowerSupplyLabelNames,
nil,
),
},
"chassis_power_powersupply_health": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_powersupply_health"),
"powersupply health of chassis component,1(OK),2(Warning),3(Critical)",
ChassisPowerSupplyLabelNames,
nil,
),
},
"chassis_power_powersupply_last_power_output_watts": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_powersupply_last_power_output_watts"),
"last_power_output_watts of powersupply on this chassis",
ChassisPowerSupplyLabelNames,
nil,
),
},
"chassis_power_powersupply_power_capacity_watts": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "power_powersupply_power_capacity_watts"),
"power_capacity_watts of powersupply on this chassis",
ChassisPowerSupplyLabelNames,
nil,
),
},
"chassis_network_adapter_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "network_adapter_state"),
"chassis network adapter state,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisNetworkAdapterLabelNames,
nil,
),
},
"chassis_network_adapter_health_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "network_adapter_health_state"),
"chassis network adapter health state,1(OK),2(Warning),3(Critical)",
ChassisNetworkAdapterLabelNames,
nil,
),
},
"chassis_network_port_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "network_port_state"),
"chassis network port state state,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)",
ChassisNetworkPortLabelNames,
nil,
),
},
"chassis_network_port_health_state": {
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, ChassisSubsystem, "network_port_health_state"),
"chassis network port state state,1(OK),2(Warning),3(Critical)",
ChassisNetworkPortLabelNames,
nil,
),
},
}
)
type ChassisCollector struct {
redfishClient *gofish.APIClient
metrics map[string]chassisMetric
collectorScrapeStatus *prometheus.GaugeVec
}
type chassisMetric struct {
desc *prometheus.Desc
}
// NewChassisCollector returns a collector that collecting chassis statistics
func NewChassisCollector(namespace string, redfishClient *gofish.APIClient) *ChassisCollector {
// get service from redfish client
return &ChassisCollector{
redfishClient: redfishClient,
metrics: chassisMetrics,
collectorScrapeStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "collector_scrape_status",
Help: "collector_scrape_status",
},
[]string{"collector"},
),
}
}
func (c *ChassisCollector) Describe(ch chan<- *prometheus.Desc) {
for _, metric := range c.metrics {
ch <- metric.desc
}
c.collectorScrapeStatus.Describe(ch)
}
func (c *ChassisCollector) Collect(ch chan<- prometheus.Metric) {
service := c.redfishClient.Service
// get a list of chassis from service
if chassises, err := service.Chassis(); err != nil {
log.Infof("Errors Getting chassis from service : %s", err)
} else {
// process the chassises
for _, chassis := range chassises {
chassisID := chassis.ID
chassisStatus := chassis.Status
chassisStatusState := chassisStatus.State
chassisStatusHealth := chassisStatus.Health
ChassisLabelValues := []string{"chassis", chassisID}
if chassisStatusHealthValue, ok := parseCommonStatusHealth(chassisStatusHealth); ok {
ch <- prometheus.MustNewConstMetric(c.metrics["chassis_health"].desc, prometheus.GaugeValue, chassisStatusHealthValue, ChassisLabelValues...)
}
if chassisStatusStateValue, ok := parseCommonStatusState(chassisStatusState); ok {
ch <- prometheus.MustNewConstMetric(c.metrics["chassis_state"].desc, prometheus.GaugeValue, chassisStatusStateValue, ChassisLabelValues...)
}
chassisThermal, err := chassis.Thermal()
if err != nil {
log.Infof("Errors Getting Thermal from chassis, error is : %s ", err)
} else if chassisThermal == nil {
log.Info("Errors Getting Thermal from chassis, no Thermal data found")
} else {
// process temperature
chassisTemperatures := chassisThermal.Temperatures
wg := &sync.WaitGroup{}
wg.Add(len(chassisTemperatures))
for _, chassisTemperature := range chassisTemperatures {
go parseChassisTemperature(ch, chassisID, chassisTemperature, wg)
}
// process fans
chassisFans := chassisThermal.Fans
wg2 := &sync.WaitGroup{}
wg2.Add(len(chassisFans))
for _, chassisFan := range chassisFans {
go parseChassisFan(ch, chassisID, chassisFan, wg2)
}
}
chassisPowerInfo, err := chassis.Power()
if err != nil {
log.Infof("Errors Getting powerinfo from chassis : %s", err)
} else if chassisPowerInfo == nil {
log.Info("Errors Getting powerinfo from chassis, no powerinfo found")
} else {
// power votages
chassisPowerInfoVoltages := chassisPowerInfo.Voltages
wg3 := &sync.WaitGroup{}
wg3.Add(len(chassisPowerInfoVoltages))
for _, chassisPowerInfoVoltage := range chassisPowerInfoVoltages {
go parseChassisPowerInfoVoltage(ch, chassisID, chassisPowerInfoVoltage, wg3)
}
// power control
chassisPowerInfoPowerControls := chassisPowerInfo.PowerControl
wg4 := &sync.WaitGroup{}
wg4.Add(len(chassisPowerInfoPowerControls))
for _, chassisPowerInfoPowerControl := range chassisPowerInfoPowerControls {
go parseChassisPowerInfoPowerControl(ch, chassisID, chassisPowerInfoPowerControl, wg4)
}
// powerSupply
chassisPowerInfoPowerSupplies := chassisPowerInfo.PowerSupplies
wg5 := &sync.WaitGroup{}
wg5.Add(len(chassisPowerInfoPowerSupplies))
for _, chassisPowerInfoPowerSupply := range chassisPowerInfoPowerSupplies {
go parseChassisPowerInfoPowerSupply(ch, chassisID, chassisPowerInfoPowerSupply, wg5)
}
}
// process NetapAdapter
if networkAdapters, err := chassis.NetworkAdapters(); err != nil {
log.Infof("Errors Getting NetworkAdapters from chassis : %s", err)
} else {
wg5 := &sync.WaitGroup{}
wg5.Add(len(networkAdapters))
for _, networkAdapter := range networkAdapters {
go parseNetworkAdapter(ch, chassisID, networkAdapter, wg5)
}
}
}
}
c.collectorScrapeStatus.WithLabelValues("chassis").Set(float64(1))
}
func parseChassisTemperature(ch chan<- prometheus.Metric, chassisID string, chassisTemperature redfish.Temperature, wg *sync.WaitGroup) {
defer wg.Done()
chassisTemperatureSensorName := chassisTemperature.Name
chassisTemperatureSensorID := chassisTemperature.MemberID
chassisTemperatureStatus := chassisTemperature.Status
// chassisTemperatureStatusHealth :=chassisTemperatureStatus.Health
chassisTemperatureStatusState := chassisTemperatureStatus.State
// chassisTemperatureStatusLabelNames :=[]string{BaseLabelNames,"temperature_sensor_name","temperature_sensor_member_id")
chassisTemperatureLabelvalues := []string{"temperature", chassisID, chassisTemperatureSensorName, chassisTemperatureSensorID}
// ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_temperature_status_health"].desc, prometheus.GaugeValue, parseCommonStatusHealth(chassisTemperatureStatusHealth), chassisTemperatureLabelvalues...)
if chassisTemperatureStatusStateValue, ok := parseCommonStatusState(chassisTemperatureStatusState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_temperature_sensor_state"].desc, prometheus.GaugeValue, chassisTemperatureStatusStateValue, chassisTemperatureLabelvalues...)
}
chassisTemperatureReadingCelsius := chassisTemperature.ReadingCelsius
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_temperature_celsius"].desc, prometheus.GaugeValue, float64(chassisTemperatureReadingCelsius), chassisTemperatureLabelvalues...)
}
func parseChassisFan(ch chan<- prometheus.Metric, chassisID string, chassisFan redfish.Fan, wg *sync.WaitGroup) {
defer wg.Done()
chassisFanID := chassisFan.MemberID
chassisFanName := chassisFan.Name
chassisFanStaus := chassisFan.Status
chassisFanStausHealth := chassisFanStaus.Health
chassisFanStausState := chassisFanStaus.State
chassisFanRPM := chassisFan.Reading
// chassisFanStatusLabelNames :=[]string{BaseLabelNames,"fan_name","fan_member_id")
chassisFanLabelvalues := []string{"fan", chassisID, chassisFanName, chassisFanID}
if chassisFanStausHealthValue, ok := parseCommonStatusHealth(chassisFanStausHealth); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_fan_health"].desc, prometheus.GaugeValue, chassisFanStausHealthValue, chassisFanLabelvalues...)
}
if chassisFanStausStateValue, ok := parseCommonStatusState(chassisFanStausState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_fan_state"].desc, prometheus.GaugeValue, chassisFanStausStateValue, chassisFanLabelvalues...)
}
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_fan_rpm"].desc, prometheus.GaugeValue, float64(chassisFanRPM), chassisFanLabelvalues...)
}
func parseChassisPowerInfoVoltage(ch chan<- prometheus.Metric, chassisID string, chassisPowerInfoVoltage redfish.Voltage, wg *sync.WaitGroup) {
defer wg.Done()
chassisPowerInfoVoltageName := chassisPowerInfoVoltage.Name
chassisPowerInfoVoltageID := chassisPowerInfoVoltage.MemberID
chassisPowerInfoVoltageNameReadingVolts := chassisPowerInfoVoltage.ReadingVolts
chassisPowerInfoVoltageState := chassisPowerInfoVoltage.Status.State
chassisPowerVotageLabelvalues := []string{"power_voltage", chassisID, chassisPowerInfoVoltageName, chassisPowerInfoVoltageID}
if chassisPowerInfoVoltageStateValue, ok := parseCommonStatusState(chassisPowerInfoVoltageState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_voltage_state"].desc, prometheus.GaugeValue, chassisPowerInfoVoltageStateValue, chassisPowerVotageLabelvalues...)
}
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_voltage_volts"].desc, prometheus.GaugeValue, float64(chassisPowerInfoVoltageNameReadingVolts), chassisPowerVotageLabelvalues...)
}
func parseChassisPowerInfoPowerControl(ch chan<- prometheus.Metric, chassisID string, chassisPowerInfoPowerControl redfish.PowerControl, wg *sync.WaitGroup) {
defer wg.Done()
name := chassisPowerInfoPowerControl.Name
id := chassisPowerInfoPowerControl.MemberID
pm := chassisPowerInfoPowerControl.PowerMetrics
chassisPowerVotageLabelvalues := []string{"power_wattage", chassisID, name, id}
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_average_consumed_watts"].desc, prometheus.GaugeValue, float64(pm.AverageConsumedWatts), chassisPowerVotageLabelvalues...)
}
func parseChassisPowerInfoPowerSupply(ch chan<- prometheus.Metric, chassisID string, chassisPowerInfoPowerSupply redfish.PowerSupply, wg *sync.WaitGroup) {
defer wg.Done()
chassisPowerInfoPowerSupplyName := chassisPowerInfoPowerSupply.Name
chassisPowerInfoPowerSupplyID := chassisPowerInfoPowerSupply.MemberID
chassisPowerInfoPowerSupplyPowerCapacityWatts := chassisPowerInfoPowerSupply.PowerCapacityWatts
chassisPowerInfoPowerSupplyLastPowerOutputWatts := chassisPowerInfoPowerSupply.LastPowerOutputWatts
chassisPowerInfoPowerSupplyState := chassisPowerInfoPowerSupply.Status.State
chassisPowerInfoPowerSupplyHealth := chassisPowerInfoPowerSupply.Status.Health
chassisPowerSupplyLabelvalues := []string{"power_supply", chassisID, chassisPowerInfoPowerSupplyName, chassisPowerInfoPowerSupplyID}
if chassisPowerInfoPowerSupplyStateValue, ok := parseCommonStatusState(chassisPowerInfoPowerSupplyState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_powersupply_state"].desc, prometheus.GaugeValue, chassisPowerInfoPowerSupplyStateValue, chassisPowerSupplyLabelvalues...)
}
if chassisPowerInfoPowerSupplyHealthValue, ok := parseCommonStatusHealth(chassisPowerInfoPowerSupplyHealth); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_powersupply_health"].desc, prometheus.GaugeValue, chassisPowerInfoPowerSupplyHealthValue, chassisPowerSupplyLabelvalues...)
}
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_powersupply_last_power_output_watts"].desc, prometheus.GaugeValue, float64(chassisPowerInfoPowerSupplyLastPowerOutputWatts), chassisPowerSupplyLabelvalues...)
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_powersupply_power_capacity_watts"].desc, prometheus.GaugeValue, float64(chassisPowerInfoPowerSupplyPowerCapacityWatts), chassisPowerSupplyLabelvalues...)
}
func parseNetworkAdapter(ch chan<- prometheus.Metric, chassisID string, networkAdapter *redfish.NetworkAdapter, wg *sync.WaitGroup) {
defer wg.Done()
networkAdapterName := networkAdapter.Name
networkAdapterID := networkAdapter.ID
networkAdapterState := networkAdapter.Status.State
networkAdapterHealthState := networkAdapter.Status.Health
chassisNetworkAdapterLabelValues := []string{"network_adapter", chassisID, networkAdapterName, networkAdapterID}
if networkAdapterStateValue, ok := parseCommonStatusState(networkAdapterState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_network_adapter_state"].desc, prometheus.GaugeValue, networkAdapterStateValue, chassisNetworkAdapterLabelValues...)
}
if networkAdapterHealthStateValue, ok := parseCommonStatusHealth(networkAdapterHealthState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_network_adapter_health_state"].desc, prometheus.GaugeValue, networkAdapterHealthStateValue, chassisNetworkAdapterLabelValues...)
}
if networkPorts, err := networkAdapter.NetworkPorts(); err != nil {
log.Infof("Errors Getting Network port from networkAdapter : %s", err)
} else {
wg6 := &sync.WaitGroup{}
wg6.Add(len(networkPorts))
for _, networkPort := range networkPorts {
go parseNetworkPort(ch, chassisID, networkPort, networkAdapterName, networkAdapterID, wg6)
}
}
}
func parseNetworkPort(ch chan<- prometheus.Metric, chassisID string, networkPort *redfish.NetworkPort, networkAdapterName string, networkAdapterID string, wg *sync.WaitGroup) {
defer wg.Done()
networkPortName := networkPort.Name
networkPortID := networkPort.ID
networkPortState := networkPort.Status.State
networkPortLinkType := networkPort.ActiveLinkTechnology
networkPortLinkSpeed := fmt.Sprintf("%d Mbps", networkPort.CurrentLinkSpeedMbps)
networkPortHealthState := networkPort.Status.Health
chassisNetworkPortLabelValues := []string{"network_port", chassisID, networkAdapterName, networkAdapterID, networkPortName, networkPortID, string(networkPortLinkType), networkPortLinkSpeed}
if networkPortStateValue, ok := parseCommonStatusState(networkPortState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_network_port_state"].desc, prometheus.GaugeValue, networkPortStateValue, chassisNetworkPortLabelValues...)
}
if networkPortHealthStateValue, ok := parseCommonStatusHealth(networkPortHealthState); ok {
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_network_port_health_state"].desc, prometheus.GaugeValue, networkPortHealthStateValue, chassisNetworkPortLabelValues...)
}
}