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
|
2023-08-30 19:24:23 +03:00
|
|
|
func (p plug) ResourceUsage() map[string]interface{} {
|
2023-08-30 22:31:58 +03:00
|
|
|
var system osinfo.System
|
|
|
|
system.GetSystemInfo()
|
2023-08-30 19:24:23 +03:00
|
|
|
|
|
|
|
data := map[string]interface{}{
|
|
|
|
// CPU Information
|
2023-08-30 22:31:58 +03:00
|
|
|
"CPU Physical Core Count": system.CPU.Cores,
|
|
|
|
// "CPU Logical Core Count": system.CPU.Logical_core_count, // TODO
|
|
|
|
// "CPU Actual Hz": system.CPU.ActualHz, // TODO
|
|
|
|
// "CPU Advertised Hz": system.CPU.Hz_advertised, // TODO
|
|
|
|
// "Processor": system.CPU.Brand, // TODO
|
2023-08-30 19:24:23 +03:00
|
|
|
|
|
|
|
// Memory Information
|
2023-08-30 22:31:58 +03:00
|
|
|
"Total Memory": system.Memory.Total,
|
|
|
|
"Usage": system.Memory.Used,
|
2023-08-30 19:24:23 +03:00
|
|
|
|
|
|
|
// Disk Information
|
2023-08-30 22:31:58 +03:00
|
|
|
"Total Disk": system.Disk.Total,
|
|
|
|
"Usage Disk": system.Disk.Used,
|
|
|
|
"Device": system.Disk.Devices,
|
2023-08-14 15:43:45 +03:00
|
|
|
}
|
2023-08-30 19:24:23 +03:00
|
|
|
|
|
|
|
// TODO see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/resource_info_fetcher.py
|
2023-08-14 15:43:45 +03:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2023-08-30 19:24:23 +03:00
|
|
|
// return general Agent system information
|
|
|
|
//
|
|
|
|
// these values changes rarely, see ResourceUsage() function for instant resource usage information
|
2023-08-24 17:44:01 +03:00
|
|
|
func (p plug) AgentInfo() map[string]interface{} {
|
2023-08-30 22:31:58 +03:00
|
|
|
var system osinfo.System
|
|
|
|
system.GetSystemInfo()
|
2023-08-30 19:24:23 +03:00
|
|
|
|
|
|
|
// Common data
|
2023-08-14 15:43:45 +03:00
|
|
|
data := map[string]interface{}{
|
2023-08-30 19:24:23 +03:00
|
|
|
"System": runtime.GOOS,
|
2023-08-30 22:31:58 +03:00
|
|
|
"DiskSpaceTotal": system.Disk.Total,
|
|
|
|
"MemoryTotal": system.Memory.Total,
|
2023-08-30 19:24:23 +03:00
|
|
|
// TODO "AhenkVersion": get Ahenk self version here
|
|
|
|
|
2023-08-30 22:31:58 +03:00
|
|
|
"Name": system.OS.Name,
|
|
|
|
"Distribution": system.OS.Distro,
|
|
|
|
"Arch": system.OS.Arch,
|
|
|
|
"Version": system.OS.Version,
|
|
|
|
"Hostname": system.Node.Hostname,
|
|
|
|
"KernelVersion": system.Kernel.Version,
|
|
|
|
"KernelRelease": system.Kernel.Release,
|
2023-08-30 19:24:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2023-08-14 15:43:45 +03:00
|
|
|
return data
|
|
|
|
}
|