X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fntpd.c;h=6bed82c22c670a62dca5614345771e51d4678d6b;hp=184c5c175b9131a74268a69b65001fafb848f217;hb=633c3966f770e4d46651a2fe219a18d8a9907a9f;hpb=b6009737c27e35990146d81c10b3b2b58053e5b7 diff --git a/src/ntpd.c b/src/ntpd.c index 184c5c17..6bed82c2 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -2,18 +2,23 @@ * collectd - src/ntpd.c * Copyright (C) 2006-2012 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Florian octo Forster @@ -322,6 +327,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; @@ -971,6 +988,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 +997,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 +1005,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);