mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-18 18:49:23 +08:00
feat(monitoring): 增加网络总量和进程计数监控
- 在 net.go 中添加总量统计功能,记录上次采样值 - 在 main.go 中添加进程计数监控 - 修改 remote.go 中的 JSON 字段名称 - 优化 report 函数,增加网络总量和进程计数数据
This commit is contained in:
23
main.go
23
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"komari/config"
|
||||
"komari/monitoring"
|
||||
"log"
|
||||
@@ -181,8 +182,14 @@ func uploadBasicInfo(endpoint string, token string) error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
message := string(body)
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("status code: %d", resp.StatusCode)
|
||||
return fmt.Errorf("status code: %d,%s", resp.StatusCode, message)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -229,13 +236,15 @@ func report(localConfig config.LocalConfig, remoteConfig config.RemoteConfig) []
|
||||
}
|
||||
}
|
||||
if remoteConfig.Network {
|
||||
networkUp, networkDown, err := monitoring.NetworkSpeed()
|
||||
totalUp, totalDown, networkUp, networkDown, err := monitoring.NetworkSpeed(remoteConfig.Interval)
|
||||
if err != nil {
|
||||
message += fmt.Sprintf("failed to get network speed: %v\n", err)
|
||||
}
|
||||
data["network"] = map[string]interface{}{
|
||||
"up": networkUp,
|
||||
"down": networkDown,
|
||||
"up": networkUp,
|
||||
"down": networkDown,
|
||||
"totalUp": totalUp,
|
||||
"totalDown": totalDown,
|
||||
}
|
||||
}
|
||||
if remoteConfig.Connections {
|
||||
@@ -243,7 +252,7 @@ func report(localConfig config.LocalConfig, remoteConfig config.RemoteConfig) []
|
||||
if err != nil {
|
||||
message += fmt.Sprintf("failed to get connections: %v\n", err)
|
||||
}
|
||||
data["network"] = map[string]interface{}{
|
||||
data["connections"] = map[string]interface{}{
|
||||
"tcp": tcpCount,
|
||||
"udp": udpCount,
|
||||
}
|
||||
@@ -255,6 +264,10 @@ func report(localConfig config.LocalConfig, remoteConfig config.RemoteConfig) []
|
||||
}
|
||||
data["uptime"] = uptime
|
||||
}
|
||||
if remoteConfig.Process {
|
||||
processcount := monitoring.ProcessCount()
|
||||
data["process"] = processcount
|
||||
}
|
||||
data["message"] = message
|
||||
|
||||
s, err := json.Marshal(data)
|
||||
|
Reference in New Issue
Block a user