mirror of
https://github.com/Alexander-D-Karpov/netfetch.git
synced 2026-03-16 22:07:03 +03:00
137 lines
2.4 KiB
Go
137 lines
2.4 KiB
Go
package collector
|
|
|
|
import (
|
|
"netfetch/internal/model"
|
|
"sync"
|
|
)
|
|
|
|
type Collector struct {
|
|
activeModules map[string]bool
|
|
info *model.SystemInfo
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
func New(activeModules []string) *Collector {
|
|
c := &Collector{
|
|
activeModules: make(map[string]bool),
|
|
info: &model.SystemInfo{
|
|
Network: &model.NetworkInfo{Interfaces: make([]model.InterfaceInfo, 0)},
|
|
Disk: &model.DiskInfo{},
|
|
},
|
|
}
|
|
|
|
for _, moduleName := range activeModules {
|
|
c.activeModules[moduleName] = true
|
|
}
|
|
|
|
c.collectStaticInfo()
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *Collector) collectStaticInfo() {
|
|
if c.activeModules["os"] {
|
|
c.collectOS()
|
|
}
|
|
if c.activeModules["hostinfo"] {
|
|
c.collectHostInfo()
|
|
}
|
|
if c.activeModules["bios"] {
|
|
c.collectBIOS()
|
|
}
|
|
if c.activeModules["cpu"] {
|
|
c.collectCPU()
|
|
}
|
|
if c.activeModules["gpu"] {
|
|
c.collectGPU()
|
|
}
|
|
if c.activeModules["de"] {
|
|
c.collectDE()
|
|
}
|
|
if c.activeModules["wm"] {
|
|
c.collectWM()
|
|
}
|
|
if c.activeModules["theme"] {
|
|
c.collectTheme()
|
|
}
|
|
if c.activeModules["icons"] {
|
|
c.collectIcons()
|
|
}
|
|
if c.activeModules["terminal"] {
|
|
c.collectTerminal()
|
|
}
|
|
if c.activeModules["font"] {
|
|
c.collectFont()
|
|
}
|
|
if c.activeModules["cursor"] {
|
|
c.collectCursor()
|
|
}
|
|
if c.activeModules["loginmanager"] {
|
|
c.collectLoginManager()
|
|
}
|
|
c.collectShell()
|
|
}
|
|
|
|
func (c *Collector) CollectDynamicInfo() {
|
|
if c.activeModules["uptime"] {
|
|
c.collectUptime()
|
|
}
|
|
if c.activeModules["memory"] {
|
|
c.collectMemory()
|
|
}
|
|
if c.activeModules["disk"] {
|
|
c.collectDisk()
|
|
}
|
|
if c.activeModules["network"] {
|
|
c.collectNetwork()
|
|
}
|
|
if c.activeModules["resolution"] {
|
|
c.collectResolution()
|
|
}
|
|
if c.activeModules["packages"] {
|
|
c.collectPackages()
|
|
}
|
|
if c.activeModules["swap"] {
|
|
c.collectMemory()
|
|
}
|
|
if c.activeModules["localip"] {
|
|
c.collectLocalIP()
|
|
}
|
|
if c.activeModules["battery"] {
|
|
c.collectBattery()
|
|
}
|
|
if c.activeModules["poweradapter"] {
|
|
c.collectPowerAdapter()
|
|
}
|
|
if c.activeModules["locale"] {
|
|
c.collectLocale()
|
|
}
|
|
if c.activeModules["processes"] {
|
|
c.collectProcesses()
|
|
}
|
|
if c.activeModules["cpuusage"] {
|
|
c.collectCPUUsage()
|
|
}
|
|
if c.activeModules["publicip"] {
|
|
c.collectPublicIP()
|
|
}
|
|
if c.activeModules["wifi"] {
|
|
c.collectWifi()
|
|
}
|
|
if c.activeModules["datetime"] {
|
|
c.collectDateTime()
|
|
}
|
|
if c.activeModules["users"] {
|
|
c.collectUsers()
|
|
}
|
|
if c.activeModules["brightness"] {
|
|
c.collectBrightness()
|
|
}
|
|
}
|
|
|
|
func (c *Collector) GetInfo() *model.SystemInfo {
|
|
c.mutex.RLock()
|
|
defer c.mutex.RUnlock()
|
|
return c.info
|
|
}
|