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
|
||||
IncludeNics string
|
||||
ExcludeNics string
|
||||
IncludeMountpoints string
|
||||
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().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.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().ParseErrorsWhitelist.UnknownFlags = true
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package monitoring
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
)
|
||||
|
||||
@@ -18,15 +19,32 @@ func Disk() DiskInfo {
|
||||
diskinfo.Total = 0
|
||||
diskinfo.Used = 0
|
||||
} 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
|
||||
// 如果指定了自定义挂载点,只统计指定的挂载点
|
||||
if flags.IncludeMountpoints != "" {
|
||||
includeMounts := strings.Split(flags.IncludeMountpoints, ";")
|
||||
for _, mountpoint := range includeMounts {
|
||||
mountpoint = strings.TrimSpace(mountpoint)
|
||||
if mountpoint != "" {
|
||||
u, err := disk.Usage(mountpoint)
|
||||
if err != nil {
|
||||
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