[agent-go] [executor] real time executor
This commit is contained in:
40
agent-go/executor/RealTimeExecutor.go
Normal file
40
agent-go/executor/RealTimeExecutor.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package executor
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func ReadTimeOutput(singleLineCommand []string) {
|
||||
|
||||
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go copyOutput(stdout)
|
||||
go copyOutput(stderr)
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func copyOutput(r io.Reader) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
fmt.Println(scanner.Text())
|
||||
}
|
||||
}
|
||||
13
agent-go/executor/RealTimeExecutor_test.go
Normal file
13
agent-go/executor/RealTimeExecutor_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package executor
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestReadTimeOutput(t *testing.T) {
|
||||
strings := []string{
|
||||
"/bin/bash",
|
||||
"/root/simple.sh",
|
||||
}
|
||||
|
||||
ReadTimeOutput(strings)
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package status
|
||||
|
||||
import (
|
||||
logger2 "agent-go/logger"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var log = logger2.Log
|
||||
@@ -13,6 +15,18 @@ type AgentStatus struct {
|
||||
DiskStatus *DiskStatus
|
||||
}
|
||||
|
||||
func ConvertToFormat(eventData float64) string {
|
||||
duration := time.Duration(eventData) * time.Second
|
||||
|
||||
fmt.Println(duration)
|
||||
|
||||
hours := int(duration.Hours())
|
||||
minutes := int(duration.Minutes()) % 60
|
||||
seconds := int(duration.Seconds()) % 60
|
||||
milliseconds := duration.Milliseconds() % 1000
|
||||
return fmt.Sprintf("%02d:%02d:%02d,%03d", hours, minutes, seconds, milliseconds)
|
||||
}
|
||||
|
||||
func Ping() string {
|
||||
return "PONG"
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConvertToFormat(t *testing.T) {
|
||||
|
||||
convertToFormat := ConvertToFormat(99.92)
|
||||
|
||||
fmt.Println(convertToFormat)
|
||||
}
|
||||
|
||||
func TestReportAppStatus(t *testing.T) {
|
||||
|
||||
agentStatus := ReportAppStatus()
|
||||
|
||||
Reference in New Issue
Block a user