mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: #5 支持指定挂载路径
This commit is contained in:
@@ -13,5 +13,6 @@ var (
|
|||||||
InfoReportInterval int
|
InfoReportInterval int
|
||||||
IncludeNics string
|
IncludeNics string
|
||||||
ExcludeNics string
|
ExcludeNics string
|
||||||
|
IncludeMountpoints string
|
||||||
MonthRotate int
|
MonthRotate int
|
||||||
)
|
)
|
||||||
|
@@ -70,6 +70,7 @@ func init() {
|
|||||||
RootCmd.PersistentFlags().IntVar(&flags.InfoReportInterval, "info-report-interval", 5, "Interval in minutes for reporting basic info")
|
RootCmd.PersistentFlags().IntVar(&flags.InfoReportInterval, "info-report-interval", 5, "Interval in minutes for reporting basic info")
|
||||||
RootCmd.PersistentFlags().StringVar(&flags.IncludeNics, "include-nics", "", "Comma-separated list of network interfaces to include")
|
RootCmd.PersistentFlags().StringVar(&flags.IncludeNics, "include-nics", "", "Comma-separated list of network interfaces to include")
|
||||||
RootCmd.PersistentFlags().StringVar(&flags.ExcludeNics, "exclude-nics", "", "Comma-separated list of network interfaces to exclude")
|
RootCmd.PersistentFlags().StringVar(&flags.ExcludeNics, "exclude-nics", "", "Comma-separated list of network interfaces to exclude")
|
||||||
|
RootCmd.PersistentFlags().StringVar(&flags.IncludeMountpoints, "include-mountpoint", "", "Semicolon-separated list of mount points to include for disk statistics")
|
||||||
RootCmd.PersistentFlags().IntVar(&flags.MonthRotate, "month-rotate", 0, "Month reset for network statistics (0 to disable)")
|
RootCmd.PersistentFlags().IntVar(&flags.MonthRotate, "month-rotate", 0, "Month reset for network statistics (0 to disable)")
|
||||||
RootCmd.PersistentFlags().ParseErrorsWhitelist.UnknownFlags = true
|
RootCmd.PersistentFlags().ParseErrorsWhitelist.UnknownFlags = true
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package monitoring
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||||
"github.com/shirou/gopsutil/v4/disk"
|
"github.com/shirou/gopsutil/v4/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,15 +19,32 @@ func Disk() DiskInfo {
|
|||||||
diskinfo.Total = 0
|
diskinfo.Total = 0
|
||||||
diskinfo.Used = 0
|
diskinfo.Used = 0
|
||||||
} else {
|
} else {
|
||||||
for _, part := range usage {
|
// 如果指定了自定义挂载点,只统计指定的挂载点
|
||||||
// 排除临时文件系统和网络驱动器
|
if flags.IncludeMountpoints != "" {
|
||||||
if isPhysicalDisk(part) {
|
includeMounts := strings.Split(flags.IncludeMountpoints, ";")
|
||||||
u, err := disk.Usage(part.Mountpoint)
|
for _, mountpoint := range includeMounts {
|
||||||
if err != nil {
|
mountpoint = strings.TrimSpace(mountpoint)
|
||||||
continue
|
if mountpoint != "" {
|
||||||
} else {
|
u, err := disk.Usage(mountpoint)
|
||||||
diskinfo.Total += u.Total
|
if err != nil {
|
||||||
diskinfo.Used += u.Used
|
continue
|
||||||
|
} else {
|
||||||
|
diskinfo.Total += u.Total
|
||||||
|
diskinfo.Used += u.Used
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 使用默认逻辑,排除临时文件系统和网络驱动器
|
||||||
|
for _, part := range usage {
|
||||||
|
if isPhysicalDisk(part) {
|
||||||
|
u, err := disk.Usage(part.Mountpoint)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
diskinfo.Total += u.Total
|
||||||
|
diskinfo.Used += u.Used
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user