mirror of
https://github.com/lollipopkit/server_box_monitor.git
synced 2025-01-08 11:47:36 +08:00
opt. for web api
This commit is contained in:
parent
92d0144a57
commit
a7caf4d094
@ -20,7 +20,7 @@ func (s Size) String() string {
|
||||
temp := float64(s)
|
||||
for {
|
||||
if temp < programKilo || nth == len(sizeSuffix)-1 {
|
||||
return fmt.Sprintf("%.1f %s", temp, sizeSuffix[nth])
|
||||
return fmt.Sprintf("%.1f%s", temp, sizeSuffix[nth])
|
||||
}
|
||||
temp = temp / programKilo
|
||||
nth++
|
||||
|
15
web/web.go
15
web/web.go
@ -9,24 +9,21 @@ import (
|
||||
|
||||
func Status(c echo.Context) error {
|
||||
s := model.Status
|
||||
var cpu any = 0.0
|
||||
cpu := ""
|
||||
if len(s.CPU) > 0 {
|
||||
var err error
|
||||
cpu, err = s.CPU[0].UsedPercent()
|
||||
if err != nil {
|
||||
cpu = err
|
||||
}
|
||||
cpu_, _ := s.CPU[0].UsedPercent()
|
||||
cpu = fmt.Sprintf("%.1f%%", cpu_ * 100)
|
||||
}
|
||||
mem := ""
|
||||
if s.Mem != nil {
|
||||
mem = fmt.Sprintf("%s / %s", s.Mem.Used.String(), s.Mem.Total.String())
|
||||
mem = fmt.Sprintf("%s/%s", s.Mem.Used.String(), s.Mem.Total.String())
|
||||
}
|
||||
net := ""
|
||||
if len(s.Network) > 0 {
|
||||
all := model.AllNetworkStatus(s.Network)
|
||||
rx, _ := all.ReceiveSpeed()
|
||||
tx, _ := all.TransmitSpeed()
|
||||
net = fmt.Sprintf("%s / %s", rx.String(), tx.String())
|
||||
net = fmt.Sprintf("%s⬇ %s⬆", rx.String(), tx.String())
|
||||
}
|
||||
disk := ""
|
||||
if len(s.Disk) > 0 {
|
||||
@ -37,7 +34,7 @@ func Status(c echo.Context) error {
|
||||
break
|
||||
}
|
||||
}
|
||||
disk = fmt.Sprintf("%s / %s", d.Used.String(), d.Total.String())
|
||||
disk = fmt.Sprintf("%s/%s", d.Used.String(), d.Total.String())
|
||||
}
|
||||
|
||||
status := map[string]any{
|
||||
|
Loading…
Reference in New Issue
Block a user