diff --git a/app/wails/frontend/wailsjs/go/models.ts b/app/wails/frontend/wailsjs/go/models.ts index 2f769a7..985b3c8 100644 --- a/app/wails/frontend/wailsjs/go/models.ts +++ b/app/wails/frontend/wailsjs/go/models.ts @@ -36,6 +36,38 @@ export namespace cpu { this.microcode = source["microcode"]; } } + export class TimesStat { + cpu: string; + user: number; + system: number; + idle: number; + nice: number; + iowait: number; + irq: number; + softirq: number; + steal: number; + guest: number; + guestNice: number; + + static createFrom(source: any = {}) { + return new TimesStat(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.cpu = source["cpu"]; + this.user = source["user"]; + this.system = source["system"]; + this.idle = source["idle"]; + this.nice = source["nice"]; + this.iowait = source["iowait"]; + this.irq = source["irq"]; + this.softirq = source["softirq"]; + this.steal = source["steal"]; + this.guest = source["guest"]; + this.guestNice = source["guestNice"]; + } + } } @@ -92,6 +124,121 @@ export namespace disk { } +export namespace mem { + + export class SwapMemoryStat { + total: number; + used: number; + free: number; + usedPercent: number; + sin: number; + sout: number; + pgin: number; + pgout: number; + pgfault: number; + pgmajfault: number; + + static createFrom(source: any = {}) { + return new SwapMemoryStat(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.total = source["total"]; + this.used = source["used"]; + this.free = source["free"]; + this.usedPercent = source["usedPercent"]; + this.sin = source["sin"]; + this.sout = source["sout"]; + this.pgin = source["pgin"]; + this.pgout = source["pgout"]; + this.pgfault = source["pgfault"]; + this.pgmajfault = source["pgmajfault"]; + } + } + export class VirtualMemoryStat { + total: number; + available: number; + used: number; + usedPercent: number; + free: number; + active: number; + inactive: number; + wired: number; + laundry: number; + buffers: number; + cached: number; + writeback: number; + dirty: number; + writebacktmp: number; + shared: number; + slab: number; + sreclaimable: number; + sunreclaim: number; + pagetables: number; + swapcached: number; + commitlimit: number; + committedas: number; + hightotal: number; + highfree: number; + lowtotal: number; + lowfree: number; + swaptotal: number; + swapfree: number; + mapped: number; + vmalloctotal: number; + vmallocused: number; + vmallocchunk: number; + hugepagestotal: number; + hugepagesfree: number; + hugepagesize: number; + + static createFrom(source: any = {}) { + return new VirtualMemoryStat(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.total = source["total"]; + this.available = source["available"]; + this.used = source["used"]; + this.usedPercent = source["usedPercent"]; + this.free = source["free"]; + this.active = source["active"]; + this.inactive = source["inactive"]; + this.wired = source["wired"]; + this.laundry = source["laundry"]; + this.buffers = source["buffers"]; + this.cached = source["cached"]; + this.writeback = source["writeback"]; + this.dirty = source["dirty"]; + this.writebacktmp = source["writebacktmp"]; + this.shared = source["shared"]; + this.slab = source["slab"]; + this.sreclaimable = source["sreclaimable"]; + this.sunreclaim = source["sunreclaim"]; + this.pagetables = source["pagetables"]; + this.swapcached = source["swapcached"]; + this.commitlimit = source["commitlimit"]; + this.committedas = source["committedas"]; + this.hightotal = source["hightotal"]; + this.highfree = source["highfree"]; + this.lowtotal = source["lowtotal"]; + this.lowfree = source["lowfree"]; + this.swaptotal = source["swaptotal"]; + this.swapfree = source["swapfree"]; + this.mapped = source["mapped"]; + this.vmalloctotal = source["vmalloctotal"]; + this.vmallocused = source["vmallocused"]; + this.vmallocchunk = source["vmallocchunk"]; + this.hugepagestotal = source["hugepagestotal"]; + this.hugepagesfree = source["hugepagesfree"]; + this.hugepagesize = source["hugepagesize"]; + } + } + +} + export namespace net { export class Addr { @@ -155,3 +302,20 @@ export namespace net { } +export namespace process { + + export class Process { + pid: number; + + static createFrom(source: any = {}) { + return new Process(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.pid = source["pid"]; + } + } + +} + diff --git a/app/wails/frontend/wailsjs/go/system/InfoUtils.d.ts b/app/wails/frontend/wailsjs/go/system/InfoUtils.d.ts index 3db7cdc..a9184f9 100644 --- a/app/wails/frontend/wailsjs/go/system/InfoUtils.d.ts +++ b/app/wails/frontend/wailsjs/go/system/InfoUtils.d.ts @@ -3,14 +3,30 @@ import {cpu} from '../models'; import {disk} from '../models'; import {net} from '../models'; +import {process} from '../models'; +import {mem} from '../models'; import {system} from '../models'; +export function GetAllProcessPid():Promise>; + export function GetCpuInfo():Promise>; +export function GetCpuTimes():Promise>; + +export function GetCpuUsage():Promise>; + export function GetDiskPartitions():Promise>; export function GetDiskUsage(arg1:string):Promise; +export function GetIOCounters():Promise<{[key: string]: disk.IOCountersStat}>; + export function GetNetWorkConnection():Promise>; +export function GetProcessInfo(arg1:number):Promise; + +export function GetSwapMemory():Promise; + +export function GetVirtualMemory():Promise; + export function ScanDir(arg1:string):Promise>; diff --git a/app/wails/frontend/wailsjs/go/system/InfoUtils.js b/app/wails/frontend/wailsjs/go/system/InfoUtils.js index 9c0e487..dc2cda5 100644 --- a/app/wails/frontend/wailsjs/go/system/InfoUtils.js +++ b/app/wails/frontend/wailsjs/go/system/InfoUtils.js @@ -2,10 +2,22 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +export function GetAllProcessPid() { + return window['go']['system']['InfoUtils']['GetAllProcessPid'](); +} + export function GetCpuInfo() { return window['go']['system']['InfoUtils']['GetCpuInfo'](); } +export function GetCpuTimes() { + return window['go']['system']['InfoUtils']['GetCpuTimes'](); +} + +export function GetCpuUsage() { + return window['go']['system']['InfoUtils']['GetCpuUsage'](); +} + export function GetDiskPartitions() { return window['go']['system']['InfoUtils']['GetDiskPartitions'](); } @@ -14,10 +26,26 @@ export function GetDiskUsage(arg1) { return window['go']['system']['InfoUtils']['GetDiskUsage'](arg1); } +export function GetIOCounters() { + return window['go']['system']['InfoUtils']['GetIOCounters'](); +} + export function GetNetWorkConnection() { return window['go']['system']['InfoUtils']['GetNetWorkConnection'](); } +export function GetProcessInfo(arg1) { + return window['go']['system']['InfoUtils']['GetProcessInfo'](arg1); +} + +export function GetSwapMemory() { + return window['go']['system']['InfoUtils']['GetSwapMemory'](); +} + +export function GetVirtualMemory() { + return window['go']['system']['InfoUtils']['GetVirtualMemory'](); +} + export function ScanDir(arg1) { return window['go']['system']['InfoUtils']['ScanDir'](arg1); } diff --git a/app/wails/go.mod b/app/wails/go.mod index a23ae76..a594de4 100644 --- a/app/wails/go.mod +++ b/app/wails/go.mod @@ -9,6 +9,7 @@ require ( github.com/go-playground/locales v0.14.1 github.com/go-playground/universal-translator v0.18.1 github.com/go-playground/validator/v10 v10.14.1 + github.com/gookit/goutil v0.6.11 github.com/mutecomm/go-sqlcipher/v4 v4.4.2 github.com/pelletier/go-toml/v2 v2.0.8 github.com/shirou/gopsutil v2.21.11+incompatible diff --git a/app/wails/go.sum b/app/wails/go.sum index 94ce1d2..42f2b4f 100644 --- a/app/wails/go.sum +++ b/app/wails/go.sum @@ -162,6 +162,9 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE= +github.com/gookit/goutil v0.6.11 h1:615nIGRpQHFmgJ1oaA48q/z7bTx6KzMvHmKTsp21T2E= +github.com/gookit/goutil v0.6.11/go.mod h1:bU9ghaM9uW23x2+jB0WcywRsFGbIP0hvdIKYl2OMiog= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= @@ -494,6 +497,7 @@ github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4X github.com/wailsapp/wails/v2 v2.5.1 h1:mfG+2kWqQXYOwdgI43HEILjOZDXbk5woPYI3jP2b+js= github.com/wailsapp/wails/v2 v2.5.1/go.mod h1:jbOZbcr/zm79PxXxAjP8UoVlDd9wLW3uDs+isIthDfs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= diff --git a/app/wails/pkg/system/cpu.go b/app/wails/pkg/system/cpu.go index bd99e9e..e5ce4c9 100644 --- a/app/wails/pkg/system/cpu.go +++ b/app/wails/pkg/system/cpu.go @@ -2,9 +2,20 @@ package system import ( "github.com/shirou/gopsutil/cpu" + "time" ) -func GetCpuInfo() []cpu.InfoStat { +func (i *InfoUtils) GetCpuInfo() []cpu.InfoStat { infoStats, _ := cpu.Info() return infoStats } + +func (i *InfoUtils) GetCpuUsage() []float64 { + info, _ := cpu.Percent(time.Second, false) + return info +} + +func (i *InfoUtils) GetCpuTimes() []cpu.TimesStat { + info, _ := cpu.Times(false) + return info +} diff --git a/app/wails/pkg/system/disk.go b/app/wails/pkg/system/disk.go index 23e3855..2f6e4c7 100644 --- a/app/wails/pkg/system/disk.go +++ b/app/wails/pkg/system/disk.go @@ -7,19 +7,17 @@ import ( "time" ) -const TypeDisk = "disk" - -func GetDiskPartitions() []disk.PartitionStat { +func (i *InfoUtils) GetDiskPartitions() []disk.PartitionStat { partitions, _ := disk.Partitions(true) return partitions } -func GetDiskUsage(diskPath string) *disk.UsageStat { +func (i *InfoUtils) GetDiskUsage(diskPath string) *disk.UsageStat { usageStat, _ := disk.Usage(diskPath) return usageStat } -func GetIOCounters() map[string]disk.IOCountersStat { +func (i *InfoUtils) GetIOCounters() map[string]disk.IOCountersStat { info, _ := disk.IOCounters() return info } @@ -33,7 +31,7 @@ type FileEntry struct { Size int64 } -func ScanDir(path string) ([]*FileEntry, error) { +func (i *InfoUtils) ScanDir(path string) ([]*FileEntry, error) { entries, err := os.ReadDir(path) data := make([]*FileEntry, 0, len(entries)) for _, entry := range entries { diff --git a/app/wails/pkg/system/memory.go b/app/wails/pkg/system/memory.go index 220abf0..49c45f9 100644 --- a/app/wails/pkg/system/memory.go +++ b/app/wails/pkg/system/memory.go @@ -2,12 +2,12 @@ package system import "github.com/shirou/gopsutil/mem" -func GetVirtualMemory() *mem.VirtualMemoryStat { +func (i *InfoUtils) GetVirtualMemory() *mem.VirtualMemoryStat { stat, _ := mem.VirtualMemory() return stat } -func GetSwapMemory() *mem.SwapMemoryStat { +func (i *InfoUtils) GetSwapMemory() *mem.SwapMemoryStat { stat, _ := mem.SwapMemory() return stat } diff --git a/app/wails/pkg/system/network.go b/app/wails/pkg/system/network.go index c3b7c83..0208a95 100644 --- a/app/wails/pkg/system/network.go +++ b/app/wails/pkg/system/network.go @@ -2,7 +2,7 @@ package system import "github.com/shirou/gopsutil/net" -func GetNetWorkConnection() []net.ConnectionStat { +func (i *InfoUtils) GetNetWorkConnection() []net.ConnectionStat { info, _ := net.Connections("all") return info } diff --git a/app/wails/pkg/system/process.go b/app/wails/pkg/system/process.go index 500d46c..0d31050 100644 --- a/app/wails/pkg/system/process.go +++ b/app/wails/pkg/system/process.go @@ -2,12 +2,12 @@ package system import "github.com/shirou/gopsutil/process" -func GetAllProcessPid() []int32 { +func (i *InfoUtils) GetAllProcessPid() []int32 { pidList, _ := process.Pids() return pidList } -func GetProcessInfo(pid int32) *process.Process { +func (i *InfoUtils) GetProcessInfo(pid int32) *process.Process { info, _ := process.NewProcess(pid) return info } diff --git a/app/wails/pkg/system/system.go b/app/wails/pkg/system/system.go index 23d158c..91430c3 100644 --- a/app/wails/pkg/system/system.go +++ b/app/wails/pkg/system/system.go @@ -1,30 +1,4 @@ package system -import ( - "github.com/shirou/gopsutil/cpu" - "github.com/shirou/gopsutil/disk" - "github.com/shirou/gopsutil/net" -) - type InfoUtils struct { } - -func (i *InfoUtils) GetCpuInfo() []cpu.InfoStat { - return GetCpuInfo() -} - -func (i *InfoUtils) GetDiskPartitions() []disk.PartitionStat { - return GetDiskPartitions() -} - -func (i *InfoUtils) GetDiskUsage(diskPath string) *disk.UsageStat { - return GetDiskUsage(diskPath) -} - -func (i *InfoUtils) ScanDir(path string) ([]*FileEntry, error) { - return ScanDir(path) -} - -func (i *InfoUtils) GetNetWorkConnection() []net.ConnectionStat { - return GetNetWorkConnection() -} diff --git a/app/wails/pkg/system/system_test.go b/app/wails/pkg/system/system_test.go index 474ed04..10aad39 100644 --- a/app/wails/pkg/system/system_test.go +++ b/app/wails/pkg/system/system_test.go @@ -2,37 +2,39 @@ package system import ( "fmt" + "github.com/gookit/goutil/jsonutil" "path/filepath" - "skapp/backend/utils" "testing" ) +var i = &InfoUtils{} + func TestCpu(t *testing.T) { - fmt.Println(GetCpuInfo()) + fmt.Println(i.GetCpuInfo()) } func TestMemory(t *testing.T) { - fmt.Println(GetVirtualMemory()) - fmt.Println(GetSwapMemory()) + fmt.Println(i.GetVirtualMemory()) + fmt.Println(i.GetSwapMemory()) } func TestDisk(t *testing.T) { - partitions := GetDiskPartitions() + partitions := i.GetDiskPartitions() fmt.Println(partitions) for _, partition := range partitions { - fmt.Println(GetDiskUsage(partition.Device)) + fmt.Println(i.GetDiskUsage(partition.Device)) } - fmt.Println(GetIOCounters()) + fmt.Println(i.GetIOCounters()) } func TestNetwork(t *testing.T) { - fmt.Println(GetNetWorkConnection()) + fmt.Println(i.GetNetWorkConnection()) } func TestProcess(t *testing.T) { - processList := GetAllProcessPid() + processList := i.GetAllProcessPid() for _, pid := range processList { - fmt.Println(GetProcessInfo(pid)) + fmt.Println(i.GetProcessInfo(pid)) } } @@ -43,12 +45,13 @@ func TestScanDir(t *testing.T) { fmt.Println(err) } - data, err := ScanDir(path) + data, err := i.ScanDir(path) if err != nil { fmt.Println(err) } for _, entry := range data { - fmt.Printf("%+v\n", utils.Json(entry)) + str, _ := jsonutil.Encode(entry) + fmt.Printf("%+v\n", str) } }