NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Import.NtpqPeerImporter Class Reference

Ntpq mapper parses status importLines from ntpq into objects. More...

Inheritance diagram for Ntp.Analyzer.Import.NtpqPeerImporter:
Collaboration diagram for Ntp.Analyzer.Import.NtpqPeerImporter:

Protected Member Functions

override void ReadFromStream ()
 
- Protected Member Functions inherited from Ntp.Analyzer.Import.Importer< AssociationEntry >
 Importer (LogBase log)
 
virtual void Initialize ()
 

Protected Attributes

override string Arguments => "-np " + address
 
override string Command => "ntpq"
 
override string ErrorMessage => LogMessage.ImportPeerError
 
- Protected Attributes inherited from Ntp.Analyzer.Import.Importer< AssociationEntry >
IList< T > Entries
 

Package Functions

 NtpqPeerImporter (string address, int hostId, LogBase log)
 

Private Member Functions

AssociationEntry ParseLine (string line)
 

Static Private Member Functions

static int CalcLastPoll (string line)
 

Private Attributes

readonly string address
 
readonly int hostId
 

Additional Inherited Members

- Public Member Functions inherited from Ntp.Analyzer.Import.Importer< AssociationEntry >
void Execute ()
 
IEnumerator< T > GetEnumerator ()
 
- Properties inherited from Ntp.Analyzer.Import.Importer< AssociationEntry >
abstract string Arguments [get]
 
abstract string Command [get]
 
abstract string ErrorMessage [get]
 
LogBase Log [get]
 
StreamReader Reader [get, private set]
 

Detailed Description

Ntpq mapper parses status importLines from ntpq into objects.

Definition at line 31 of file NtpqPeerImporter.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Import.NtpqPeerImporter.NtpqPeerImporter ( string  address,
int  hostId,
LogBase  log 
)
inlinepackage

Definition at line 33 of file NtpqPeerImporter.cs.

34  : base(log)
35  {
36  this.address = address;
37  this.hostId = hostId;
38  }

Member Function Documentation

static int Ntp.Analyzer.Import.NtpqPeerImporter.CalcLastPoll ( string  line)
inlinestaticprivate

Definition at line 67 of file NtpqPeerImporter.cs.

68  {
69  string lastPollString = line.Substring(38, 4);
70 
71  char lastPollUnit = lastPollString.Substring(lastPollString.Length - 1, 1)[0];
72  string lastPollValue = lastPollString.Substring(0, lastPollString.Length - 1).Trim();
73 
74  switch (lastPollUnit)
75  {
76  case 'm':
77  return Convert.ToInt32(lastPollValue)*60;
78  case 'h':
79  return Convert.ToInt32(lastPollValue)*60*60;
80  case 'd':
81  return Convert.ToInt32(lastPollValue)*60*60*24;
82  case '-':
83  return -1;
84  default:
85  return Convert.ToInt32(lastPollString);
86  }
87  }
AssociationEntry Ntp.Analyzer.Import.NtpqPeerImporter.ParseLine ( string  line)
inlineprivate

Definition at line 89 of file NtpqPeerImporter.cs.

90  {
91  char state = line[0];
92  string remote = line.Substring(1, 16).Trim();
93  string refid = line.Substring(17, 16).Trim();
94  int stratus = Convert.ToInt32(line.Substring(33, 2).Trim());
95  char t = line[36];
96  int lastPoll = CalcLastPoll(line);
97  int pollFrequency = Convert.ToInt32(line.Substring(43, 4).Trim());
98  int reach = Convert.ToInt32(line.Substring(49, 3).Trim());
99  double delay = Convert.ToDouble(line.Substring(53, 8).Trim());
100  double offset = Convert.ToDouble(line.Substring(61, 9).Trim());
101  double jitter = Convert.ToDouble(line.Substring(70, 8).Trim());
102 
103  var entry = new AssociationEntry(
104  hostId, state, remote, refid, stratus, t,
105  lastPoll, pollFrequency, reach, delay, offset, jitter);
106 
107  return entry;
108  }
static int CalcLastPoll(string line)
override void Ntp.Analyzer.Import.NtpqPeerImporter.ReadFromStream ( )
inlineprotectedvirtual

Implements Ntp.Analyzer.Import.Importer< AssociationEntry >.

Definition at line 49 of file NtpqPeerImporter.cs.

50  {
51  // Skip header
52  Reader.ReadLine();
53  Reader.ReadLine();
54 
55  while (Reader.Peek() != -1)
56  {
57  string line = Reader.ReadLine();
58 
59  if (string.IsNullOrWhiteSpace(line))
60  continue;
61 
62  var entry = ParseLine(line);
63  Entries.Add(entry);
64  }
65  }
AssociationEntry ParseLine(string line)

Member Data Documentation

readonly string Ntp.Analyzer.Import.NtpqPeerImporter.address
private

Definition at line 40 of file NtpqPeerImporter.cs.

override string Ntp.Analyzer.Import.NtpqPeerImporter.Arguments => "-np " + address
protected

Definition at line 45 of file NtpqPeerImporter.cs.

override string Ntp.Analyzer.Import.NtpqPeerImporter.Command => "ntpq"
protected

Definition at line 43 of file NtpqPeerImporter.cs.

override string Ntp.Analyzer.Import.NtpqPeerImporter.ErrorMessage => LogMessage.ImportPeerError
protected

Definition at line 47 of file NtpqPeerImporter.cs.

readonly int Ntp.Analyzer.Import.NtpqPeerImporter.hostId
private

Definition at line 41 of file NtpqPeerImporter.cs.


The documentation for this class was generated from the following file: