23 using System.Collections.Generic;
29 namespace Ntp.Analyzer.Import
39 this.address = address;
49 protected override string Command =>
"ntpq";
51 protected override string Arguments =>
"-nc kerninfo -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, 19).Replace(
":",
string.Empty).TrimEnd();
81 string value = line.Substring(19).Trim();
86 peerIp = value.Replace(
":123",
string.Empty).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)
NtpqHostImporter(string address, Host host, ReadingBulk bulk, LogBase log)
PeerDatabaseMapper Peers
Gets the peer mapper.
Singleton facade class used to access memory persistent data.
readonly ReadingBulk bulk
const string ImportHostError
static DataFace Instance
Gets the Singleton instance.
override void ReadFromStream()
override void Initialize()