@@ -26,10 +26,12 @@ var (
26
26
SystemDeviceLabelNames = []string {"hostname" , "resource" , "device" }
27
27
SystemDriveLabelNames = []string {"hostname" , "resource" , "drive" , "drive_id" }
28
28
SystemStorageControllerLabelNames = []string {"hostname" , "resource" , "storage_controller" , "storage_controller_id" }
29
- SystemPCIeDeviceLabelNames = []string {"hostname" , "resource" , "pcie_device" , "pcie_device_id" , "pcie_device_partnumber" ,"pcie_device_type" ,"pcie_serial_number" }
29
+ SystemPCIeDeviceLabelNames = []string {"hostname" , "resource" , "pcie_device" , "pcie_device_id" , "pcie_device_partnumber" , "pcie_device_type" , "pcie_serial_number" }
30
30
SystemNetworkInterfaceLabelNames = []string {"hostname" , "resource" , "network_interface" , "network_interface_id" }
31
31
SystemEthernetInterfaceLabelNames = []string {"hostname" , "resource" , "ethernet_interface" , "ethernet_interface_id" , "ethernet_interface_speed" }
32
- systemMetrics = map [string ]systemMetric {
32
+ SystemPCIeFunctionLabelNames = []string {"hostname" , "resource" , "pcie_function_name" , "pcie_function_id" , "pci_function_deviceclass" , "pci_function_type" }
33
+
34
+ systemMetrics = map [string ]systemMetric {
33
35
"system_state" : {
34
36
desc : prometheus .NewDesc (
35
37
prometheus .BuildFQName (namespace , SystemSubsystem , "state" ),
@@ -255,6 +257,22 @@ var (
255
257
nil ,
256
258
),
257
259
},
260
+ "system_pcie_function_state" : {
261
+ desc : prometheus .NewDesc (
262
+ prometheus .BuildFQName (namespace , SystemSubsystem , "pcie_function_state" ),
263
+ "system pcie device state,1(Enabled),2(Disabled),3(StandbyOffinline),4(StandbySpare),5(InTest),6(Starting),7(Absent),8(UnavailableOffline),9(Deferring),10(Quiesced),11(Updating)" ,
264
+ SystemPCIeFunctionLabelNames ,
265
+ nil ,
266
+ ),
267
+ },
268
+ "system_pcie_function_health_state" : {
269
+ desc : prometheus .NewDesc (
270
+ prometheus .BuildFQName (namespace , SystemSubsystem , "pcie_function_health_state" ),
271
+ "system pcie device health state,1(OK),2(Warning),3(Critical)" ,
272
+ SystemPCIeFunctionLabelNames ,
273
+ nil ,
274
+ ),
275
+ },
258
276
"system_network_interface_state" : {
259
277
desc : prometheus .NewDesc (
260
278
prometheus .BuildFQName (namespace , SystemSubsystem , "network_interface_state" ),
@@ -536,7 +554,7 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
536
554
537
555
}
538
556
539
- //process nethernetinterfaces
557
+ //process ethernetinterfaces
540
558
ethernetInterfaces , err := system .EthernetInterfaces ()
541
559
if err != nil {
542
560
systemLogContext .WithField ("operation" , "system.EthernetInterfaces()" ).WithError (err ).Error ("error getting ethernet interface data from system" )
@@ -566,6 +584,19 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
566
584
}
567
585
}
568
586
}
587
+ //process pci functions
588
+ pcieFunctions , err := system .PCIeFunctions ()
589
+ if err != nil {
590
+ systemLogContext .WithField ("operation" , "system.PCIeFunctions()" ).WithError (err ).Error ("error getting PCI-E device function data from system" )
591
+ } else if pcieFunctions == nil {
592
+ systemLogContext .WithField ("operation" , "system.PCIeFunctions()" ).Info ("no PCI-E device function data found" )
593
+ } else {
594
+ wg9 := & sync.WaitGroup {}
595
+ wg9 .Add (len (pcieFunctions ))
596
+ for _ , pcieFunction := range pcieFunctions {
597
+ go parsePcieFunction (ch , systemHostName , pcieFunction , wg9 )
598
+ }
599
+ }
569
600
systemLogContext .Info ("collector scrape completed" )
570
601
}
571
602
s .collectorScrapeStatus .WithLabelValues ("system" ).Set (float64 (1 ))
@@ -674,9 +705,9 @@ func parsePcieDevice(ch chan<- prometheus.Metric, systemHostName string, pcieDev
674
705
pcieDeviceState := pcieDevice .Status .State
675
706
pcieDeviceHealthState := pcieDevice .Status .Health
676
707
pcieDevicePartNumber := pcieDevice .PartNumber
677
- pcieDeviceType := fmt .Sprintf ("%v," ,pcieDevice .DeviceType )
678
- pcieSerialNumber := pcieDevice .SerialNumber
679
- systemPCIeDeviceLabelValues := []string {systemHostName , "pcie_device" , pcieDeviceName , pcieDeviceID , pcieDevicePartNumber ,pcieDeviceType ,pcieSerialNumber }
708
+ pcieDeviceType := fmt .Sprintf ("%v," , pcieDevice .DeviceType )
709
+ pcieSerialNumber := pcieDevice .SerialNumber
710
+ systemPCIeDeviceLabelValues := []string {systemHostName , "pcie_device" , pcieDeviceName , pcieDeviceID , pcieDevicePartNumber , pcieDeviceType , pcieSerialNumber }
680
711
681
712
if pcieStateVaule , ok := parseCommonStatusState (pcieDeviceState ); ok {
682
713
ch <- prometheus .MustNewConstMetric (systemMetrics ["system_pcie_device_state" ].desc , prometheus .GaugeValue , pcieStateVaule , systemPCIeDeviceLabelValues ... )
@@ -734,3 +765,24 @@ func parseEthernetInterface(ch chan<- prometheus.Metric, systemHostName string,
734
765
ch <- prometheus .MustNewConstMetric (systemMetrics ["system_ethernet_interface_link_enabled" ].desc , prometheus .GaugeValue , boolToFloat64 (ethernetInterfaceEnabled ), systemEthernetInterfaceLabelValues ... )
735
766
736
767
}
768
+
769
+ func parsePcieFunction (ch chan <- prometheus.Metric , systemHostName string , pcieFunction * redfish.PCIeFunction , wg * sync.WaitGroup ) {
770
+
771
+ defer wg .Done ()
772
+ pcieFunctionName := pcieFunction .Name
773
+ pcieFunctionID := fmt .Sprint ("%v" , pcieFunction .ID )
774
+ pciFunctionDeviceclass := fmt .Sprintf ("%v" , pcieFunction .DeviceClass )
775
+ pciFunctionType := fmt .Sprintf ("%v" , pcieFunction .FunctionType )
776
+ pciFunctionState := pcieFunction .Status .State
777
+ pciFunctionHealthState := pcieFunction .Status .Health
778
+
779
+ systemPCIeFunctionLabelLabelValues := []string {systemHostName , "pcie_function" , pcieFunctionName , pcieFunctionID , pciFunctionDeviceclass , pciFunctionType }
780
+
781
+ if pciFunctionStateValue , ok := parseCommonStatusState (pciFunctionState ); ok {
782
+ ch <- prometheus .MustNewConstMetric (systemMetrics ["system_pcie_function_state" ].desc , prometheus .GaugeValue , pciFunctionStateValue , systemPCIeFunctionLabelLabelValues ... )
783
+ }
784
+
785
+ if pciFunctionHealthStateValue , ok := parseCommonStatusHealth (pciFunctionHealthState ); ok {
786
+ ch <- prometheus .MustNewConstMetric (systemMetrics ["system_pcie_function_health_state" ].desc , prometheus .GaugeValue , pciFunctionHealthStateValue , systemPCIeFunctionLabelLabelValues ... )
787
+ }
788
+ }
0 commit comments