6
6
"sync"
7
7
8
8
"github.com/apex/log"
9
+ "github.com/jenningsloy318/redfish_exporter/common"
9
10
"github.com/prometheus/client_golang/prometheus"
10
- "github.com/stmcginnis/gofish"
11
11
"github.com/stmcginnis/gofish/redfish"
12
12
)
13
13
34
34
35
35
// SystemCollector implements the prometheus.Collector.
36
36
type SystemCollector struct {
37
- redfishClient * gofish.APIClient
38
- metrics map [string ]Metric
39
- disabledMetrics []string
40
- collectLogs bool
37
+ Ctx * common.CollectionContext
38
+ metrics map [string ]Metric
41
39
prometheus.Collector
42
40
collectorScrapeStatus * prometheus.GaugeVec
43
41
Log * log.Entry
@@ -103,12 +101,10 @@ func createSystemMetricMap() map[string]Metric {
103
101
}
104
102
105
103
// NewSystemCollector returns a collector that collecting memory statistics
106
- func NewSystemCollector (redfishClient * gofish. APIClient , collectLogs bool , disabledMetrics [] string , logger * log.Entry ) * SystemCollector {
104
+ func NewSystemCollector (ctx * common. CollectionContext , logger * log.Entry ) * SystemCollector {
107
105
return & SystemCollector {
108
- redfishClient : redfishClient ,
109
- metrics : systemMetrics ,
110
- disabledMetrics : disabledMetrics ,
111
- collectLogs : collectLogs ,
106
+ metrics : systemMetrics ,
107
+ Ctx : ctx ,
112
108
Log : logger .WithFields (log.Fields {
113
109
"collector" : "SystemCollector" ,
114
110
}),
@@ -134,10 +130,10 @@ func (s *SystemCollector) Describe(ch chan<- *prometheus.Desc) {
134
130
// Collect implements prometheus.Collector.
135
131
func (s * SystemCollector ) Collect (ch chan <- prometheus.Metric ) {
136
132
collectorLogContext := s .Log
137
- collectLogs := s .collectLogs
138
- disabledMetrics := s .disabledMetrics
133
+ disabledMetrics := s .Ctx . DisabledMetrics
134
+ collectLogs := s .Ctx . CollectLogs
139
135
//get service
140
- service := s .redfishClient .Service
136
+ service := s .Ctx . RedfishClient .Service
141
137
142
138
// get a list of systems from service
143
139
if systems , err := service .Systems (); err != nil {
@@ -242,7 +238,7 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
242
238
wg10 .Add (len (logServices ))
243
239
244
240
for _ , logService := range logServices {
245
- if err = parseLogService (ch , systemMetrics , SystemSubsystem , SystemID , logService , wg10 ); err != nil {
241
+ if err = parseLogService (ch , systemMetrics , s . Ctx , systemLogContext , SystemSubsystem , SystemID , logService , wg10 ); err != nil {
246
242
systemLogContext .WithField ("operation" , "system.LogServices()" ).WithError (err ).Error ("error getting log entries from log service" )
247
243
}
248
244
}
0 commit comments