opt.: disk usage status calc

This commit is contained in:
lollipopkit 2024-03-13 00:19:28 -06:00
parent ef0812a21a
commit abb5ef2a01
2 changed files with 31 additions and 10 deletions

View File

@ -149,6 +149,14 @@ var (
Code: 200,
}
defaultWebhookIfaceBytes, _ = json.Marshal(defaultWebhookIface)
defaultIosIface = PushIfaceIOS{
Token: "",
Title: res.PushFormatNameLocator,
Content: res.PushFormatMsgLocator,
BodyRegex: ".*",
Code: 200,
}
defaultIosIfaceBytes, _ = json.Marshal(defaultIosIface)
DefaultAppConfig = &AppConfig{
Version: res.ConfVersion,
@ -168,6 +176,11 @@ var (
Name: "QQ Group",
Iface: defaultWebhookIfaceBytes,
},
{
Type: PushTypeIOS,
Name: "My iPhone",
Iface: defaultIosIfaceBytes,
},
},
}
)

View File

@ -2,8 +2,10 @@ package web
import (
"fmt"
"strings"
"github.com/labstack/echo/v4"
"github.com/lollipopkit/gommon/util"
"github.com/lollipopkit/server_box_monitor/model"
)
@ -25,18 +27,24 @@ func Status(c echo.Context) error {
tx := all.Transmit().String()
net = fmt.Sprintf("%s / %s", rx, tx)
}
disk := ""
if len(s.Disk) > 0 {
d := s.Disk[0]
for _, v := range s.Disk {
if v.MountPath == "/" {
d = v
break
}
diskUsed := model.Size(0)
diskTotal := model.Size(0)
diskDevs := []string{}
for _, v := range s.Disk {
if !strings.HasPrefix(v.Filesystem, "/dev") {
continue
}
disk = fmt.Sprintf("%s / %s", d.Used.String(), d.Total.String())
if util.Contains(diskDevs, v.Filesystem) {
continue
}
diskDevs = append(diskDevs, v.Filesystem)
diskUsed += v.Used
diskTotal += v.Total
}
disk := ""
if diskTotal > 0 {
disk = fmt.Sprintf("%s / %s", diskUsed.String(), diskTotal.String())
}
status := map[string]string{
"name": model.Config.Name,
"cpu": cpu,