opt. for web api

This commit is contained in:
lollipopkit 2023-07-16 17:41:21 +08:00
parent 92d0144a57
commit a7caf4d094
2 changed files with 7 additions and 10 deletions

View File

@ -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++

View File

@ -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{