| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | 	"oc-schedulerd/conf" | 
					
						
							| 
									
										
										
										
											2024-08-09 18:44:33 +02:00
										 |  |  | 	"os/exec" | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/rs/zerolog" | 
					
						
							| 
									
										
										
										
											2024-08-09 18:44:33 +02:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-07-29 15:46:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | type LocalMonitor struct { | 
					
						
							| 
									
										
										
										
											2024-10-02 14:38:51 +02:00
										 |  |  | 	LokiURL     string | 
					
						
							|  |  |  | 	KubeURL     string | 
					
						
							|  |  |  | 	ExecutionID string | 
					
						
							| 
									
										
										
										
											2025-02-05 08:38:50 +01:00
										 |  |  | 	PeerID      string | 
					
						
							| 
									
										
										
										
											2024-10-02 14:38:51 +02:00
										 |  |  | 	Duration    int | 
					
						
							|  |  |  | 	Logger      zerolog.Logger | 
					
						
							| 
									
										
										
										
											2024-07-29 15:46:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | func (lm *LocalMonitor) LaunchLocalMonitor() { | 
					
						
							| 
									
										
										
										
											2024-08-21 14:20:13 +02:00
										 |  |  | 	if lm.LokiURL == "" || lm.KubeURL == "" || lm.ExecutionID == "" { | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | 		lm.Logger.Error().Msg("Missing parameter in LocalMonitor") | 
					
						
							| 
									
										
										
										
											2024-07-29 15:46:44 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// For dev purposes, in prod KubeURL must be a kube API's URL | 
					
						
							| 
									
										
										
										
											2024-08-20 15:24:46 +02:00
										 |  |  | 	if lm.KubeURL != "localhost" { | 
					
						
							| 
									
										
										
										
											2024-08-09 18:44:33 +02:00
										 |  |  | 		lm.execRemoteKube() | 
					
						
							| 
									
										
										
										
											2024-08-20 15:24:46 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		lm.execLocalKube() | 
					
						
							| 
									
										
										
										
											2024-07-29 15:46:44 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | func (lm *LocalMonitor) execLocalKube() { | 
					
						
							| 
									
										
										
										
											2025-02-17 16:55:01 +01:00
										 |  |  | 	args := []string{"-e", lm.ExecutionID, "-p", lm.PeerID, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, | 
					
						
							|  |  |  | 		"-d", conf.GetConfig().DBName} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if conf.GetConfig().Mode == "kubernetes" { | 
					
						
							|  |  |  | 		args = append(args, []string{"-M", conf.GetConfig().Mode, "-H", conf.GetConfig().KubeHost, "-P", conf.GetConfig().KubePort, | 
					
						
							|  |  |  | 			"-C", conf.GetConfig().KubeCert, "-D", conf.GetConfig().KubeData, "-c", conf.GetConfig().KubeCA}...) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-08-20 16:14:10 +02:00
										 |  |  | 	if lm.Duration > 0 { | 
					
						
							|  |  |  | 		args = append(args, "-t", fmt.Sprintf("%d", lm.Duration)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	cmd := exec.Command(conf.GetConfig().MonitorPath, args...) | 
					
						
							| 
									
										
										
										
											2024-10-15 11:18:40 +02:00
										 |  |  | 	fmt.Printf("Command : %v\n", cmd) | 
					
						
							| 
									
										
										
										
											2024-08-12 16:09:30 +02:00
										 |  |  | 	err := cmd.Start() | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-08-21 14:20:13 +02:00
										 |  |  | 		lm.Logger.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error()) | 
					
						
							| 
									
										
										
										
											2024-08-09 18:44:33 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-07-29 15:46:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 11:42:26 +02:00
										 |  |  | // TODO : implement this | 
					
						
							| 
									
										
										
										
											2024-10-02 14:38:51 +02:00
										 |  |  | func (lm *LocalMonitor) execRemoteKube() {} |