github.com/netdata/go.d.plugin@v0.58.1/modules/windows/collect_thermalzone.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package windows
     4  
     5  import (
     6  	"strings"
     7  
     8  	"github.com/netdata/go.d.plugin/pkg/prometheus"
     9  )
    10  
    11  const (
    12  	metricThermalzoneTemperatureCelsius = "windows_thermalzone_temperature_celsius"
    13  )
    14  
    15  func (w *Windows) collectThermalzone(mx map[string]int64, pms prometheus.Series) {
    16  	seen := make(map[string]bool)
    17  	for _, pm := range pms.FindByName(metricThermalzoneTemperatureCelsius) {
    18  		if name := cleanZoneName(pm.Labels.Get("name")); name != "" {
    19  			seen[name] = true
    20  			mx["thermalzone_"+name+"_temperature"] = int64(pm.Value)
    21  		}
    22  	}
    23  
    24  	for zone := range seen {
    25  		if !w.cache.thermalZones[zone] {
    26  			w.cache.thermalZones[zone] = true
    27  			w.addThermalZoneCharts(zone)
    28  		}
    29  	}
    30  	for zone := range w.cache.thermalZones {
    31  		if !seen[zone] {
    32  			delete(w.cache.thermalZones, zone)
    33  			w.removeThermalZoneCharts(zone)
    34  		}
    35  	}
    36  }
    37  
    38  func cleanZoneName(name string) string {
    39  	// "\\_TZ.TZ10", "\\_TZ.X570" => TZ10, X570
    40  	i := strings.Index(name, ".")
    41  	if i == -1 || len(name) == i+1 {
    42  		return ""
    43  	}
    44  	return name[i+1:]
    45  }