Component for checking and comparing remote host times. This can be used to validate proper time keeping (e.g. via ntpd or similar) on multiple remote hosts by comparing with local time. Its also illustrative of syncwrap threading and synchronized output formatting.
First you should add this component to some or all hosts:
role( :all, TimeChecker.new )
Then you run it via the command line:
You can also experiment with -v and -t flags if desired.
Output is in the following form per host:
host-name : start-delta <- HH:MM:SS.NNNNNNZ -> return-delta
the captured and parsed remote time is shown in 'Z'ulu (UTC)
start-delta is the time difference between the local time, just before the remote command is started, and the remote time.
return-delta is the difference between the remote time and local time, just after the remote command has returned.
If both local and remote hosts have well synchronized clocks, then both these differences should be positive, but small negative values for return-delta are common, in the range of the clock skew. Negative values are formatted in red when output is colorized.
Host component dependencies: none
# File lib/syncwrap/components/time_checker.rb, line 68 def check lnow1 = Time.now.utc rc, out = capture( 'date --rfc-3339=ns' ) if rc == 0 lnow2 = Time.now.utc rnow = Time.parse( out ).utc d1 = rnow - lnow1 d2 = lnow2 - rnow formatter.sync do c = formatter.io c << FORMAT % [ host.name, d1 < 0.0 ? red? : green?, d1, clear?, rnow.strftime( '%H:%M:%S.%6NZ' ), d2 < 0.0 ? red? : green?, d2, clear? ] c.flush end end end