Skip to content

Commit

Permalink
Add support for monitoring sensor temperatures (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
funnyzak authored Jun 1, 2024
1 parent 611ad8b commit 968faca
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 77 deletions.
15 changes: 15 additions & 0 deletions model/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
pb "github.com/nezhahq/agent/proto"
)

type SensorTemperature struct {
Name string
Temperature float64
}

type HostState struct {
CPU float64
MemUsed uint64
Expand All @@ -20,9 +25,18 @@ type HostState struct {
TcpConnCount uint64
UdpConnCount uint64
ProcessCount uint64
Temperatures []SensorTemperature
}

func (s *HostState) PB() *pb.State {
var ts []*pb.State_SensorTemperature
for _, t := range s.Temperatures {
ts = append(ts, &pb.State_SensorTemperature{
Name: t.Name,
Temperature: t.Temperature,
})
}

return &pb.State{
Cpu: s.CPU,
MemUsed: s.MemUsed,
Expand All @@ -39,6 +53,7 @@ func (s *HostState) PB() *pb.State {
TcpConnCount: s.TcpConnCount,
UdpConnCount: s.UdpConnCount,
ProcessCount: s.ProcessCount,
Temperatures: ts,
}
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ func GetState(agentConfig *model.AgentConfig, skipConnectionCount bool, skipProc
}
}

temperatures, err := host.SensorsTemperatures()
if err != nil {
println("host.SensorsTemperatures error:", err)
} else {
for _, t := range temperatures {
ret.Temperatures = append(ret.Temperatures, model.SensorTemperature{
Name: t.SensorKey,
Temperature: t.Temperature,
})
}
}

ret.NetInTransfer, ret.NetOutTransfer = netInTransfer, netOutTransfer
ret.NetInSpeed, ret.NetOutSpeed = netInSpeed, netOutSpeed
ret.Uptime = uint64(time.Since(cachedBootTime).Seconds())
Expand Down
Loading

0 comments on commit 968faca

Please sign in to comment.