23 using System.Collections.Generic;
29 namespace Ntp.Analyzer.Import
39 this.address = address;
49 protected override string Command =>
"ntpdc";
51 protected override string Arguments =>
"-nc loopinfo -c sysinfo " + address;
73 while (Reader.Peek() != -1)
75 string line = Reader.ReadLine();
77 if (
string.IsNullOrWhiteSpace(line) || line.Length < 24)
80 string name = line.Substring(0, 22).Replace(
":",
string.Empty).TrimEnd();
81 string value = line.Substring(22).TrimEnd();
86 peerIp = value.Trim();
89 offset = Convert.ToDouble(value.Replace(
"s",
string.Empty).Trim());
92 frequency = Convert.ToDouble(value.Replace(
"ppm",
string.Empty).Trim());
95 jitter = Convert.ToDouble(value.Replace(
"s",
string.Empty).Trim());
98 stability = Convert.ToDouble(value.Replace(
"ppm",
string.Empty).Trim());
103 if (peerIp != null && peerIp.StartsWith(
"0.0.0.0"))
105 Log.NoSyncing(host.Name);
109 CreateEntry(peerIp, offset, jitter, frequency, stability);
112 private void CreateEntry(
string peerIp,
double offset,
double jitter,
double frequency,
double stability)
114 IEnumerable<Peer> peerList = peers.Where(p => p.Ip == peerIp).ToList();
118 switch (peerList.Count())
121 peer = peerList.Single();
124 Log.PeerNotFound(host.Name, peerIp);
127 Log.MultiplePeersFound(host.Name, peerIp);
131 Log.Syncing(host.Name, peer.
Name);
133 var reading =
new HostReading(host, peer, bulk, offset, jitter, frequency, stability);
134 Entries.Add(reading);
void CreateEntry(string peerIp, double offset, double jitter, double frequency, double stability)
readonly ReadingBulk bulk
PeerDatabaseMapper Peers
Gets the peer mapper.
override void ReadFromStream()
Singleton facade class used to access memory persistent data.
NtpdcImporter(string address, Host host, ReadingBulk bulk, LogBase log)
override void Initialize()
const string ImportHostError
static DataFace Instance
Gets the Singleton instance.