mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: 启动时输出监控的文件夹和网卡名
This commit is contained in:
11
cmd/root.go
11
cmd/root.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/komari-monitor/komari-agent/cmd/flags"
|
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||||
|
monitoring "github.com/komari-monitor/komari-agent/monitoring/unit"
|
||||||
"github.com/komari-monitor/komari-agent/server"
|
"github.com/komari-monitor/komari-agent/server"
|
||||||
"github.com/komari-monitor/komari-agent/update"
|
"github.com/komari-monitor/komari-agent/update"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -19,6 +20,16 @@ var RootCmd = &cobra.Command{
|
|||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
log.Println("Komari Agent", update.CurrentVersion)
|
log.Println("Komari Agent", update.CurrentVersion)
|
||||||
log.Println("Github Repo:", update.Repo)
|
log.Println("Github Repo:", update.Repo)
|
||||||
|
diskList, err := monitoring.DiskList()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to get disk list:", err)
|
||||||
|
}
|
||||||
|
log.Println("Monitoring Mountpoints:", diskList)
|
||||||
|
interfaceList, err := monitoring.InterfaceList()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to get interface list:", err)
|
||||||
|
}
|
||||||
|
log.Println("Monitoring Interfaces:", interfaceList)
|
||||||
|
|
||||||
// 忽略不安全的证书
|
// 忽略不安全的证书
|
||||||
if flags.IgnoreUnsafeCert {
|
if flags.IgnoreUnsafeCert {
|
||||||
|
@@ -90,3 +90,27 @@ func isPhysicalDisk(part disk.PartitionStat) bool {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DiskList() ([]string, error) {
|
||||||
|
diskList := []string{}
|
||||||
|
if flags.IncludeMountpoints != "" {
|
||||||
|
includeMounts := strings.Split(flags.IncludeMountpoints, ";")
|
||||||
|
for _, mountpoint := range includeMounts {
|
||||||
|
mountpoint = strings.TrimSpace(mountpoint)
|
||||||
|
if mountpoint != "" {
|
||||||
|
diskList = append(diskList, mountpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
usage, err := disk.Partitions(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, part := range usage {
|
||||||
|
if isPhysicalDisk(part) {
|
||||||
|
diskList = append(diskList, part.Mountpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return diskList, nil
|
||||||
|
}
|
||||||
|
@@ -321,3 +321,30 @@ func shouldInclude(nicName string, includeNics, excludeNics map[string]struct{})
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InterfaceList() ([]string, error) {
|
||||||
|
includeNics := parseNics(flags.IncludeNics)
|
||||||
|
excludeNics := parseNics(flags.ExcludeNics)
|
||||||
|
interfaces := []string{}
|
||||||
|
if flags.MonthRotate != 0 {
|
||||||
|
vnstatData, err := getVnstatData()
|
||||||
|
if err == nil {
|
||||||
|
for interfaceName := range vnstatData {
|
||||||
|
if shouldInclude(interfaceName, includeNics, excludeNics) {
|
||||||
|
interfaces = append(interfaces, interfaceName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return interfaces, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioCounters, err := net.IOCounters(true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, interfaceStats := range ioCounters {
|
||||||
|
if shouldInclude(interfaceStats.Name, includeNics, excludeNics) {
|
||||||
|
interfaces = append(interfaces, interfaceStats.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return interfaces, nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user