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