FetchStats fetches GMs via http
(cfg *Config)
| 53 | } |
| 54 | |
| 55 | // FetchStats fetches GMs via http |
| 56 | func (hf *HTTPFetcher) FetchStats(cfg *Config) (*DataPoint, error) { |
| 57 | url := fmt.Sprintf("http://%s/", cfg.PTPClientAddress) |
| 58 | sm, err := stats.FetchStats(url) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | log.Debugf("TIME_STATUS_NP: %+v", sm) |
| 63 | |
| 64 | for _, s := range sm { |
| 65 | if s.Selected { |
| 66 | accuracyNS := s.ClockQuality.ClockAccuracy.Duration().Nanoseconds() |
| 67 | return &DataPoint{ |
| 68 | IngressTimeNS: s.IngressTime, |
| 69 | MasterOffsetNS: s.Offset, |
| 70 | PathDelayNS: s.MeanPathDelay, |
| 71 | ClockAccuracyNS: float64(int64(s.GMPresent) * accuracyNS), |
| 72 | ServoState: s.ServoState, |
| 73 | }, nil |
| 74 | } |
| 75 | } |
| 76 | return nil, fmt.Errorf("no selected grandmaster out of %d reported by sptp: [%s]", len(sm), describeGMs(sm)) |
| 77 | } |
| 78 | |
| 79 | // describeGMs prints what bmca rejects a grandmaster on: an error, a negative correction field, or its clock quality. |