mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	megacli: prevent crash when drive temperature is N/A
Intel SSD do not report their temperature in MegaCLI output Drive Temperature : N/A
This commit is contained in:
		
							parent
							
								
									aca4688dc3
								
							
						
					
					
						commit
						0028abc077
					
				
							
								
								
									
										3
									
								
								collector/fixtures/megacli
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								collector/fixtures/megacli
									
									
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
cat fixtures/megacli_disks.txt
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +83,7 @@ Foreign State: None
 | 
			
		|||
Device Speed: Unknown 
 | 
			
		||||
Link Speed: Unknown 
 | 
			
		||||
Media Type: Hard Disk Device
 | 
			
		||||
Drive Temperature :37C (98.60 F)
 | 
			
		||||
Drive Temperature : N/A
 | 
			
		||||
PI Eligibility:  No 
 | 
			
		||||
Drive is formatted for PI information:  No
 | 
			
		||||
PI: No PI
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -196,17 +196,18 @@ func (c *megaCliCollector) updateDisks() error {
 | 
			
		|||
 | 
			
		||||
	for enc, encStats := range stats {
 | 
			
		||||
		for slot, slotStats := range encStats {
 | 
			
		||||
			tStr := slotStats["Drive Temperature"]
 | 
			
		||||
			tStr = tStr[:strings.Index(tStr, "C")]
 | 
			
		||||
			t, err := strconv.ParseFloat(tStr, 64)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			encStr := strconv.Itoa(enc)
 | 
			
		||||
			slotStr := strconv.Itoa(slot)
 | 
			
		||||
 | 
			
		||||
			c.driveTemperature.WithLabelValues(encStr, slotStr).Set(t)
 | 
			
		||||
			tStr := slotStats["Drive Temperature"]
 | 
			
		||||
			if strings.Index(tStr, "C") > 0 {
 | 
			
		||||
				tStr = tStr[:strings.Index(tStr, "C")]
 | 
			
		||||
				t, err := strconv.ParseFloat(tStr, 64)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
				c.driveTemperature.WithLabelValues(encStr, slotStr).Set(t)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			for _, i := range counters {
 | 
			
		||||
				counter, err := strconv.ParseFloat(slotStats[i], 64)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,8 +3,11 @@
 | 
			
		|||
package collector
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"flag"
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/prometheus/client_golang/prometheus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +51,32 @@ func TestMegaCliDisks(t *testing.T) {
 | 
			
		|||
		t.Fatalf("Unexpected drive temperature: %s", stats[32][0]["Drive Temperature"])
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if stats[32][1]["Drive Temperature"] != "N/A" {
 | 
			
		||||
		t.Fatalf("Unexpected drive temperature: %s", stats[32][2]["Drive Temperature"])
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if stats[32][3]["Predictive Failure Count"] != "23" {
 | 
			
		||||
		t.Fatal()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestMegaCliCollectorDoesntCrash(t *testing.T) {
 | 
			
		||||
	if err := flag.Set("collector.megacli.command", "./fixtures/megacli"); err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	collector, err := NewMegaCliCollector()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	sink := make(chan prometheus.Metric)
 | 
			
		||||
	go func() {
 | 
			
		||||
		for {
 | 
			
		||||
			<-sink
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	err = collector.Update(sink)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue