From e16901942e2715d3e51ef879688117327289ffb1 Mon Sep 17 00:00:00 2001 From: Aneesh Puttur Date: Mon, 22 Jul 2024 08:53:22 -0400 Subject: [PATCH] Add process down indicator for ts2phc Signed-off-by: Aneesh Puttur --- pkg/daemon/daemon.go | 12 ++++++++++++ pkg/daemon/metrics.go | 2 +- pkg/event/event.go | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 4e1b73b08..38a096a28 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -871,6 +871,7 @@ func (p *ptpProcess) cmdRun(stdoutToSocket bool) { } else { processStatus(nil, p.name, p.messageTag, PtpProcessDown) } + p.updateGMStatusOnProcessDown(p.name) time.Sleep(connectionRetryInterval) // Delay to prevent flooding restarts if startup fails // Don't restart after termination @@ -1153,3 +1154,14 @@ func (p *ptpProcess) replaceClockID(input string) (output string) { output = clockIDRegEx.ReplaceAllString(input, iface) return output } + +// updateGMStatusOnProcessDown send events when ts2phc process is down by +// send event to EventHandler +func (p *ptpProcess) updateGMStatusOnProcessDown(process string) { + // need to update GM status for following process kill for ts2phc + if process == ts2phcProcessName { + // ts2phc process dead should update GM-STATUS + iface := p.ifaces.GetGMInterface().Name + p.ProcessTs2PhcEvents(faultyOffset, ts2phcProcessName, iface, map[event.ValueType]interface{}{event.PROCESS_STATUS: int64(0)}) + } +} diff --git a/pkg/daemon/metrics.go b/pkg/daemon/metrics.go index a905333cd..9703101a0 100644 --- a/pkg/daemon/metrics.go +++ b/pkg/daemon/metrics.go @@ -371,7 +371,7 @@ func extractRegularMetrics(configName, processName, output string, ifaces config } output = strings.Replace(output, "path", "", 1) - replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ", " phc ", " ", " sys ", "") + replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ", " phc ", " ", " sys ", " ") output = replacer.Replace(output) index := strings.Index(output, configName) diff --git a/pkg/event/event.go b/pkg/event/event.go index 252239d6b..c76803262 100644 --- a/pkg/event/event.go +++ b/pkg/event/event.go @@ -31,6 +31,7 @@ const ( PHASE_STATUS ValueType = "phase_status" FREQUENCY_STATUS ValueType = "frequency_status" NMEA_STATUS ValueType = "nmea_status" + PROCESS_STATUS ValueType = "process_status" PPS_STATUS ValueType = "pps_status" GM_INTERFACE_UNKNOWN string = "unknown" )