Skip to content

Commit

Permalink
add SENSORS env var
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Sep 29, 2024
1 parent 5447cca commit 9ab359d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions beszel/internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Agent struct {
dockerClient *http.Client // HTTP client to query docker api
apiContainerList *[]container.ApiInfo // List of containers from docker host
sensorsContext context.Context // Sensors context to override sys location
sensorsWhitelist map[string]struct{} // List of sensors to monitor
}

func NewAgent() *Agent {
Expand Down Expand Up @@ -64,6 +65,14 @@ func (a *Agent) Run(pubKey []byte, addr string) {
)
}

// Set sensors whitelist
if sensors, exists := os.LookupEnv("SENSORS"); exists {
a.sensorsWhitelist = make(map[string]struct{})
for _, sensor := range strings.Split(sensors, ",") {
a.sensorsWhitelist[sensor] = struct{}{}
}
}

a.initializeSystemInfo()
a.initializeDiskInfo()
a.initializeNetIoStats()
Expand Down
9 changes: 9 additions & 0 deletions beszel/internal/agent/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ func (a *Agent) getSystemStats() (system.Info, system.Stats) {
systemStats.Temperatures[sensor.SensorKey] = twoDecimals(sensor.Temperature)
}
}
// remove sensors from systemStats if whitelist exists and sensor is not in whitelist
// (do this here instead of in initial loop so we have correct keys if int was appended)
if a.sensorsWhitelist != nil {
for key := range systemStats.Temperatures {
if _, nameInWhitelist := a.sensorsWhitelist[key]; !nameInWhitelist {
delete(systemStats.Temperatures, key)
}
}
}
}

systemInfo := system.Info{
Expand Down

0 comments on commit 9ab359d

Please sign in to comment.