func (c *ntpCollector) Update(ch chan<- prometheus.Metric) (err error) { resp, err := ntp.Query(*ntpServer, *ntpProtocolVersion) if err != nil { return fmt.Errorf("couldn't get NTP drift: %s", err) } driftSeconds := resp.ClockOffset.Seconds() log.Debugf("Set ntp_drift_seconds: %f", driftSeconds) ch <- c.drift.mustNewConstMetric(driftSeconds) stratum := float64(resp.Stratum) log.Debugf("Set ntp_stratum: %f", stratum) ch <- c.stratum.mustNewConstMetric(stratum) return nil }
func (self *SyncSender) AnnounceTime(destination sfconnection.AMAddr, offset int64) { if ntpr, err := ntp.Query(self.host, 4); err == nil { self.Debug.Printf("NTP %d stratum %d RTT %s offset %s", ntpr.Time.Unix(), ntpr.Stratum, ntpr.RTT, ntpr.ClockOffset) m := new(RTCSyncMsg) m.Header = TIME_ANNOUNCEMENT_UNIX m.Stratum = ntpr.Stratum + 1 m.Nxtime = ntpr.Time.Unix() + offset msg := self.dsp.NewMessage() msg.SetDestination(destination) msg.SetType(AMID_RTC) msg.Payload = sfconnection.SerializePacket(m) self.Info.Printf("Announce %s->%s %d(%d)\n", msg.Source(), destination, m.Nxtime, offset) self.sfc.Send(msg) } else { self.Warning.Printf("NTP query failed %s", err) } }