Skip to content

Commit

Permalink
Small updates and requirements.txt updated for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaharia Constantin committed May 18, 2021
1 parent ef45e9a commit b2eaafc
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 25 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,18 @@
[https://tools.ietf.org/html/rfc958](https://tools.ietf.org/html/rfc958)


[https://www.monitorix.org/](https://www.monitorix.org/)

[https://rplcd.readthedocs.io/en/stable/index.html](https://rplcd.readthedocs.io/en/stable/index.html)

### **Chrony**

[https://chrony.tuxfamily.org/index.html](https://chrony.tuxfamily.org/index.html)

[https://docs.fedoraproject.org/en-US/Fedora/18/html/System_Administrators_Guide/sect-Checking_if_chrony_is_synchronized.html](https://docs.fedoraproject.org/en-US/Fedora/18/html/System_Administrators_Guide/sect-Checking_if_chrony_is_synchronized.html)

### **NTPD**

[https://github.com/cf-natali/ntplib](https://github.com/cf-natali/ntplib)

![RaspberryPi NTP LCD demo](media/rplcd_demo.gif)
57 changes: 56 additions & 1 deletion Screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ def chrony_status(self):

@register_screen(order=8)
def chrony_root_delay(self):
"""This is the total of the network path delays to the stratum-1 computer from which the computer is ultimately
synchronised. In certain extreme situations, this value can be negative.
(This can arise in a symmetric peer arrangement where the computers’ frequencies are not tracking each other
and the network delay is very short relative to the turn-around time at each computer.)
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -288,6 +295,12 @@ def chrony_root_delay(self):

@register_screen(order=9)
def chrony_root_dispersion(self):
"""This is the total dispersion accumulated through all the computers back to the stratum-1 computer from
which the computer is ultimately synchronised. Dispersion is due to system clock resolution,
statistical measurement variations etc.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -305,6 +318,10 @@ def chrony_root_dispersion(self):

@register_screen(order=10)
def chrony_last_offset(self):
"""This is the estimated local offset on the last clock update.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -313,11 +330,16 @@ def chrony_last_offset(self):
last_off = normalize_timespec(float(last_offset))

l1 = '{} Last offset'.format(reference_name)
l2 = '{last_off} {last_off_unit}'.format(last_off=int(last_off[0]), last_off_unit=last_off[1])
l2 = '{last_off} {last_off_unit}'.format(last_off=int(last_off[0]),
last_off_unit=chr(228)+"s" if last_off[1] == 'µs' else last_off[1])
return (l1, 0), (l2, 1)

@register_screen(order=11)
def chrony_rms_offset(self):
"""This is a long-term average of the offset value.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -331,6 +353,17 @@ def chrony_rms_offset(self):

@register_screen(order=12)
def chrony_system_time(self):
"""In normal operation, chronyd never steps the system clock, because any jump in the timescale can have
adverse consequences for certain application programs. Instead, any error in the system clock is corrected by
slightly speeding up or slowing down the system clock until the error has been removed,
and then returning to the system clock’s normal speed.
A consequence of this is that there will be a period when the system clock
(as read by other programs using the gettimeofday() system call, or by the date command in the shell)
will be different from chronyd's estimate of the current true time (which it reports to NTP clients when it is
operating in server mode). The value reported on this line is the difference due to this effect.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -345,6 +378,13 @@ def chrony_system_time(self):

@register_screen(order=13)
def chrony_frequency(self):
"""The ‘frequency’ is the rate by which the system’s clock would be would be wrong if chronyd was not
correcting it. It is expressed in ppm (parts per million). For example, a value of 1ppm would mean that when
the system’s clock thinks it has advanced 1 second, it has actually advanced by 1.000001 seconds relative to
true time.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -357,6 +397,17 @@ def chrony_frequency(self):

@register_screen(order=14)
def chrony_residual_freq(self):
"""This shows the ‘residual frequency’ for the currently selected reference source.
This reflects any difference between what the measurements from the reference source indicate the frequency
should be and the frequency currently being used. The reason this is not always zero is that a smoothing
procedure is applied to the frequency. Each time a measurement from the reference source is obtained and a new
residual frequency computed, the estimated accuracy of this residual is compared with the estimated accuracy
(see ‘skew’ next) of the existing frequency value. A weighted average is computed for the new frequency,
with weights depending on these accuracies. If the measurements from the reference source follow a consistent
trend, the residual will be driven to zero over time.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand All @@ -369,6 +420,10 @@ def chrony_residual_freq(self):

@register_screen(order=15)
def chrony_skew(self):
"""This is the estimated error bound on the frequency.
:return:
"""
stderr, chrony = self.chrony.chrony_tracking()

reference_name = chrony.get('reference_name')
Expand Down
21 changes: 2 additions & 19 deletions libs/chrony.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,13 @@ def chrony_tracking(self):
clock_offset = normalize_timespec(clock_offset_from_ntp)

if abs(clock_offset_from_ntp) >= self.maximum_divergence_tolerated:
clock_status = '{co}[max{mt}s]slow'.format(
clock_status = '{co}[max{mt}s] NOK'.format(
co=int(clock_offset_from_ntp), mt=int(self.maximum_divergence_tolerated))
else:
clock_status = '{co}{co_unit}[{mt}s]'.format(
clock_status = '{co}{co_unit}[{mt}s] OK'.format(
co=int(clock_offset[0]), co_unit=clock_offset[1], mt=int(self.maximum_divergence_tolerated))
indata['clock_status'] = clock_status
else:
stderr = b'Unexpected error on Chrony tracking'


#
# for line in rows:
# stats = line.split(':')
# if len(stats) < 2:
# return "unexpected output from chronyc, expected ':' in %s".format(data), indata
# name = stats[0].strip().replace(" ", "_").lower()
# print(name)
# if 'ref_time' in name:
# continue
#
# value_fields = stats[1].strip().split(" ")
#
# if "slow" in stats[1]:
# value_fields[0] = "-{0}".format(value_fields[0])
#
# indata[name] = value_fields[0]
return stderr.decode('UTF-8'), indata
15 changes: 10 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ cffi==1.14.5
chardet==4.0.0
cryptography==3.4.7
distro==1.5.0
docopt==0.6.2
entrypoints==0.3
idna==3.1
idna==2.10
importlib-metadata==4.0.1
jeepney==0.6.0
keyring==23.0.1
keyrings.alt==4.0.2
pipreqs==0.4.10
psutil==5.8.0
pycairo==1.20.0
pycparser==2.20
pycrypto==2.6.1
PyGObject==3.40.1
python-apt==0.7.8
pyxdg==0.27
PyGObject==3.30.4
python-apt==1.8.4.3
python-distutils-extra==2.39
pyxdg==0.25
requests==2.25.1
RPLCD==1.3.0
SecretStorage==3.3.1
six==1.16.0
smbus==1.1.post2
smbus2==0.4.1
spidev==3.5
spidev==3.4
ssh-import-id==5.11
typing-extensions==3.10.0.0
urllib3==1.26.4
yarg==0.1.9
zipp==3.4.1

0 comments on commit b2eaafc

Please sign in to comment.