Skip to content

Commit 6c51bfa

Browse files
committed
feat: add log service metrics
1 parent 2b05def commit 6c51bfa

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed

collector/chassis_collector.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ var (
2525
ChassisNetworkPortLabelNames = []string{"resource", "chassis_id", "network_adapter", "network_adapter_id", "network_port", "network_port_id", "network_port_type", "network_port_speed", "network_port_connectiont_type", "network_physical_port_number"}
2626
ChassisPhysicalSecurityLabelNames = []string{"resource", "chassis_id", "intrusion_sensor_number", "intrusion_sensor_rearm"}
2727

28+
ChassisLogServiceLabelNames = []string{"chassis_id", "log_service", "log_service_id", "log_service_enabled", "log_service_overwrite_policy"}
29+
ChassisLogEntryLabelNames = []string{"chassis_id", "log_service", "log_service_id", "log_entry", "log_entry_id", "log_entry_code", "log_entry_type", "log_entry_message_id", "log_entry_sensor_number", "log_entry_sensor_type"}
30+
2831
chassisMetrics = createChassisMetricMap()
2932
)
3033

@@ -78,6 +81,10 @@ func createChassisMetricMap() map[string]Metric {
7881
addToMetricMap(chassisMetrics, ChassisSubsystem, "network_port_link_state", fmt.Sprintf("chassis network port link state state,%s", CommonPortLinkHelp), ChassisNetworkPortLabelNames)
7982
addToMetricMap(chassisMetrics, ChassisSubsystem, "physical_security_sensor_state", fmt.Sprintf("indicates the known state of the physical security sensor, such as if it is hardware intrusion detected,%s", CommonIntrusionSensorHelp), ChassisPhysicalSecurityLabelNames)
8083

84+
addToMetricMap(chassisMetrics, ChassisSubsystem, "log_service_state", fmt.Sprintf("chassis log service state,%s", CommonStateHelp), ChassisLogServiceLabelNames)
85+
addToMetricMap(chassisMetrics, ChassisSubsystem, "log_service_health_state", fmt.Sprintf("chassis log service health state,%s", CommonHealthHelp), ChassisLogServiceLabelNames)
86+
addToMetricMap(chassisMetrics, ChassisSubsystem, "log_entry_severity_state", fmt.Sprintf("chassis log entry severity state,%s", CommonSeverityHelp), ChassisLogEntryLabelNames)
87+
8188
return chassisMetrics
8289
}
8390

@@ -229,6 +236,22 @@ func (c *ChassisCollector) Collect(ch chan<- prometheus.Metric) {
229236
}
230237
}
231238

239+
// process log services
240+
logServices, err := chassis.LogServices()
241+
if err != nil {
242+
chassisLogContext.WithField("operation", "chassis.LogServices()").WithError(err).Error("error getting log services from chassis")
243+
} else if logServices == nil {
244+
chassisLogContext.WithField("operation", "chassis.LogServices()").Info("no log services found")
245+
} else {
246+
wg6 := &sync.WaitGroup{}
247+
wg6.Add(len(logServices))
248+
249+
for _, logService := range logServices {
250+
if err = parseLogService(ch, chassisMetrics, ChassisSubsystem, chassisID, logService, wg6); err != nil {
251+
chassisLogContext.WithField("operation", "chassis.LogServices()").WithError(err).Error("error getting log entries from log service")
252+
}
253+
}
254+
}
232255
chassisLogContext.Info("collector scrape completed")
233256
}
234257
}

collector/common_collector.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package collector
22

33
import (
44
"fmt"
5+
"sync"
56

67
"github.com/prometheus/client_golang/prometheus"
8+
"github.com/stmcginnis/gofish/redfish"
79
)
810

911
const (
@@ -30,3 +32,51 @@ func addToMetricMap(metricMap map[string]Metric, subsystem, name, help string, v
3032
),
3133
}
3234
}
35+
36+
func parseLogService(ch chan<- prometheus.Metric, metrics map[string]Metric, subsystem, collectorID string, logService *redfish.LogService, wg *sync.WaitGroup) (err error) {
37+
defer wg.Done()
38+
logServiceName := logService.Name
39+
logServiceID := logService.ID
40+
logServiceEnabled := fmt.Sprintf("%t", logService.ServiceEnabled)
41+
logServiceOverWritePolicy := string(logService.OverWritePolicy)
42+
logServiceState := logService.Status.State
43+
logServiceHealthState := logService.Status.Health
44+
45+
logServiceLabelValues := []string{collectorID, logServiceName, logServiceID, logServiceEnabled, logServiceOverWritePolicy}
46+
47+
if logServiceStateValue, ok := parseCommonStatusState(logServiceState); ok {
48+
ch <- prometheus.MustNewConstMetric(metrics[fmt.Sprintf("%s_%s", subsystem, "log_service_state")].desc, prometheus.GaugeValue, logServiceStateValue, logServiceLabelValues...)
49+
}
50+
if logServiceHealthStateValue, ok := parseCommonStatusHealth(logServiceHealthState); ok {
51+
ch <- prometheus.MustNewConstMetric(metrics[fmt.Sprintf("%s_%s", subsystem, "log_service_health_state")].desc, prometheus.GaugeValue, logServiceHealthStateValue, logServiceLabelValues...)
52+
}
53+
54+
logEntries, err := logService.Entries()
55+
if err != nil {
56+
return
57+
}
58+
wg2 := &sync.WaitGroup{}
59+
wg2.Add(len(logEntries))
60+
for _, logEntry := range logEntries {
61+
go parseLogEntry(ch, metrics[fmt.Sprintf("%s_%s", subsystem, "log_entry_severity_state")].desc, collectorID, logServiceName, logServiceID, logEntry, wg2)
62+
}
63+
return
64+
}
65+
66+
func parseLogEntry(ch chan<- prometheus.Metric, desc *prometheus.Desc, collectorID, logServiceName, logServiceID string, logEntry *redfish.LogEntry, wg *sync.WaitGroup) {
67+
defer wg.Done()
68+
logEntryName := logEntry.Name
69+
logEntryID := logEntry.ID
70+
logEntryCode := string(logEntry.EntryCode)
71+
logEntryType := string(logEntry.EntryType)
72+
logEntryMessageID := logEntry.MessageID
73+
logEntrySensorNumber := fmt.Sprintf("%d", logEntry.SensorNumber)
74+
logEntrySensorType := string(logEntry.SensorType)
75+
logEntrySeverityState := logEntry.Severity
76+
77+
logEntryLabelValues := []string{collectorID, logServiceName, logServiceID, logEntryName, logEntryID, logEntryCode, logEntryType, logEntryMessageID, logEntrySensorNumber, logEntrySensorType}
78+
79+
if logEntrySeverityStateValue, ok := parseCommonSeverityState(logEntrySeverityState); ok {
80+
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, logEntrySeverityStateValue, logEntryLabelValues...)
81+
}
82+
}

collector/manager_collector.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package collector
22

33
import (
44
"fmt"
5+
"sync"
56

67
"github.com/apex/log"
78
"github.com/prometheus/client_golang/prometheus"
@@ -13,6 +14,9 @@ var (
1314
ManagerSubmanager = "manager"
1415
ManagerLabelNames = []string{"manager_id", "name", "model", "type"}
1516

17+
ManagerLogServiceLabelNames = []string{"manager_id", "log_service", "log_service_id", "log_service_enabled", "log_service_overwrite_policy"}
18+
ManagerLogEntryLabelNames = []string{"manager_id", "log_service", "log_service_id", "log_entry", "log_entry_id", "log_entry_code", "log_entry_type", "log_entry_message_id", "log_entry_sensor_number", "log_entry_sensor_type"}
19+
1620
managerMetrics = createManagerMetricMap()
1721
)
1822

@@ -30,6 +34,10 @@ func createManagerMetricMap() map[string]Metric {
3034
addToMetricMap(managerMetrics, ManagerSubmanager, "health_state", fmt.Sprintf("manager health,%s", CommonHealthHelp), ManagerLabelNames)
3135
addToMetricMap(managerMetrics, ManagerSubmanager, "power_state", "manager power state", ManagerLabelNames)
3236

37+
addToMetricMap(managerMetrics, ManagerSubmanager, "log_service_state", fmt.Sprintf("manager log service state,%s", CommonStateHelp), ManagerLogServiceLabelNames)
38+
addToMetricMap(managerMetrics, ManagerSubmanager, "log_service_health_state", fmt.Sprintf("manager log service health state,%s", CommonHealthHelp), ManagerLogServiceLabelNames)
39+
addToMetricMap(managerMetrics, ManagerSubmanager, "log_entry_severity_state", fmt.Sprintf("manager log entry severity state,%s", CommonSeverityHelp), ManagerLogEntryLabelNames)
40+
3341
return managerMetrics
3442
}
3543

@@ -93,7 +101,23 @@ func (m *ManagerCollector) Collect(ch chan<- prometheus.Metric) {
93101
}
94102
if managerPowerStateValue, ok := parseCommonPowerState(managerPowerState); ok {
95103
ch <- prometheus.MustNewConstMetric(m.metrics["manager_power_state"].desc, prometheus.GaugeValue, managerPowerStateValue, ManagerLabelValues...)
104+
}
96105

106+
// process log services
107+
logServices, err := manager.LogServices()
108+
if err != nil {
109+
managerLogContext.WithField("operation", "manager.LogServices()").WithError(err).Error("error getting log services from manager")
110+
} else if logServices == nil {
111+
managerLogContext.WithField("operation", "manager.LogServices()").Info("no log services found")
112+
} else {
113+
wg := &sync.WaitGroup{}
114+
wg.Add(len(logServices))
115+
116+
for _, logService := range logServices {
117+
if err = parseLogService(ch, managerMetrics, ManagerSubmanager, ManagerID, logService, wg); err != nil {
118+
managerLogContext.WithField("operation", "manager.LogServices()").WithError(err).Error("error getting log entries from log service")
119+
}
120+
}
97121
}
98122

99123
managerLogContext.Info("collector scrape completed")

collector/redfish_collector.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ func parseCommonStatusState(status gofishcommon.State) (float64, bool) {
159159
return float64(0), false
160160
}
161161

162+
func parseCommonSeverityState(severity redfish.EventSeverity) (float64, bool) {
163+
if bytes.Equal([]byte(severity), []byte("OK")) {
164+
return float64(1), true
165+
} else if bytes.Equal([]byte(severity), []byte("Warning")) {
166+
return float64(2), true
167+
} else if bytes.Equal([]byte(severity), []byte("Critical")) {
168+
return float64(3), true
169+
}
170+
return float64(0), false
171+
}
172+
162173
func parseCommonPowerState(status redfish.PowerState) (float64, bool) {
163174
if bytes.Equal([]byte(status), []byte("On")) {
164175
return float64(1), true

collector/system_collector.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ var (
2525
SystemEthernetInterfaceLabelNames = []string{"hostname", "resource", "ethernet_interface", "ethernet_interface_id", "ethernet_interface_speed"}
2626
SystemPCIeFunctionLabelNames = []string{"hostname", "resource", "pcie_function_name", "pcie_function_id", "pci_function_deviceclass", "pci_function_type"}
2727

28+
SystemLogServiceLabelNames = []string{"system_id", "log_service", "log_service_id", "log_service_enabled", "log_service_overwrite_policy"}
29+
SystemLogEntryLabelNames = []string{"system_id", "log_service", "log_service_id", "log_entry", "log_entry_id", "log_entry_code", "log_entry_type", "log_entry_message_id", "log_entry_sensor_number", "log_entry_sensor_type"}
30+
2831
systemMetrics = createSystemMetricMap()
2932
)
3033

@@ -89,6 +92,10 @@ func createSystemMetricMap() map[string]Metric {
8992
addToMetricMap(systemMetrics, SystemSubsystem, "ethernet_interface_link_status", fmt.Sprintf("system ethernet interface link status,%s", CommonLinkHelp), SystemEthernetInterfaceLabelNames)
9093
addToMetricMap(systemMetrics, SystemSubsystem, "ethernet_interface_link_enabled", "system ethernet interface if the link is enabled", SystemEthernetInterfaceLabelNames)
9194

95+
addToMetricMap(systemMetrics, SystemSubsystem, "log_service_state", fmt.Sprintf("system log service state,%s", CommonStateHelp), SystemLogServiceLabelNames)
96+
addToMetricMap(systemMetrics, SystemSubsystem, "log_service_health_state", fmt.Sprintf("system log service health state,%s", CommonHealthHelp), SystemLogServiceLabelNames)
97+
addToMetricMap(systemMetrics, SystemSubsystem, "log_entry_severity_state", fmt.Sprintf("system log entry severity state,%s", CommonSeverityHelp), SystemLogEntryLabelNames)
98+
9299
return systemMetrics
93100
}
94101

@@ -348,6 +355,23 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
348355
}
349356
}
350357

358+
// process log services
359+
logServices, err := system.LogServices()
360+
if err != nil {
361+
systemLogContext.WithField("operation", "system.LogServices()").WithError(err).Error("error getting log services from system")
362+
} else if logServices == nil {
363+
systemLogContext.WithField("operation", "system.LogServices()").Info("no log services found")
364+
} else {
365+
wg10 := &sync.WaitGroup{}
366+
wg10.Add(len(logServices))
367+
368+
for _, logService := range logServices {
369+
if err = parseLogService(ch, systemMetrics, SystemSubsystem, SystemID, logService, wg10); err != nil {
370+
systemLogContext.WithField("operation", "system.LogServices()").WithError(err).Error("error getting log entries from log service")
371+
}
372+
}
373+
}
374+
351375
systemLogContext.Info("collector scrape completed")
352376
}
353377
s.collectorScrapeStatus.WithLabelValues("system").Set(float64(1))

0 commit comments

Comments
 (0)