2023-08-21 16:45:11 +03:00
|
|
|
package main
|
2023-08-14 15:43:45 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
2023-08-23 22:49:17 +03:00
|
|
|
|
|
|
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/osinfo"
|
2023-08-14 15:43:45 +03:00
|
|
|
)
|
|
|
|
|
2023-08-24 17:44:01 +03:00
|
|
|
type plug string
|
|
|
|
|
|
|
|
// exported plugin Symbol
|
|
|
|
var ResourcesConnect plug
|
2023-08-21 16:45:11 +03:00
|
|
|
|
2023-08-14 15:43:45 +03:00
|
|
|
// return instant resource usage information
|
|
|
|
func ResourceUsage() map[string]string {
|
|
|
|
data := map[string]string{
|
2023-08-25 15:13:52 +03:00
|
|
|
"System": runtime.GOOS, "Release": osinfo.GetKernelInfo()["Release"],
|
|
|
|
// TODO "Version":
|
2023-08-14 15:43:45 +03:00
|
|
|
// '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()
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
// return general Agent information (that changes rarely)
|
2023-08-24 17:44:01 +03:00
|
|
|
func (p plug) AgentInfo() map[string]interface{} {
|
2023-08-14 15:43:45 +03:00
|
|
|
data := map[string]interface{}{
|
2023-08-25 15:13:52 +03:00
|
|
|
"System": runtime.GOOS, "Release": osinfo.GetKernelInfo()["Release"],
|
2023-08-24 17:44:01 +03:00
|
|
|
"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?
|
|
|
|
|
2023-08-14 15:43:45 +03:00
|
|
|
// TODO 'agentVersion': self.get_agent_version(),
|
|
|
|
// TODO 'ipAddresses': str(self.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''),
|
2023-08-24 17:44:01 +03:00
|
|
|
// TODO get distrubition name also (pardus,arch,debian,windows10 for example ...)
|
2023-08-14 15:43:45 +03:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func Info() map[string]string {
|
|
|
|
inf := make(map[string]string)
|
|
|
|
inf["name"] = "resources"
|
2023-08-24 17:44:01 +03:00
|
|
|
inf["version"] = "0.0.2"
|
2023-08-14 15:43:45 +03:00
|
|
|
inf["support"] = "debian"
|
|
|
|
inf["description"] = "Resource Usage Information and Controls"
|
|
|
|
inf["developer"] = "asandikci@aliberksandikci.com.tr"
|
|
|
|
return inf
|
|
|
|
}
|