mirror of
https://github.com/fankes/komari-agent.git
synced 2025-12-12 00:13:37 +08:00
feat: #28 支持使用环境变量 / 配置文件来传入 agent 参数
This commit is contained in:
@@ -5,10 +5,12 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
pkg_flags "github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
monitoring "github.com/komari-monitor/komari-agent/monitoring/unit"
|
||||
)
|
||||
|
||||
var flags = pkg_flags.GlobalConfig
|
||||
|
||||
func GenerateReport() []byte {
|
||||
message := ""
|
||||
data := map[string]interface{}{}
|
||||
@@ -92,7 +94,7 @@ func GenerateReport() []byte {
|
||||
// 成功获取详细信息
|
||||
gpuData := make([]map[string]interface{}, len(gpuInfo))
|
||||
totalGPUUsage := 0.0
|
||||
|
||||
|
||||
for i, info := range gpuInfo {
|
||||
gpuData[i] = map[string]interface{}{
|
||||
"name": info.Name,
|
||||
@@ -103,13 +105,13 @@ func GenerateReport() []byte {
|
||||
}
|
||||
totalGPUUsage += info.Utilization
|
||||
}
|
||||
|
||||
|
||||
avgGPUUsage := totalGPUUsage / float64(len(gpuInfo))
|
||||
|
||||
|
||||
data["gpu"] = map[string]interface{}{
|
||||
"count": len(gpuInfo),
|
||||
"average_usage": avgGPUUsage,
|
||||
"detailed_info": gpuData,
|
||||
"count": len(gpuInfo),
|
||||
"average_usage": avgGPUUsage,
|
||||
"detailed_info": gpuData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
pkg_flags "github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
"github.com/shirou/gopsutil/v4/cpu"
|
||||
)
|
||||
|
||||
var flags = pkg_flags.GlobalConfig
|
||||
|
||||
type CpuInfo struct {
|
||||
CPUName string `json:"cpu_name"`
|
||||
CPUArchitecture string `json:"cpu_architecture"`
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
"github.com/komari-monitor/komari-agent/dnsresolver"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package monitoring
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
"github.com/shirou/gopsutil/v4/mem"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
"github.com/komari-monitor/komari-agent/monitoring/netstatic"
|
||||
"github.com/komari-monitor/komari-agent/utils"
|
||||
"github.com/shirou/gopsutil/v4/net"
|
||||
|
||||
@@ -2,8 +2,6 @@ package monitoring
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
)
|
||||
|
||||
func TestConnectionsCount(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user