Skip to content

Commit

Permalink
rework pps_status
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <[email protected]>
  • Loading branch information
jzding committed Nov 22, 2023
1 parent b434581 commit 7590b55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 24 additions & 11 deletions plugins/ptp_operator/metrics/logparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,12 @@ func (p *PTPEventManager) ParseGMLogs(processName, configName, output string, fi
// ParseDPLLLogs ... parse logs for various events
func (p *PTPEventManager) ParseDPLLLogs(processName, configName, output string, fields []string,
ptpStats map[types.IFace]*stats.Stats) {
// dpll[1689282767]:[ts2phc.0.config] ens2f1 phase_status 0 frequency_status 0 offset 0 s0
//dpll[1689014436]:[ts2phc.0.config] ens2f1 frequency_status 0 offset 0 phase_status 0 s0
// 0 1 2 3 4 5 6 7 8 9 10
// dpll 1689014436 ts2phc.0.config ens2f1 frequency_status 0 offset 0 phase_status 0 s0
// dpll[1700598434]:[ts2phc.0.config] ens2f0 frequency_status 3 offset 0 phase_status 3 pps_status 1 s2
// 0 1 2 3 4 5 6 7 8 9 10 11 12
// dpll 1700598434 ts2phc.0.config ens2f0 frequency_status 3 offset 0 phase_status 3 pps_status 1 s2
log.Infof("ParseDPLLLogs: %s", output)
if strings.Contains(output, "frequency_status") {
if len(fields) < 10 {
if len(fields) < 12 {
log.Errorf("DPLL Status is not in right format %s", output)
return
}
Expand All @@ -395,12 +394,13 @@ func (p *PTPEventManager) ParseDPLLLogs(processName, configName, output string,
var phaseStatus int64
var frequencyStatus int64
var dpllOffset float64
var ppsStatus float64
var err error
iface := pointer.String(fields[3])
syncState := fields[10]
syncState := fields[12]
logStatusLoop:
// read 4 ,6 and 8,
for i := 4; i < 9; i = i + 2 { // the order need to be fixed in linux ptp daemon , this is workaround
// read 4, 6, 8 and 10
for i := 4; i < 11; i = i + 2 { // the order need to be fixed in linux ptp daemon , this is workaround
switch fields[i] {
case "frequency_status":
if frequencyStatus, err = strconv.ParseInt(fields[i+1], 10, 64); err != nil {
Expand All @@ -418,13 +418,15 @@ logStatusLoop:
log.Errorf("%s failed to parse offset from the output %s error %s", processName, fields[3], err.Error())
break logStatusLoop
}
case "pps_status":
if ppsStatus, err = strconv.ParseFloat(fields[i+1], 64); err != nil {
log.Errorf("%s failed to parse offset from the output %s error %s", processName, fields[3], err.Error())
break logStatusLoop
}
}
}

if err == nil {
pLabels := map[string]string{"from": processName, "node": ptpNodeName,
"process": processName, "iface": *iface}
PtpOffset.With(pLabels).Set(dpllOffset)
SyncState.With(map[string]string{"process": processName, "node": ptpNodeName, "iface": *iface}).Set(GetSyncStateID(syncState))
ptpStats[master].SetPtpDependentEventState(event.ClockState{
State: GetSyncState(syncState),
Expand All @@ -436,6 +438,17 @@ logStatusLoop:
NodeName: ptpNodeName,
HelpText: "-1=UNKNOWN, 0=INVALID, 1=FREERUN, 2=LOCKED, 3=LOCKED_HO_ACQ, 4=HOLDOVER",
})
var alias string
r := []rune(*iface)
alias = string(r[:len(r)-1]) + "x"
masterResource := fmt.Sprintf("%s/%s", alias, MasterClockType)
interfaceType := types.IFace(master)
if ppsStatus == UNAVAILABLE {
p.GenPTPEvent(processName, ptpStats[interfaceType], masterResource, int64(dpllOffset), ptp.FREERUN, ptp.PtpStateChange)
} else {
UpdatePTPOffsetMetrics(processName, processName, *iface, dpllOffset)
}
UpdatePpsStatusMetrics(processName, alias, ppsStatus)
}
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/ptp_operator/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func InitPubSubTypes() map[ptp.EventType]*types.EventPublisherType {
}

var testCase = []string{
"dpll[1700614893]:[ts2phc.0.config] ens7f0 frequency_status 3 offset 5 phase_status 3 pps_status 1 s2",
"dpll[1700614893]:[ts2phc.0.config] ens7f0 frequency_status 3 offset 7 phase_status 3 pps_status 0 s2",
"GM[1699929086]:[ts2phc.0.config] ens2f0 T-GM-STATUS s0",
"ts2phc[1699929121]:[ts2phc.0.config] ens2f0 nmea_status 0 offset 999999 s0",
"ts2phc[1699929171]:[ts2phc.0.config] ens2fx nmea_status 1 offset 0 s2",
Expand Down

0 comments on commit 7590b55

Please sign in to comment.