update osinfo and resource usage plugin

This commit is contained in:
Aliberk Sandıkçı 2023-08-30 19:24:23 +03:00
parent 21ebd0a25c
commit fb59a6364e
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
10 changed files with 292 additions and 120 deletions

View File

@ -1,8 +1,11 @@
package main
import (
"encoding/json"
"log"
"time"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
)
// General Functions/Methods that each plugin has
@ -13,6 +16,7 @@ type PlugGeneral interface {
// plugins/resources
type Resources interface {
AgentInfo() map[string]interface{}
ResourceUsage() map[string]interface{}
}
// plugins/resources
@ -50,21 +54,28 @@ func PluginManager(params ...string) {
// checkPlugin(res, ok)
// Run plugins concurrently and log out
go logPlugin("AgentInfo", resources.AgentInfo(), true)
for {
go logPlugin("AgentInfo", resources.AgentInfo())
go logPlugin("ResourceUsage", resources.ResourceUsage(), true)
// FILLME Running/Log out a plugin, template
// go logPlugin("InfoAboutFunction", pluginName.Function() )
// go logPlugin("InfoAboutFunction", pluginName.Function(), true)
time.Sleep(30 * time.Second)
}
}
// Logs plugin outputs.
func logPlugin(title string, mp map[string]interface{}) {
func logPlugin(title string, mp map[string]interface{}, toJson bool) {
log.Printf("\n----- %v -----\n", title)
for i, v := range mp {
log.Printf("%v: %v\n", i, v)
if toJson {
data, err := json.MarshalIndent(&mp, "", " ")
utils.Check(err)
log.Println(string(data))
} else {
for i, v := range mp {
log.Printf("%v: %v\n", i, v)
}
}
}

9
go.mod
View File

@ -4,18 +4,21 @@ go 1.20
require (
github.com/sevlyar/go-daemon v0.1.6
github.com/zcalusic/sysinfo v1.0.1
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
golang.org/x/text v0.12.0
)
require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zcalusic/sysinfo v1.0.1 // indirect
golang.org/x/text v0.12.0 // indirect
)
require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // direct
golang.org/x/sys v0.10.0 // indirect
golang.org/x/sys v0.11.0 // direct
)

41
go.sum
View File

@ -1,34 +1,19 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/ricochet2200/go-disk-usage v1.1.2 h1:5mEUQLwZXKYiEl2d4CXNi8fqsVGzGQNTaG6rKDVSTsQ=
github.com/ricochet2200/go-disk-usage v1.1.2/go.mod h1:yhevTRDiduxPJHQDCtlqUn53ojFPkRh/mKhMUzQUCpc=
github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285 h1:d54EL9l+XteliUfUCGsEwwuk65dmmxX85VXF+9T6+50=
github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285/go.mod h1:fxIDly1xtudczrZeOOlfaUvd2OPb2qZAPuWdU2BsBTk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs=
github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.23.7 h1:C+fHO8hfIppoJ1WdsVm1RoI0RwXoNdfTK7yWXV0wVj4=
github.com/shirou/gopsutil/v3 v3.23.7/go.mod h1:c4gnmoRC0hQuaLqvxnx1//VXQ0Ms/X9UnJF8pddY5z4=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zcalusic/sysinfo v1.0.1 h1:cVh8q3codjh43AGRTa54dJ2Zq+qPejv8n2VWpxKViwc=
@ -36,13 +21,9 @@ github.com/zcalusic/sysinfo v1.0.1/go.mod h1:LxwKwtQdbTIQc65drhjQzYzt0o7jfB80Lrr
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

41
pkg/osinfo/cpu.go Normal file
View File

@ -0,0 +1,41 @@
package osinfo
import (
"runtime"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
"github.com/shirou/gopsutil/cpu"
"github.com/zcalusic/sysinfo"
)
type CPU struct {
Vendor string `json:"vendor,omitempty"`
Model string `json:"model,omitempty"`
Speed uint `json:"speed,omitempty"` // CPU clock rate in MHz
Cache uint `json:"cache,omitempty"` // CPU cache size in KB
Cpus uint `json:"cpus,omitempty"` // number of physical CPUs
Cores uint `json:"cores,omitempty"` // number of physical CPU cores
Threads uint `json:"threads,omitempty"` // number of logical (HT) CPU cores
}
func (h *Hardware) getCPUInfo() {
if runtime.GOOS == "linux" {
var si sysinfo.SysInfo
si.GetSysInfo()
h.CPU.Vendor = si.CPU.Vendor
h.CPU.Model = si.CPU.Model
h.CPU.Speed = si.CPU.Speed
h.CPU.Cache = si.CPU.Cache
h.CPU.Cpus = si.CPU.Cpus
h.CPU.Cores = si.CPU.Cores
h.CPU.Threads = si.CPU.Threads
} else {
cpuInfo, err := cpu.Info()
utils.Check(err)
h.CPU.Vendor = cpuInfo[0].VendorID
h.CPU.Vendor = cpuInfo[0].Model
// h.CPU.Vendor = cpuInfo[0].Speed // TODO
}
}

53
pkg/osinfo/disk.go Normal file
View File

@ -0,0 +1,53 @@
package osinfo
import (
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
"github.com/shirou/gopsutil/disk"
)
type Disk struct {
Devices string `json:"devices,omitempty"` // physical disk devices as string
Total float64 `json:"total,omitempty"` // Total Disk size in GiB
Used float64 `json:"used,omitempty"` // Used Disk size in GiB
Free float64 `json:"free,omitempty"` // Free Disk size in GiB
}
func (h *Hardware) getDiskInfo() {
for _, v := range GetDisks() {
h.Disk.Devices += v.Device
}
h.Disk.Total = GetDiskUsage()["spaceTotal"]
h.Disk.Used = GetDiskUsage()["usedTotal"]
h.Disk.Free = GetDiskUsage()["usedFree"]
}
// return all physical disks, USB and CD-ROM devices
//
// An example output:
// device: /dev/example, mountpoint: /, fstype: ext4, opts:rw,noatime
func GetDisks() []disk.PartitionStat {
parts, err := disk.Partitions(false)
utils.Check(err)
return parts
}
// return disk usage as GiB
//
// TODO different functions for all disks / a specified disk?
// FIXME Wrong Disk values for docker !!! (probably because counting also virtual mountpoints?)
func GetDiskUsage() map[string]float64 {
var totalSize, freeSize, usedSize uint64
for _, part := range GetDisks() {
u, err := disk.Usage(part.Mountpoint)
utils.Check(err)
totalSize += u.Total
freeSize += u.Free
usedSize += u.Used
}
return map[string]float64{
"spaceTotal": utils.Byte2GiB(totalSize),
"freeTotal": utils.Byte2GiB(freeSize),
"usedTotal": utils.Byte2GiB(usedSize),
}
}

View File

@ -4,55 +4,59 @@ import (
"syscall"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
"github.com/zcalusic/sysinfo"
)
const KB = uint64(1024)
// return kernel information as string map with calling syscall (like uname command)
func GetKernelInfo() map[string]string {
type Hardware struct {
CPU CPU `json:"cpu"`
Memory Memory `json:"memory"`
Disk Disk `json:"disk"`
// Node Node `json:"node"`
// Kernel Kernel `json:"kernel"`
OS OS `json:"OS"`
}
func (h *Hardware) GetHardwareInfo() {
h.getCPUInfo()
h.getMemoryInfo()
h.getDiskInfo()
h.getOSInfo()
}
// return linux Kernel, Node and System Information
//
// REVIEW are there any command that also compatible with windows?
func GetLinuxInfo() map[string]map[string]interface{} {
var uname syscall.Utsname
if err := syscall.Uname(&uname); err != nil {
panic(err)
}
return map[string]string{
"Sysname": utils.Byte2String(uname.Sysname[:]),
"Nodename": utils.Byte2String(uname.Nodename[:]),
"Release": utils.Byte2String(uname.Release[:]),
"Version": utils.Byte2String(uname.Version[:]),
"Machine": utils.Byte2String(uname.Machine[:]),
"Domainname": utils.Byte2String(uname.Domainname[:]),
}
}
// return all physical disks, USB and CD-ROM devices
//
// An example output:
// device: /dev/example, mountpoint: /, fstype: ext4, opts:rw,noatime
func GetDisks() []disk.PartitionStat {
parts, err := disk.Partitions(false)
utils.Check(err)
return parts
}
// return disk usage as GiB
//
// TODO different functions for all disks / a specified disk?
// FIXME Wrong Disk values for docker !!! (probably because counting also virtual mountpoints?)
func GetDiskUsage() map[string]float64 {
var totalSize, freeSize, usedSize uint64
for _, part := range GetDisks() {
u, err := disk.Usage(part.Mountpoint)
utils.Check(err)
totalSize += u.Total
freeSize += u.Free
usedSize += u.Used
}
return map[string]float64{
"total": utils.Byte2GiB(totalSize),
"free": utils.Byte2GiB(freeSize),
"used": utils.Byte2GiB(usedSize),
var si sysinfo.SysInfo
si.GetSysInfo()
return map[string]map[string]interface{}{
"Kernel": {
"Sysname": utils.Byte2String(uname.Sysname[:]),
"Release": si.Kernel.Release,
"Version": si.Kernel.Version,
"Machine": si.Kernel.Architecture,
},
"Node": {
"Domainname": utils.Byte2String(uname.Domainname[:]),
"Hostname": si.Node.Hostname,
"MachineID": si.Node.MachineID,
"Timezone": si.Node.Timezone,
},
"OS": { //REVIEW review info in pardus
"Name": si.OS.Name,
"Vendor": si.OS.Vendor,
"Arch": si.OS.Architecture,
"Version": si.OS.Version,
"Release": si.OS.Release,
},
}
}

31
pkg/osinfo/memory.go Normal file
View File

@ -0,0 +1,31 @@
package osinfo
import (
"runtime"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
"github.com/shirou/gopsutil/mem"
"github.com/zcalusic/sysinfo"
)
type Memory struct {
Type string `json:"type,omitempty"`
Speed uint `json:"speed,omitempty"` // RAM data rate in MT/s
Total float64 `json:"total,omitempty"` // Total RAM size in GiB
Used float64 `json:"used,omitempty"` // Used RAM size in GiB
}
func (h *Hardware) getMemoryInfo() {
memInfo, err := mem.VirtualMemory()
utils.Check(err)
h.Memory.Used = utils.Byte2GiB(memInfo.Used)
h.Memory.Total = utils.Byte2GiB(memInfo.Total)
if runtime.GOOS == "linux" {
var si sysinfo.SysInfo
si.GetSysInfo()
h.Memory.Type = si.Memory.Type
h.Memory.Speed = si.Memory.Speed
}
}

28
pkg/osinfo/os.go Normal file
View File

@ -0,0 +1,28 @@
package osinfo
import (
"runtime"
"github.com/zcalusic/sysinfo"
)
type OS struct {
Name string `json:"name,omitempty"`
Distro string `json:"distro,omitempty"`
Version string `json:"version,omitempty"`
Release string `json:"release,omitempty"`
Arch string `json:"architecture,omitempty"`
}
func (h *Hardware) getOSInfo() {
if runtime.GOOS == "linux" {
var si sysinfo.SysInfo
si.GetSysInfo()
h.OS.Name = si.OS.Name
h.OS.Distro = si.OS.Vendor
h.OS.Version = si.OS.Version
h.OS.Release = si.OS.Release
h.OS.Arch = si.OS.Architecture
}
}

View File

@ -24,6 +24,10 @@ func Byte2GiB(b uint64) float64 {
return float64(float64(b) / (1024 * 1024 * 1024))
}
func MB2GiB(b uint64) float64 {
return float64(float64(b*1000*1000) / (1024 * 1024 * 1024))
}
func CheckPath(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {

View File

@ -12,56 +12,72 @@ type plug string
var ResourcesConnect plug
// return instant resource usage information
func ResourceUsage() map[string]string {
data := map[string]string{
"System": runtime.GOOS, "Release": osinfo.GetKernelInfo()["Release"],
// TODO "Version":
// 'Version': self.Os.distribution_version(), 'Machine': self.Os.architecture(),
// 'CPU Physical Core Count': self.Hardware.Cpu.physical_core_count(),
// 'Total Memory': self.Hardware.Memory.total(),
// 'Usage': self.Hardware.Memory.used(),
// 'Total Disc': self.Hardware.Disk.total(),
// 'Usage Disc': self.Hardware.Disk.used(),
// 'Processor': self.Hardware.Cpu.brand(),
// 'Device': device,
// 'CPU Logical Core Count': self.Hardware.Cpu.logical_core_count(),
// 'CPU Actual Hz': self.Hardware.Cpu.hz_actual(),
// 'CPU Advertised Hz': self.Hardware.Cpu.hz_advertised()
// }
func (p plug) ResourceUsage() map[string]interface{} {
var hardware osinfo.Hardware
hardware.GetHardwareInfo()
data := map[string]interface{}{
// General System Information
"System": runtime.GOOS,
"Release": osinfo.GetLinuxInfo()["Kernel"]["Release"], //needs REVIEW for windows
"Version": osinfo.GetLinuxInfo()["OS"]["Version"], //needs REVIEW for windows
"Machine": osinfo.GetLinuxInfo()["OS"]["Arch"], //needs REVIEW for windows
// CPU Information
"CPU Physical Core Count": hardware.CPU.Cores,
// "CPU Logical Core Count": hardware.CPU.Logical_core_count, // TODO
// "CPU Actual Hz": hardware.CPU.ActualHz, // TODO
// "CPU Advertised Hz": hardware.CPU.Hz_advertised, // TODO
// "Processor": hardware.CPU.Brand, // TODO
// Memory Information
"Total Memory": hardware.Memory.Total,
"Usage": hardware.Memory.Used,
// Disk Information
"Total Disk": hardware.Disk.Total,
"Usage Disk": hardware.Disk.Used,
"Device": hardware.Disk.Devices,
}
// TODO see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/resource_info_fetcher.py
return data
}
// return general Agent information (that changes rarely)
// return general Agent system information
//
// these values changes rarely, see ResourceUsage() function for instant resource usage information
func (p plug) AgentInfo() map[string]interface{} {
var hardware osinfo.Hardware
hardware.GetHardwareInfo()
// Common data
data := map[string]interface{}{
"System": runtime.GOOS, "Release": osinfo.GetKernelInfo()["Release"],
"hostname": osinfo.GetKernelInfo()["Hostname"],
"osMachine": osinfo.GetKernelInfo()["Machine"],
"diskTotal": osinfo.GetDiskUsage()["total"],
"diskUsed": osinfo.GetDiskUsage()["used"],
"diskFree": osinfo.GetDiskUsage()["free"],
"diskUsage": osinfo.GetDiskUsage()["used"] / osinfo.GetDiskUsage()["total"],
"memoryTotal": osinfo.GetMemoryUsage()["total"],
"memoryFree": osinfo.GetMemoryUsage()["free"],
"memoryAvaliable": osinfo.GetMemoryUsage()["avaliable"],
"memoryUsed": osinfo.GetMemoryUsage()["used"],
"memoryCached": osinfo.GetMemoryUsage()["cached"],
"memoryUsage": (osinfo.GetMemoryUsage()["used"] + osinfo.GetMemoryUsage()["cached"]) / osinfo.GetMemoryUsage()["total"], //REVIEW just used/total ?
// TODO is calling all functions one by one slow downs code?
// TODO 'agentVersion': self.get_agent_version(),
// TODO 'ipAddresses': str(self.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''),
// TODO get distrubition name also (pardus,arch,debian,windows10 for example ...)
// TODO 'macAddresses': str(self.Hardware.Network.mac_addresses()).replace('[', '').replace(']', ''),
// TODO 'hardware.systemDefinitions': self.Hardware.system_definitions(),
// TODO 'hardware.monitors': self.Hardware.monitors(),
// TODO 'hardware.screens': self.Hardware.screens(),
// TODO 'hardware.usbDevices': self.Hardware.usb_devices(),
// TODO 'hardware.printers': self.Hardware.printers(),
// TODO 'Device': device,
"System": runtime.GOOS,
"DiskSpaceTotal": hardware.Disk.Total,
"MemoryTotal": hardware.Memory.Total,
// TODO "AhenkVersion": get Ahenk self version here
}
// Linux specific data
if runtime.GOOS == "linux" {
data["Name"] = osinfo.GetLinuxInfo()["OS"]["Name"]
data["Distribution"] = osinfo.GetLinuxInfo()["OS"]["Vendor"]
data["Architecture"] = osinfo.GetLinuxInfo()["OS"]["Arch"]
data["Version"] = osinfo.GetLinuxInfo()["OS"]["Version"]
data["NodeHostname"] = osinfo.GetLinuxInfo()["Node"]["Hostname"]
data["Architecture"] = osinfo.GetLinuxInfo()["Kernel"]["Machine"]
data["KernelVersion"] = osinfo.GetLinuxInfo()["Kernel"]["Version"]
}
// LINK see https://github.com/golang/go/blob/master/src/go/build/syslist.go#L14 for all possible Operating systems
// and https://go.dev/doc/install/source#environment for all possible combinations
// REVIEW is calling all functions one by one slow downs code?
// TODO see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/agent_info.py
return data
}