oc-schedulerd/daemons/execute_monitor_local.go
2024-10-15 11:18:40 +02:00

47 lines
1.1 KiB
Go

package daemons
import (
"fmt"
"oc-schedulerd/conf"
"os/exec"
"github.com/rs/zerolog"
)
type LocalMonitor struct {
LokiURL string
KubeURL string
ExecutionID string
Duration int
Logger zerolog.Logger
}
func (lm *LocalMonitor) LaunchLocalMonitor() {
if lm.LokiURL == "" || lm.KubeURL == "" || lm.ExecutionID == "" {
lm.Logger.Error().Msg("Missing parameter in LocalMonitor")
}
// For dev purposes, in prod KubeURL must be a kube API's URL
if lm.KubeURL != "localhost" {
lm.execRemoteKube()
} else {
lm.execLocalKube()
}
}
func (lm *LocalMonitor) execLocalKube() {
args := []string{"-e", lm.ExecutionID, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, "-d", conf.GetConfig().DBName}
if lm.Duration > 0 {
args = append(args, "-t", fmt.Sprintf("%d", lm.Duration))
}
cmd := exec.Command(conf.GetConfig().MonitorPath, args...)
fmt.Printf("Command : %v\n", cmd)
err := cmd.Start()
if err != nil {
lm.Logger.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error())
}
}
// TODO : implement this
func (lm *LocalMonitor) execRemoteKube() {}