oc-schedulerd/daemons/execute_monitor_local.go

74 lines
1.4 KiB
Go
Raw Normal View History

2024-07-29 15:46:44 +02:00
package daemons
2024-08-09 18:44:33 +02:00
import (
2024-08-20 15:24:46 +02:00
"fmt"
"oc-schedulerd/conf"
2024-08-09 18:44:33 +02:00
"os/exec"
"github.com/rs/zerolog"
2024-08-09 18:44:33 +02:00
)
2024-07-29 15:46:44 +02:00
type LocalMonitor struct {
2024-10-02 14:38:51 +02:00
ExecutionID string
PeerID string
2024-10-02 14:38:51 +02:00
Duration int
LokiUrl string
MongoUrl string
DBName string
2024-07-29 15:46:44 +02:00
}
func NewLocalMonitor(executionsId string, peerId string, duration int) (Executor){
return &LocalMonitor{
ExecutionID: executionsId,
PeerID: peerId,
Duration: duration,
LokiUrl: conf.GetConfig().LokiUrl,
MongoUrl: conf.GetConfig().MongoUrl,
DBName: conf.GetConfig().DBName,
2024-07-29 15:46:44 +02:00
}
}
// func (lm *LocalMonitor) LaunchLocalMonitor() {
// if lm.ExecutionID == "" {
// lm.Logger.Error().Msg("Missing parameter in LocalMonitor")
// }
// }
func (lm *LocalMonitor) PrepareMonitorExec() []string {
2025-02-18 15:00:17 +01:00
args := []string{
"-e", lm.ExecutionID,
"-p", lm.PeerID,
"-u", lm.LokiUrl,
"-m", lm.MongoUrl,
"-d", lm.DBName,
2025-02-18 15:00:17 +01:00
}
2025-02-17 16:55:01 +01:00
2024-08-20 16:14:10 +02:00
if lm.Duration > 0 {
args = append(args, "-t", fmt.Sprintf("%d", lm.Duration))
}
return args
}
func (lm *LocalMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
2024-08-20 16:14:10 +02:00
cmd := exec.Command(conf.GetConfig().MonitorPath, args...)
2024-10-15 11:18:40 +02:00
fmt.Printf("Command : %v\n", cmd)
stdoutMonitord, err := cmd.StdoutPipe()
if err != nil {
l.Error().Msg("Could not retrieve stdoutpipe for execution of oc-monitord" + err.Error())
}
err = cmd.Start()
if err != nil {
l.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error())
2024-08-09 18:44:33 +02:00
}
logExecution(stdoutMonitord, l)
2024-07-29 15:46:44 +02:00
}