Skip to content

Commit 48cdc2e

Browse files
authored
Merge pull request PR2#259 from knorth55/ignore-self
add --ignore-self arg in ntp_monitor.py
2 parents cc6853f + 7b0df9d commit 48cdc2e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pr2_computer_monitor/scripts/ntp_monitor.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,36 @@
5454

5555
NAME = 'ntp_monitor'
5656

57-
def ntp_monitor(ntp_hostname, offset=500, self_offset=500, diag_hostname = None, error_offset = 5000000):
57+
def ntp_monitor(ntp_hostname, offset=500, self_offset=500, diag_hostname=None,
58+
error_offset=5000000, ignore_self=False):
5859
pub = rospy.Publisher("/diagnostics", DiagnosticArray, queue_size=10)
5960
rospy.init_node(NAME, anonymous=True)
6061

6162
hostname = socket.gethostname()
6263
if diag_hostname is None:
6364
diag_hostname = hostname
6465

66+
ntp_checks = []
6567
stat = DiagnosticStatus()
6668
stat.level = 0
6769
stat.name = "NTP offset from "+ diag_hostname + " to " + ntp_hostname
6870
stat.message = "OK"
6971
stat.hardware_id = hostname
7072
stat.values = []
73+
ntp_checks.append((stat, ntp_hostname, offset))
74+
75+
if not ignore_self:
76+
self_stat = DiagnosticStatus()
77+
self_stat.level = DiagnosticStatus.OK
78+
self_stat.name = "NTP self-offset for "+ diag_hostname
79+
self_stat.message = "OK"
80+
self_stat.hardware_id = hostname
81+
self_stat.values = []
82+
ntp_checks.append((self_stat, hostname, self_offset))
7183

72-
self_stat = DiagnosticStatus()
73-
self_stat.level = DiagnosticStatus.OK
74-
self_stat.name = "NTP self-offset for "+ diag_hostname
75-
self_stat.message = "OK"
76-
self_stat.hardware_id = hostname
77-
self_stat.values = []
78-
7984
while not rospy.is_shutdown():
80-
for st,host,off in [(stat,ntp_hostname,offset), (self_stat, hostname,self_offset)]:
85+
msg = DiagnosticArray()
86+
for st, host, off in ntp_checks:
8187
try:
8288
p = Popen(["ntpdate", "-q", host], stdout=PIPE, stdin=PIPE, stderr=PIPE)
8389
res = p.wait()
@@ -111,11 +117,9 @@ def ntp_monitor(ntp_hostname, offset=500, self_offset=500, diag_hostname = None,
111117
KeyValue("Offset tolerance (us) for Error", str(error_offset)),
112118
KeyValue("Output", o),
113119
KeyValue("Errors", e) ]
120+
msg.status.append(st)
114121

115-
116-
msg = DiagnosticArray()
117122
msg.header.stamp = rospy.get_rostime()
118-
msg.status = [stat, self_stat]
119123
pub.publish(msg)
120124
time.sleep(1)
121125

@@ -135,6 +139,8 @@ def ntp_monitor_main(argv=sys.argv):
135139
help="Computer name in diagnostics output (ex: 'c1')",
136140
metavar="DIAG_HOSTNAME",
137141
action="store", default=None)
142+
parser.add_option("--ignore-self", dest="ignore_self",
143+
help="Ignore self NTP test", action="store_true")
138144
options, args = parser.parse_args(rospy.myargv())
139145

140146
if (len(args) != 2):
@@ -145,10 +151,12 @@ def ntp_monitor_main(argv=sys.argv):
145151
offset = int(options.offset_tol)
146152
self_offset = int(options.self_offset_tol)
147153
error_offset = int(options.error_offset_tol)
154+
ignore_self = options.ignore_self
148155
except:
149156
parser.error("Offsets must be numbers")
150157

151-
ntp_monitor(args[1], offset, self_offset, options.diag_hostname, error_offset)
158+
ntp_monitor(args[1], offset, self_offset, options.diag_hostname,
159+
error_offset, ignore_self)
152160

153161

154162
if __name__ == "__main__":

0 commit comments

Comments
 (0)