This commit is contained in:
Logan committed 2026-07-09 14:16:56 +08:00
1 parent 0690285147
commit 5618cd2738
154 files changed
+5021 -3161

No files matched your search

+16 -16
View File
@@ -28,7 +28,7 @@ type ZabbixHostSummary struct {
Hostname string `json:"hostname"`
Name string `json:"name"`
IP string `json:"ip"`
Available string `json:"available"` // 0=未知 1=可用 2=不可用
Available string `json:"available"` // 0=未知 1=可用 2=不可用
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
DiskUsage float64 `json:"disk_usage"`
@@ -71,7 +71,7 @@ func (h *ZabbixProxyHandler) Connect(c *gin.Context) {
// 获取主机列表(含接口和组信息)
hosts, err := client.GetHosts(ctx, &zabbix.GetHostsParams{
Status: 0, // 只获取被监控的主机
Status: 0, // 只获取被监控的主机
SelectInterfaces: []string{"interfaceid", "hostid", "main", "type", "useip", "ip", "dns", "port"},
SelectGroups: []string{"groupid", "name"},
Output: []string{"hostid", "host", "name", "status", "available", "description"},
@@ -85,17 +85,17 @@ func (h *ZabbixProxyHandler) Connect(c *gin.Context) {
// 为每台主机查询监控项
var summaries []ZabbixHostSummary
itemKeys := []string{
"system.cpu.util[,idle]", // CPU 空闲率
"system.cpu.util", // CPU 使用率(备用)
"vm.memory.size[total]", // 总内存 bytes
"vm.memory.size[available]", // 可用内存 bytes
"vfs.fs.size[/,total]", // 总磁盘 bytes
"vfs.fs.size[/,used]", // 已用磁盘 bytes
"system.cpu.load[all,avg5]", // 5分钟负载
"net.if.in[ens18]", // 网络流入
"net.if.out[ens18]", // 网络流出
"system.cpu.num", // CPU 数量
"system.uptime", // 运行时间
"system.cpu.util[,idle]", // CPU 空闲率
"system.cpu.util", // CPU 使用率(备用)
"vm.memory.size[total]", // 总内存 bytes
"vm.memory.size[available]", // 可用内存 bytes
"vfs.fs.size[/,total]", // 总磁盘 bytes
"vfs.fs.size[/,used]", // 已用磁盘 bytes
"system.cpu.load[all,avg5]", // 5分钟负载
"net.if.in[ens18]", // 网络流入
"net.if.out[ens18]", // 网络流出
"system.cpu.num", // CPU 数量
"system.uptime", // 运行时间
}
for _, host := range hosts {
@@ -185,9 +185,9 @@ func (h *ZabbixProxyHandler) Connect(c *gin.Context) {
Code: 200,
Message: "success",
Data: gin.H{
"version": version,
"hosts": summaries,
"total": len(summaries),
"version": version,
"hosts": summaries,
"total": len(summaries),
},
})
}