X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fntpd.c;h=540eb788e0b67e3e481be0b382373de5e5d96218;hb=dbf349ec8c0150a52a7bad5f8b9fc79a6201e2f6;hp=184c5c175b9131a74268a69b65001fafb848f217;hpb=b6009737c27e35990146d81c10b3b2b58053e5b7;p=collectd.git diff --git a/src/ntpd.c b/src/ntpd.c index 184c5c17..540eb788 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -322,6 +322,18 @@ static void ntpd_submit (char *type, char *type_inst, double value) plugin_dispatch_values (&vl); } +/* Each time a peer is polled, ntpd shifts the reach register to the left and + * sets the LSB based on whether the peer was reachable. If the LSB is zero, + * the values are out of date. */ +static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach, + double value) +{ + if (!(reach & 1)) + value = NAN; + + ntpd_submit (type, type_inst, value); +} + static int ntpd_connect (void) { char *host; @@ -652,7 +664,6 @@ static int ntpd_receive_response (int *res_items, int *res_size, (items_num + pkt_item_num) * res_item_size); if (items == NULL) { - items = *res_data; ERROR ("ntpd plugin: realloc failed."); continue; } @@ -971,6 +982,7 @@ static int ntpd_read (void) DEBUG ("peer %i:\n" " peername = %s\n" " srcadr = 0x%08x\n" + " reach = 0%03o\n" " delay = %f\n" " offset_int = %i\n" " offset_frc = %i\n" @@ -979,6 +991,7 @@ static int ntpd_read (void) i, peername, ntohl (ptr->srcadr), + ptr->reach, ntpd_read_fp (ptr->delay), ntohl (ptr->offset_int), ntohl (ptr->offset_frc), @@ -986,10 +999,13 @@ static int ntpd_read (void) ntpd_read_fp (ptr->dispersion)); if (refclock_id != 1) /* not the system clock (offset will always be zero.. */ - ntpd_submit ("time_offset", peername, offset); - ntpd_submit ("time_dispersion", peername, ntpd_read_fp (ptr->dispersion)); + ntpd_submit_reach ("time_offset", peername, ptr->reach, + offset); + ntpd_submit_reach ("time_dispersion", peername, ptr->reach, + ntpd_read_fp (ptr->dispersion)); if (refclock_id == 0) /* not a reference clock */ - ntpd_submit ("delay", peername, ntpd_read_fp (ptr->delay)); + ntpd_submit_reach ("delay", peername, ptr->reach, + ntpd_read_fp (ptr->delay)); } free (ps);