Skip to content

Commit

Permalink
ready
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedvaziry committed Apr 2, 2024
1 parent aaacb87 commit af48c28
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions cmd/agent.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/vitodeploy/agent/pkg/config"
"github.com/vitodeploy/agent/pkg/cpu"
"github.com/vitodeploy/agent/pkg/disk"
"github.com/vitodeploy/agent/pkg/memory"
)

type Payload struct {
Load float64 `json:"load"`
DiskTotal uint64 `json:"disk_total"`
DiskFree uint64 `json:"disk_free"`
DiskUsed uint64 `json:"disk_used"`
MemoryTotal string `json:"memory_total"`
MemoryFree string `json:"memory_free"`
MemoryUsed string `json:"memory_used"`
}

func main() {
// cfg := config.GetConfig()
cpuInfo := cpu.GetCPUInfo()
diskInfo := disk.GetDiskInfo()
memoryInfo := memory.GetMemoryInfo()
fmt.Println(cpuInfo)
fmt.Println(diskInfo)
fmt.Println(memoryInfo)
cfg := config.GetConfig()
for {
cpuInfo := cpu.GetCPUInfo()
diskInfo := disk.GetDiskInfo()
memoryInfo := memory.GetMemoryInfo()
payload := Payload{
Load: cpuInfo.Load,
DiskTotal: diskInfo.Total,
DiskFree: diskInfo.Free,
DiskUsed: diskInfo.Used,
MemoryTotal: memoryInfo.Total,
MemoryFree: memoryInfo.Free,
MemoryUsed: memoryInfo.Used,
}
jsonPayload, err := json.Marshal(payload)
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", cfg.Url, bytes.NewBuffer(jsonPayload))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Secret", cfg.Secret)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
fmt.Println("Response Status:", resp.Status)
resp.Body.Close()
time.Sleep(time.Minute)
}
}

0 comments on commit af48c28

Please sign in to comment.