Skip to content

Commit b9c0e57

Browse files
Merge pull request #38 from NETWAYS/psi_rework
Separate Full and Some Pressure and display them properly
2 parents 546f698 + 19f2349 commit b9c0e57

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

cmd/psi.go

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func init() {
237237
func checkPsiCPUPressure(config *psiConfig) result.PartialResult {
238238
var cpuCheck result.PartialResult
239239
_ = cpuCheck.SetDefaultState(check.OK)
240+
cpuCheck.Output = "CPU"
240241

241242
psiCPU, err := psi.ReadCPUPressure()
242243
if err != nil {
@@ -251,7 +252,6 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult {
251252
}
252253

253254
cpuCheck.Perfdata = *psiCPU.Perfdata()
254-
_ = cpuCheck.SetState(check.OK)
255255

256256
//nolint:nestif
257257
if psiCPU.FullPresent {
@@ -293,17 +293,23 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult {
293293
cpuCheck.Perfdata[psi.CPUFullAvg300].Crit = &config.CriticalCPUAvg.Th
294294
}
295295

296+
cpuFullSc := result.PartialResult{}
297+
_ = cpuFullSc.SetDefaultState(check.OK)
298+
296299
if cpuCheck.Perfdata[psi.CPUFullAvg10].Warn.DoesViolate(psiCPU.Full.Avg10) ||
297300
cpuCheck.Perfdata[psi.CPUFullAvg60].Warn.DoesViolate(psiCPU.Full.Avg60) ||
298301
cpuCheck.Perfdata[psi.CPUFullAvg300].Warn.DoesViolate(psiCPU.Full.Avg300) {
299-
_ = cpuCheck.SetState(check.Warning)
302+
_ = cpuFullSc.SetState(check.Warning)
300303
}
301304

302305
if cpuCheck.Perfdata[psi.CPUFullAvg10].Crit.DoesViolate(psiCPU.Full.Avg10) ||
303306
cpuCheck.Perfdata[psi.CPUFullAvg60].Crit.DoesViolate(psiCPU.Full.Avg60) ||
304307
cpuCheck.Perfdata[psi.CPUFullAvg300].Crit.DoesViolate(psiCPU.Full.Avg300) {
305-
_ = cpuCheck.SetState(check.Critical)
308+
_ = cpuFullSc.SetState(check.Critical)
306309
}
310+
311+
cpuFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Full.Avg10, psiCPU.Full.Avg60, psiCPU.Full.Avg300)
312+
cpuCheck.AddSubcheck(cpuFullSc)
307313
}
308314

309315
if config.WarningCPUSomeAvg10.IsSet {
@@ -343,34 +349,35 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult {
343349
cpuCheck.Perfdata[psi.CPUSomeAvg300].Crit = &config.CriticalCPUAvg.Th
344350
}
345351

352+
cpuSomeSc := result.PartialResult{}
353+
_ = cpuSomeSc.SetDefaultState(check.OK)
354+
346355
if (cpuCheck.GetStatus() != check.Critical) && (cpuCheck.GetStatus() != check.Warning) {
347356
if cpuCheck.Perfdata[psi.CPUSomeAvg10].Warn.DoesViolate(psiCPU.Some.Avg10) ||
348357
cpuCheck.Perfdata[psi.CPUSomeAvg60].Warn.DoesViolate(psiCPU.Some.Avg60) ||
349358
cpuCheck.Perfdata[psi.CPUSomeAvg300].Warn.DoesViolate(psiCPU.Some.Avg300) {
350-
_ = cpuCheck.SetState(check.Warning)
359+
_ = cpuSomeSc.SetState(check.Warning)
351360
}
352361
}
353362

354363
if cpuCheck.GetStatus() != check.Critical {
355364
if cpuCheck.Perfdata[psi.CPUSomeAvg10].Crit.DoesViolate(psiCPU.Some.Avg10) ||
356365
cpuCheck.Perfdata[psi.CPUSomeAvg60].Crit.DoesViolate(psiCPU.Some.Avg60) ||
357366
cpuCheck.Perfdata[psi.CPUSomeAvg300].Crit.DoesViolate(psiCPU.Some.Avg300) {
358-
_ = cpuCheck.SetState(check.Critical)
367+
_ = cpuSomeSc.SetState(check.Critical)
359368
}
360369
}
361370

362-
if psiCPU.FullPresent {
363-
cpuCheck.Output = fmt.Sprintf("CPU Full Pressure - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Full.Avg10, psiCPU.Full.Avg60, psiCPU.Full.Avg300)
364-
} else {
365-
cpuCheck.Output = fmt.Sprintf("CPU Some Pressure - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Some.Avg10, psiCPU.Some.Avg60, psiCPU.Some.Avg300)
366-
}
371+
cpuSomeSc.Output = fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Some.Avg10, psiCPU.Some.Avg60, psiCPU.Some.Avg300)
372+
cpuCheck.AddSubcheck(cpuSomeSc)
367373

368374
return cpuCheck
369375
}
370376

371377
func checkPsiIoPressure(config *psiConfig) result.PartialResult {
372378
var ioCheck result.PartialResult
373379
_ = ioCheck.SetDefaultState(check.OK)
380+
ioCheck.Output = "IO"
374381

375382
psiIo, err := psi.ReadIoPressure()
376383
if err != nil {
@@ -426,17 +433,23 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult {
426433
ioCheck.Perfdata[psi.IoFullAvg300].Crit = &config.CriticalIoAvg.Th
427434
}
428435

436+
ioFullSc := result.PartialResult{}
437+
_ = ioFullSc.SetDefaultState(check.OK)
438+
429439
if ioCheck.Perfdata[psi.IoFullAvg10].Warn.DoesViolate(psiIo.Full.Avg10) ||
430440
ioCheck.Perfdata[psi.IoFullAvg60].Warn.DoesViolate(psiIo.Full.Avg60) ||
431441
ioCheck.Perfdata[psi.IoFullAvg300].Warn.DoesViolate(psiIo.Full.Avg300) {
432-
_ = ioCheck.SetState(check.Warning)
442+
_ = ioFullSc.SetState(check.Warning)
433443
}
434444

435445
if ioCheck.Perfdata[psi.IoFullAvg10].Crit.DoesViolate(psiIo.Full.Avg10) ||
436446
ioCheck.Perfdata[psi.IoFullAvg60].Crit.DoesViolate(psiIo.Full.Avg60) ||
437447
ioCheck.Perfdata[psi.IoFullAvg300].Crit.DoesViolate(psiIo.Full.Avg300) {
438-
_ = ioCheck.SetState(check.Critical)
448+
_ = ioFullSc.SetState(check.Critical)
439449
}
450+
451+
ioFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Full.Avg10, psiIo.Full.Avg60, psiIo.Full.Avg300)
452+
ioCheck.AddSubcheck(ioFullSc)
440453
}
441454

442455
if config.WarningIoSomeAvg10.IsSet {
@@ -475,30 +488,35 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult {
475488
ioCheck.Perfdata[psi.IoSomeAvg300].Crit = &config.CriticalIoAvg.Th
476489
}
477490

491+
ioSomeSc := result.PartialResult{}
492+
_ = ioSomeSc.SetDefaultState(check.OK)
493+
478494
if (ioCheck.GetStatus() != check.Critical) && (ioCheck.GetStatus() != check.Warning) {
479495
if ioCheck.Perfdata[psi.IoSomeAvg10].Warn.DoesViolate(psiIo.Some.Avg10) ||
480496
ioCheck.Perfdata[psi.IoSomeAvg60].Warn.DoesViolate(psiIo.Some.Avg60) ||
481497
ioCheck.Perfdata[psi.IoSomeAvg300].Warn.DoesViolate(psiIo.Some.Avg300) {
482-
_ = ioCheck.SetState(check.Warning)
498+
_ = ioSomeSc.SetState(check.Warning)
483499
}
484500
}
485501

486502
if ioCheck.GetStatus() != check.Critical {
487503
if ioCheck.Perfdata[psi.IoSomeAvg10].Crit.DoesViolate(psiIo.Some.Avg10) ||
488504
ioCheck.Perfdata[psi.IoSomeAvg60].Crit.DoesViolate(psiIo.Some.Avg60) ||
489505
ioCheck.Perfdata[psi.IoSomeAvg300].Crit.DoesViolate(psiIo.Some.Avg300) {
490-
_ = ioCheck.SetState(check.Critical)
506+
_ = ioSomeSc.SetState(check.Critical)
491507
}
492508
}
493509

494-
ioCheck.Output = fmt.Sprintf("IO Pressure - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Full.Avg10, psiIo.Full.Avg60, psiIo.Full.Avg300)
510+
ioSomeSc.Output = fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Some.Avg10, psiIo.Some.Avg60, psiIo.Some.Avg300)
511+
ioCheck.AddSubcheck(ioSomeSc)
495512

496513
return ioCheck
497514
}
498515

499516
func checkPsiMemoryPressure(config *psiConfig) result.PartialResult {
500517
var memoryCheck result.PartialResult
501518
_ = memoryCheck.SetDefaultState(check.OK)
519+
memoryCheck.Output = "Memory"
502520

503521
psiMemory, err := psi.ReadMemoryPressure()
504522
if err != nil {
@@ -554,17 +572,23 @@ func checkPsiMemoryPressure(config *psiConfig) result.PartialResult {
554572
memoryCheck.Perfdata[psi.MemoryFullAvg300].Crit = &config.CriticalMemoryAvg.Th
555573
}
556574

575+
memoryFullSc := result.PartialResult{}
576+
_ = memoryFullSc.SetDefaultState(check.OK)
577+
557578
if memoryCheck.Perfdata[psi.MemoryFullAvg10].Warn.DoesViolate(psiMemory.Full.Avg10) ||
558579
memoryCheck.Perfdata[psi.MemoryFullAvg60].Warn.DoesViolate(psiMemory.Full.Avg60) ||
559580
memoryCheck.Perfdata[psi.MemoryFullAvg300].Warn.DoesViolate(psiMemory.Full.Avg300) {
560-
_ = memoryCheck.SetState(check.Warning)
581+
_ = memoryFullSc.SetState(check.Warning)
561582
}
562583

563584
if memoryCheck.Perfdata[psi.MemoryFullAvg10].Crit.DoesViolate(psiMemory.Full.Avg10) ||
564585
memoryCheck.Perfdata[psi.MemoryFullAvg60].Crit.DoesViolate(psiMemory.Full.Avg60) ||
565586
memoryCheck.Perfdata[psi.MemoryFullAvg300].Crit.DoesViolate(psiMemory.Full.Avg300) {
566-
_ = memoryCheck.SetState(check.Critical)
587+
_ = memoryFullSc.SetState(check.Critical)
567588
}
589+
590+
memoryFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Full.Avg10, psiMemory.Full.Avg60, psiMemory.Full.Avg300)
591+
memoryCheck.AddSubcheck(memoryFullSc)
568592
}
569593

570594
if config.WarningMemorySomeAvg10.IsSet {
@@ -604,23 +628,27 @@ func checkPsiMemoryPressure(config *psiConfig) result.PartialResult {
604628
memoryCheck.Perfdata[psi.MemorySomeAvg300].Crit = &config.CriticalMemoryAvg.Th
605629
}
606630

631+
memorySomeSc := result.PartialResult{}
632+
_ = memorySomeSc.SetDefaultState(check.OK)
633+
607634
if (memoryCheck.GetStatus() != check.Critical) && (memoryCheck.GetStatus() != check.Warning) {
608635
if memoryCheck.Perfdata[psi.MemorySomeAvg10].Warn.DoesViolate(psiMemory.Some.Avg10) ||
609636
memoryCheck.Perfdata[psi.MemorySomeAvg60].Warn.DoesViolate(psiMemory.Some.Avg60) ||
610637
memoryCheck.Perfdata[psi.MemorySomeAvg300].Warn.DoesViolate(psiMemory.Some.Avg300) {
611-
_ = memoryCheck.SetState(check.Warning)
638+
_ = memorySomeSc.SetState(check.Warning)
612639
}
613640
}
614641

615642
if memoryCheck.GetStatus() != check.Critical {
616643
if memoryCheck.Perfdata[psi.MemorySomeAvg10].Crit.DoesViolate(psiMemory.Some.Avg10) ||
617644
memoryCheck.Perfdata[psi.MemorySomeAvg60].Crit.DoesViolate(psiMemory.Some.Avg60) ||
618645
memoryCheck.Perfdata[psi.MemorySomeAvg300].Crit.DoesViolate(psiMemory.Some.Avg300) {
619-
_ = memoryCheck.SetState(check.Critical)
646+
_ = memorySomeSc.SetState(check.Critical)
620647
}
621648
}
622649

623-
memoryCheck.Output = fmt.Sprintf("Memory Pressure - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Full.Avg10, psiMemory.Full.Avg60, psiMemory.Full.Avg300)
650+
memorySomeSc.Output = fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Some.Avg10, psiMemory.Some.Avg60, psiMemory.Some.Avg300)
651+
memoryCheck.AddSubcheck(memorySomeSc)
624652

625653
return memoryCheck
626654
}

0 commit comments

Comments
 (0)