feat: 添加 list-disk 命令以列出所有物理磁盘

This commit is contained in:
Akizon77
2025-09-06 04:33:30 +00:00
parent 245fc45160
commit b2860fbfb0
2 changed files with 42 additions and 1 deletions

41
cmd/listDisk.go Normal file
View File

@@ -0,0 +1,41 @@
package cmd
import (
"fmt"
"log"
"text/tabwriter"
monitoring "github.com/komari-monitor/komari-agent/monitoring/unit"
"github.com/shirou/gopsutil/v4/disk"
"github.com/spf13/cobra"
)
var ListDiskCmd = &cobra.Command{
Use: "list-disk",
Short: "List all physical disks",
Long: `List all physical disks`,
Run: func(cmd *cobra.Command, args []string) {
dl, err := disk.Partitions(true)
if err != nil {
log.Println("Failed to get disk partitions:", err)
return
}
log.Println("All Disk Partitions:")
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "Mountpoint\tFstype")
for _, part := range dl {
fmt.Fprintf(w, "%s\t%s\n", part.Mountpoint, part.Fstype)
}
_ = w.Flush()
diskList, err := monitoring.DiskList()
if err != nil {
log.Println("Failed to get disk list:", err)
return
}
log.Println("Monitoring Mountpoints:", diskList)
},
}
func init() {
RootCmd.AddCommand(ListDiskCmd)
}

View File

@@ -83,7 +83,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&flags.Token, "token", "t", "", "API token")
//RootCmd.MarkPersistentFlagRequired("token")
RootCmd.PersistentFlags().StringVarP(&flags.Endpoint, "endpoint", "e", "", "API endpoint")
RootCmd.MarkPersistentFlagRequired("endpoint")
//RootCmd.MarkPersistentFlagRequired("endpoint")
RootCmd.PersistentFlags().StringVar(&flags.AutoDiscoveryKey, "auto-discovery", "", "Auto discovery key for the agent")
RootCmd.PersistentFlags().BoolVar(&flags.DisableAutoUpdate, "disable-auto-update", false, "Disable automatic updates")
RootCmd.PersistentFlags().BoolVar(&flags.DisableWebSsh, "disable-web-ssh", false, "Disable remote control(web ssh and rce)")