[agent-go] [status] - start to unit

This commit is contained in:
zeaslity
2023-04-23 14:15:12 +08:00
parent 6b9487b9b2
commit c5143d2d59
8 changed files with 139 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ import (
"os/exec"
)
func ReadTimeOutput(singleLineCommand []string) {
func ReadTimeCommandExecutor(singleLineCommand []string) {
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
stdout, err := cmd.StdoutPipe()

View File

@@ -14,7 +14,8 @@ type DiskStatus struct {
}
func GetDiskStatus() *DiskStatus {
var ds *DiskStatus
ds := &DiskStatus{}
// Get disk usage
du, _ := disk.Usage("/")

View File

@@ -1,6 +1,7 @@
package status
import (
"encoding/json"
"fmt"
"testing"
)
@@ -11,4 +12,11 @@ func TestGetDiskStatus(t *testing.T) {
fmt.Printf("Total: %v, Used: %v\n", ds.Total, ds.Used)
fmt.Printf("Logical Disks: %v\n", ds.LogicalDisk)
marshalIndent, err := json.MarshalIndent(ds, "", " ")
if err != nil {
fmt.Printf("error")
}
fmt.Println(string(marshalIndent))
}

View File

@@ -14,7 +14,7 @@ type MemoryStatus struct {
}
func GetMemoryStatus() (*MemoryStatus, error) {
var memoryStatus *MemoryStatus
memoryStatus := &MemoryStatus{}
virtualMemoryStat, err := mem.VirtualMemory()
if err != nil {

View File

@@ -1,6 +1,7 @@
package status
import (
"encoding/json"
"fmt"
"testing"
)
@@ -17,4 +18,11 @@ func TestGetMemoryStatus(t *testing.T) {
fmt.Printf("Available Memory: %s\n", FormatMemorySize(memoryStatus.AvailableMemory))
fmt.Printf("Total Virtual Memory: %s\n", FormatMemorySize(memoryStatus.TotalVirtualMemory))
fmt.Printf("Used Virtual Memory: %s\n", FormatMemorySize(memoryStatus.UsedVirtualMemory))
marshalIndent, err := json.MarshalIndent(memoryStatus, "", " ")
if err != nil {
fmt.Printf("error")
}
fmt.Println(string(marshalIndent))
}