diff --git a/plugins/ptp_operator/metrics/logparser.go b/plugins/ptp_operator/metrics/logparser.go index c5c26e25..d5ed66e1 100644 --- a/plugins/ptp_operator/metrics/logparser.go +++ b/plugins/ptp_operator/metrics/logparser.go @@ -99,13 +99,16 @@ func extractRegularMetrics(processName, output string) (interfaceName string, pt // phc2sys[4268818.286]: [ptp4l.0.config] CLOCK_REALTIME phc offset -62 s0 freq -78368 delay 1100 // phc2sys[4268818.287]: [ptp4l.0.config] ens5f1 phc offset -92 s0 freq -890 delay 2464 ( this is down) // phc2sys[4268818.287]: [ptp4l.0.config] ens5f0 phc offset -47 s2 freq -2047 delay 2438 - // ts2phc[82674.465]: [ts2phc.0.cfg] nmea delay: 88403525 ns - // ts2phc[82674.465]: [ts2phc.0.cfg] ens2f1 extts index 0 at 1673031129.000000000 corr 0 src 1673031129.911642976 diff 0 - // ts2phc[82674.465]: [ts2phc.0.cfg] ens2f1 master offset 0 s2 freq -0 + // ts2phc[82674.465]: [ts2phc.0.config] nmea delay: 88403525 ns + // ts2phc[82674.465]: [ts2phc.0.config] ens2f1 extts index 0 at 1673031129.000000000 corr 0 src 1673031129.911642976 diff 0 + // ts2phc[82674.465]: [ts2phc.0.config] ens2f1 master offset 0 s2 freq -0 + // ts2phc[521734.693]: [ts2phc.0.config:6] /dev/ptp6 offset 0 s2 freq -0 // 0 1 2 3 4 5 6 7 8 9 10 11 // 1 2 3 4 5 6 7 8 9 // ptp4l 5196819.100 ptp4l.0.config master offset -2162130 s2 freq +22451884 path delay 374976 + // + // ts2phc 522946.693 ts2phc.0.config ens7f0 offset 0 s2 freq -0 index := FindInLogForCfgFileIndex(output) if index == -1 { log.Errorf("config name is not found in log output %s", output) @@ -113,17 +116,20 @@ func extractRegularMetrics(processName, output string) (interfaceName string, pt } output = strings.Replace(output, "path", "", 1) - replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ", "phc", "", "sys", "") + // ts2phc 522946.693 ts2phc.0.config ens7f0 offset 0 s2 freq -0 + // careful ts2phc --> here phc will be replaced so use empty string around the text + replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ", " phc ", " ", " sys ", " ") output = replacer.Replace(output) output = output[index:] fields := strings.Fields(output) - // 0 1 2 3 4 5 6 7 8 - // ptp4l.0.config master offset -2162130 s2 freq +22451884 delay 374976 - // ts2phc.0.cfg ens2f1 master offset 0 s2 freq -0 - // (ts2phc.0.cfg master offset 0 s2 freq -0) - // 0 1 2 3 4 5 6 7 8 + // 0 1 2 3 4 5 6 7 8 + // ptp4l.0.config master offset -2162130 s2 freq +22451884 delay 374976 + // ts2phc.0.config ens2f1 master offset 0 s2 freq -0 + // 0 1 2 3 4 5 6 + // ts2phc.0.config ens7f0 offset 0 s2 freq -0 + // 0 1 2 3 4 5 6 7 // ptp4l.0.config CLOCK_REALTIME offset -62 s0 freq -78368 delay 1100 if len(fields) < 7 { return diff --git a/plugins/ptp_operator/metrics/metrics.go b/plugins/ptp_operator/metrics/metrics.go index 2a955fc7..4623531a 100644 --- a/plugins/ptp_operator/metrics/metrics.go +++ b/plugins/ptp_operator/metrics/metrics.go @@ -181,6 +181,11 @@ func (p *PTPEventManager) ExtractMetrics(msg string) { alias := getAlias(interfaceName) // no event for nmeas status , change in GM will manage ptp events and sync states UpdateNmeaStatusMetrics(processName, alias, status) + } else if strings.Contains(output, "process_status") && + processName == ts2phcProcessName { + // do nothing processDown identifier will update metrics and stats + // but prevent further from reading offsets + return } else if strings.Contains(output, " offset ") { // DPLL has Offset too // ptp4l[5196819.100]: [ptp4l.0.config] master offset -2162130 s2 freq +22451884 path delay 374976 // phc2sys[4268818.286]: [ptp4l.0.config] CLOCK_REALTIME phc offset -62 s0 freq -78368 delay 1100 @@ -316,15 +321,35 @@ func (p *PTPEventManager) ExtractMetrics(msg string) { func (p *PTPEventManager) processDownEvent(profileName, processName string, ptpStats stats.PTPStats) { // if the process is responsible to set master offset - if masterOffsetSource == processName { - if ptpStats[master].Alias() != "" { - masterResource := fmt.Sprintf("%s/%s", ptpStats[master].Alias(), MasterClockType) - p.GenPTPEvent(profileName, ptpStats[master], masterResource, FreeRunOffsetValue, ptp.FREERUN, ptp.PtpStateChange) + if processName == ts2phcProcessName { + // update metrics for all interface defined by ts2phc + // set ts2phc stats to FREERUN + // this should generate PTP stat as free run by event manager + for iface := range ptpStats { + if iface != ClockRealTime && iface != master { + ptpStats[iface].SetLastOffset(FreeRunOffsetValue) + ptpStats[iface].SetLastSyncState(ptp.FREERUN) + alias := ptpStats[iface].Alias() + if alias == "" { + alias = getAlias(string(iface)) + } + // update all ts2phc reported metrics as FREERUN + UpdateSyncStateMetrics(processName, alias, ptpStats[iface].LastSyncState()) + UpdatePTPMetrics(master, processName, alias, FreeRunOffsetValue, float64(ptpStats[iface].MaxAbs()), + float64(ptpStats[iface].FrequencyAdjustment()), float64(ptpStats[iface].Delay())) + } } - } - if s, ok := ptpStats[ClockRealTime]; ok { - if t, ok2 := p.PtpConfigMapUpdates.PtpProcessOpts[profileName]; ok2 && t.Phc2SysEnabled() { - p.GenPTPEvent(profileName, s, ClockRealTime, FreeRunOffsetValue, ptp.FREERUN, ptp.OsClockSyncStateChange) + } else { // other profiles + if masterOffsetSource == processName { + if ptpStats[master].Alias() != "" { + masterResource := fmt.Sprintf("%s/%s", ptpStats[master].Alias(), MasterClockType) + p.GenPTPEvent(profileName, ptpStats[master], masterResource, FreeRunOffsetValue, ptp.FREERUN, ptp.PtpStateChange) + } + } + if s, ok := ptpStats[ClockRealTime]; ok { + if t, ok2 := p.PtpConfigMapUpdates.PtpProcessOpts[profileName]; ok2 && t.Phc2SysEnabled() { + p.GenPTPEvent(profileName, s, ClockRealTime, FreeRunOffsetValue, ptp.FREERUN, ptp.OsClockSyncStateChange) + } } } } diff --git a/plugins/ptp_operator/stats/stats.go b/plugins/ptp_operator/stats/stats.go index c67660ec..abf28e0c 100644 --- a/plugins/ptp_operator/stats/stats.go +++ b/plugins/ptp_operator/stats/stats.go @@ -236,7 +236,7 @@ func (s *Stats) GetStateState(processName string, iface *string) (ptp.SyncState, return d[0].State, nil } for _, state := range d { - if *state.IFace == *iface { + if iface != nil && *state.IFace == *iface { return state.State, nil } }