mirror of
https://github.com/fankes/komari-agent.git
synced 2026-03-26 21:35:12 +08:00
Compare commits
4 Commits
ec28397f8b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1c863bacd | ||
|
|
bb1e01459b | ||
|
|
c829958d59 | ||
|
|
3be21757f6 |
@@ -10,7 +10,9 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/dnsresolver"
|
||||
"github.com/komari-monitor/komari-agent/utils"
|
||||
)
|
||||
|
||||
@@ -136,7 +138,7 @@ func registerWithAutoDiscovery() error {
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
client := dnsresolver.GetHTTPClient(30 * time.Second)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send register request: %v", err)
|
||||
|
||||
@@ -83,26 +83,21 @@ func isPhysicalDisk(part disk.PartitionStat) bool {
|
||||
}
|
||||
mountpoint := strings.ToLower(part.Mountpoint)
|
||||
// 排除挂载点
|
||||
var mountpointsToExclude = []string{
|
||||
var mountpointsToExcludePerfix = []string{
|
||||
"/tmp",
|
||||
"/var/tmp",
|
||||
"/dev/shm",
|
||||
"/dev",
|
||||
"/run",
|
||||
"/run/lock",
|
||||
"/run/user",
|
||||
"/var/lib/containers",
|
||||
"/var/lib/docker",
|
||||
"/proc",
|
||||
"/dev/pts",
|
||||
"/sys",
|
||||
"/sys/fs/cgroup",
|
||||
"/dev/mqueue",
|
||||
"/etc/resolv.conf",
|
||||
"/etc/host", // /etc/hosts,/etc/hostname
|
||||
"/dev/hugepages",
|
||||
"/nix/store",
|
||||
}
|
||||
for _, mp := range mountpointsToExclude {
|
||||
for _, mp := range mountpointsToExcludePerfix {
|
||||
if mountpoint == mp || strings.HasPrefix(mountpoint, mp) {
|
||||
return false
|
||||
}
|
||||
@@ -123,6 +118,7 @@ func isPhysicalDisk(part disk.PartitionStat) bool {
|
||||
var fstypeToExclude = []string{
|
||||
"tmpfs",
|
||||
"devtmpfs",
|
||||
"udev",
|
||||
"nfs",
|
||||
"cifs",
|
||||
"smb",
|
||||
@@ -136,6 +132,9 @@ func isPhysicalDisk(part disk.PartitionStat) bool {
|
||||
"cgroup",
|
||||
"mqueue",
|
||||
"hugetlbfs",
|
||||
"debugfs",
|
||||
"binfmt_misc",
|
||||
"securityfs",
|
||||
}
|
||||
for _, fs := range fstypeToExclude {
|
||||
if fstype == fs || strings.HasPrefix(fstype, fs) {
|
||||
@@ -172,11 +171,33 @@ func DiskList() ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 同一物理设备只保留路径最短的根挂载点
|
||||
deviceMap := make(map[string]disk.PartitionStat)
|
||||
for _, part := range usage {
|
||||
if isPhysicalDisk(part) {
|
||||
diskList = append(diskList, fmt.Sprintf("%s (%s)", part.Mountpoint, part.Fstype))
|
||||
deviceID := part.Device
|
||||
// ZFS去重: 基于 pool 名称
|
||||
if strings.ToLower(part.Fstype) == "zfs" {
|
||||
if idx := strings.Index(deviceID, "/"); idx != -1 {
|
||||
deviceID = deviceID[:idx]
|
||||
}
|
||||
}
|
||||
|
||||
if existing, ok := deviceMap[deviceID]; ok {
|
||||
// 优先保留路径更短的挂载点 (e.g., /volume1 优于 /volume1/@appdata/...)
|
||||
if len(part.Mountpoint) < len(existing.Mountpoint) {
|
||||
deviceMap[deviceID] = part
|
||||
}
|
||||
} else {
|
||||
deviceMap[deviceID] = part
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, part := range deviceMap {
|
||||
diskList = append(diskList, fmt.Sprintf("%s (%s)", part.Mountpoint, part.Fstype))
|
||||
}
|
||||
}
|
||||
return diskList, nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ var (
|
||||
// 创建适用于IPv4和IPv6的HTTP客户端
|
||||
ipv4HTTPClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
dialer := dnsresolver.GetNetDialer(15 * time.Second)
|
||||
return dialer.DialContext(ctx, "tcp4", addr) // 锁v4防止出现问题
|
||||
@@ -29,6 +30,7 @@ var (
|
||||
}
|
||||
ipv6HTTPClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
dialer := dnsresolver.GetNetDialer(15 * time.Second)
|
||||
return dialer.DialContext(ctx, "tcp6", addr) // 锁v6防止出现问题
|
||||
|
||||
@@ -192,6 +192,7 @@ func newWSDialer() *websocket.Dialer {
|
||||
d := &websocket.Dialer{
|
||||
HandshakeTimeout: 15 * time.Second,
|
||||
NetDialContext: dnsresolver.GetDialContext(15 * time.Second),
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
}
|
||||
if flags.IgnoreUnsafeCert {
|
||||
d.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
|
||||
Reference in New Issue
Block a user