mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-21 21:26:16 +01:00
* add agent smart support * refactor(system): update JSON tags in SmartData struct * refactor(agent): use serial number as the key of SmartDataMap Updated the SmartManager's methods to use the device's serial number as the key in the SmartDataMap instead of the device name. * refactor: use raw values in smart attributes for nvme devices * feat: add S.M.A.R.T. data display in web ui Introduced a new Disks tab in the SystemDetail component to display disk information and S.M.A.R.T. data. The tab includes a table for visualizing disk attributes and their statuses. Also added SmartData and SmartAttribute interfaces to support the new functionality.
126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
package system
|
|
|
|
// TODO: this is confusing, make common package with common/types common/helpers etc
|
|
|
|
import (
|
|
"beszel/internal/entities/container"
|
|
"time"
|
|
)
|
|
|
|
type Stats struct {
|
|
Cpu float64 `json:"cpu"`
|
|
MaxCpu float64 `json:"cpum,omitempty"`
|
|
Mem float64 `json:"m"`
|
|
MemUsed float64 `json:"mu"`
|
|
MemPct float64 `json:"mp"`
|
|
MemBuffCache float64 `json:"mb"`
|
|
MemZfsArc float64 `json:"mz,omitempty"` // ZFS ARC memory
|
|
Swap float64 `json:"s,omitempty"`
|
|
SwapUsed float64 `json:"su,omitempty"`
|
|
DiskTotal float64 `json:"d"`
|
|
DiskUsed float64 `json:"du"`
|
|
DiskPct float64 `json:"dp"`
|
|
DiskReadPs float64 `json:"dr"`
|
|
DiskWritePs float64 `json:"dw"`
|
|
MaxDiskReadPs float64 `json:"drm,omitempty"`
|
|
MaxDiskWritePs float64 `json:"dwm,omitempty"`
|
|
NetworkSent float64 `json:"ns"`
|
|
NetworkRecv float64 `json:"nr"`
|
|
MaxNetworkSent float64 `json:"nsm,omitempty"`
|
|
MaxNetworkRecv float64 `json:"nrm,omitempty"`
|
|
Temperatures map[string]float64 `json:"t,omitempty"`
|
|
ExtraFs map[string]*FsStats `json:"efs,omitempty"`
|
|
GPUData map[string]GPUData `json:"g,omitempty"`
|
|
SmartData map[string]SmartData `json:"sm,omitempty"`
|
|
}
|
|
|
|
type GPUData struct {
|
|
Name string `json:"n"`
|
|
Temperature float64 `json:"-"`
|
|
MemoryUsed float64 `json:"mu,omitempty"`
|
|
MemoryTotal float64 `json:"mt,omitempty"`
|
|
Usage float64 `json:"u"`
|
|
Power float64 `json:"p,omitempty"`
|
|
Count float64 `json:"-"`
|
|
}
|
|
|
|
type FsStats struct {
|
|
Time time.Time `json:"-"`
|
|
Root bool `json:"-"`
|
|
Mountpoint string `json:"-"`
|
|
DiskTotal float64 `json:"d"`
|
|
DiskUsed float64 `json:"du"`
|
|
TotalRead uint64 `json:"-"`
|
|
TotalWrite uint64 `json:"-"`
|
|
DiskReadPs float64 `json:"r"`
|
|
DiskWritePs float64 `json:"w"`
|
|
MaxDiskReadPS float64 `json:"rm,omitempty"`
|
|
MaxDiskWritePS float64 `json:"wm,omitempty"`
|
|
}
|
|
|
|
type NetIoStats struct {
|
|
BytesRecv uint64
|
|
BytesSent uint64
|
|
Time time.Time
|
|
Name string
|
|
}
|
|
|
|
type Os uint8
|
|
|
|
const (
|
|
Linux Os = iota
|
|
Darwin
|
|
Windows
|
|
Freebsd
|
|
)
|
|
|
|
type SmartData struct {
|
|
ModelFamily string `json:"mf,omitempty"`
|
|
ModelName string `json:"mn,omitempty"`
|
|
SerialNumber string `json:"sn,omitempty"`
|
|
FirmwareVersion string `json:"fv,omitempty"`
|
|
Capacity uint64 `json:"c,omitempty"`
|
|
SmartStatus string `json:"s,omitempty"`
|
|
DiskName string `json:"dn,omitempty"` // something like /dev/sda
|
|
DiskType string `json:"dt,omitempty"`
|
|
Temperature int `json:"t,omitempty"`
|
|
Attributes []*SmartAttribute `json:"a,omitempty"`
|
|
}
|
|
|
|
type SmartAttribute struct {
|
|
Id int `json:"id,omitempty"`
|
|
Name string `json:"n"`
|
|
Value int `json:"v,omitempty"`
|
|
Worst int `json:"w,omitempty"`
|
|
Threshold int `json:"t,omitempty"`
|
|
RawValue int `json:"rv"`
|
|
RawString string `json:"rs,omitempty"`
|
|
Flags string `json:"f,omitempty"`
|
|
WhenFailed string `json:"wf,omitempty"`
|
|
}
|
|
|
|
type Info struct {
|
|
Hostname string `json:"h"`
|
|
KernelVersion string `json:"k,omitempty"`
|
|
Cores int `json:"c"`
|
|
Threads int `json:"t,omitempty"`
|
|
CpuModel string `json:"m"`
|
|
Uptime uint64 `json:"u"`
|
|
Cpu float64 `json:"cpu"`
|
|
MemPct float64 `json:"mp"`
|
|
DiskPct float64 `json:"dp"`
|
|
Bandwidth float64 `json:"b"`
|
|
AgentVersion string `json:"v"`
|
|
Podman bool `json:"p,omitempty"`
|
|
GpuPct float64 `json:"g,omitempty"`
|
|
DashboardTemp float64 `json:"dt,omitempty"`
|
|
Os Os `json:"os"`
|
|
}
|
|
|
|
// Final data structure to return to the hub
|
|
type CombinedData struct {
|
|
Stats Stats `json:"stats"`
|
|
Info Info `json:"info"`
|
|
Containers []*container.Stats `json:"container"`
|
|
}
|