Skip to content

Commit c1b860f

Browse files
Merge pull request jenningsloy318#68 from chiveturkey/fix-collector-panic
Fix "panic: send on closed channel"
2 parents e28371d + 36567a3 commit c1b860f

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

collector/chassis_collector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ func parseNetworkAdapter(ch chan<- prometheus.Metric, chassisID string, networkA
398398
for _, networkPort := range networkPorts {
399399
go parseNetworkPort(ch, chassisID, networkPort, networkAdapterName, networkAdapterID, wg6)
400400
}
401+
wg6.Wait()
401402
}
402403
return nil
403404
}

collector/system_collector.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
182182
// get system OdataID
183183
//systemOdataID := system.ODataID
184184

185+
wg1 := &sync.WaitGroup{}
186+
wg2 := &sync.WaitGroup{}
187+
wg3 := &sync.WaitGroup{}
188+
wg4 := &sync.WaitGroup{}
189+
wg5 := &sync.WaitGroup{}
190+
wg6 := &sync.WaitGroup{}
191+
wg7 := &sync.WaitGroup{}
192+
wg8 := &sync.WaitGroup{}
193+
wg9 := &sync.WaitGroup{}
194+
wg10 := &sync.WaitGroup{}
195+
185196
// process memory metrics
186197
// construct memory Link
187198
//memoriesLink := fmt.Sprintf("%sMemory/", systemOdataID)
@@ -193,7 +204,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
193204
} else if memories == nil {
194205
systemLogContext.WithField("operation", "system.Memory()").Info("no memory data found")
195206
} else {
196-
wg1 := &sync.WaitGroup{}
197207
wg1.Add(len(memories))
198208

199209
for _, memory := range memories {
@@ -212,7 +222,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
212222
} else if processors == nil {
213223
systemLogContext.WithField("operation", "system.Processors()").Info("no processor data found")
214224
} else {
215-
wg2 := &sync.WaitGroup{}
216225
wg2.Add(len(processors))
217226

218227
for _, processor := range processors {
@@ -235,7 +244,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
235244
if volumes, err := storage.Volumes(); err != nil {
236245
systemLogContext.WithField("operation", "system.Volumes()").WithError(err).Error("error getting storage data from system")
237246
} else {
238-
wg3 := &sync.WaitGroup{}
239247
wg3.Add(len(volumes))
240248

241249
for _, volume := range volumes {
@@ -249,7 +257,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
249257
} else if drives == nil {
250258
systemLogContext.WithFields(log.Fields{"operation": "system.Drives()", "storage": storage.ID}).Info("no drive data found")
251259
} else {
252-
wg4 := &sync.WaitGroup{}
253260
wg4.Add(len(drives))
254261
for _, drive := range drives {
255262
go parseDrive(ch, systemHostName, drive, wg4)
@@ -290,7 +297,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
290297
} else if pcieDevices == nil {
291298
systemLogContext.WithField("operation", "system.PCIeDevices()").Info("no PCI-E device data found")
292299
} else {
293-
wg5 := &sync.WaitGroup{}
294300
wg5.Add(len(pcieDevices))
295301
for _, pcieDevice := range pcieDevices {
296302
go parsePcieDevice(ch, systemHostName, pcieDevice, wg5)
@@ -304,7 +310,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
304310
} else if networkInterfaces == nil {
305311
systemLogContext.WithField("operation", "system.NetworkInterfaces()").Info("no network interface data found")
306312
} else {
307-
wg6 := &sync.WaitGroup{}
308313
wg6.Add(len(networkInterfaces))
309314
for _, networkInterface := range networkInterfaces {
310315
go parseNetworkInterface(ch, systemHostName, networkInterface, wg6)
@@ -318,7 +323,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
318323
} else if ethernetInterfaces == nil {
319324
systemLogContext.WithField("operation", "system.PCIeDevices()").Info("no ethernet interface data found")
320325
} else {
321-
wg7 := &sync.WaitGroup{}
322326
wg7.Add(len(ethernetInterfaces))
323327
for _, ethernetInterface := range ethernetInterfaces {
324328
go parseEthernetInterface(ch, systemHostName, ethernetInterface, wg7)
@@ -334,7 +338,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
334338
} else {
335339
for _, simpleStorage := range simpleStorages {
336340
devices := simpleStorage.Devices
337-
wg8 := &sync.WaitGroup{}
338341
wg8.Add(len(devices))
339342
for _, device := range devices {
340343
go parseDevice(ch, systemHostName, device, wg8)
@@ -348,7 +351,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
348351
} else if pcieFunctions == nil {
349352
systemLogContext.WithField("operation", "system.PCIeFunctions()").Info("no PCI-E device function data found")
350353
} else {
351-
wg9 := &sync.WaitGroup{}
352354
wg9.Add(len(pcieFunctions))
353355
for _, pcieFunction := range pcieFunctions {
354356
go parsePcieFunction(ch, systemHostName, pcieFunction, wg9)
@@ -362,7 +364,6 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
362364
} else if logServices == nil {
363365
systemLogContext.WithField("operation", "system.LogServices()").Info("no log services found")
364366
} else {
365-
wg10 := &sync.WaitGroup{}
366367
wg10.Add(len(logServices))
367368

368369
for _, logService := range logServices {
@@ -372,6 +373,17 @@ func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {
372373
}
373374
}
374375

376+
wg1.Wait()
377+
wg2.Wait()
378+
wg3.Wait()
379+
wg4.Wait()
380+
wg5.Wait()
381+
wg6.Wait()
382+
wg7.Wait()
383+
wg8.Wait()
384+
wg9.Wait()
385+
wg10.Wait()
386+
375387
systemLogContext.Info("collector scrape completed")
376388
}
377389
s.collectorScrapeStatus.WithLabelValues("system").Set(float64(1))

0 commit comments

Comments
 (0)