]> git.gsnw.org Git - fping.git/commitdiff
first attempt at fixing #97 (fixes #97)
authorDavid Schweikert <david@schweikert.ch>
Tue, 1 Nov 2016 14:22:09 +0000 (15:22 +0100)
committerDavid Schweikert <david@schweikert.ch>
Tue, 1 Nov 2016 14:22:09 +0000 (15:22 +0100)
ChangeLog
src/fping.c

index 4142cc217445e75e7af9dc629f2684813d5f89bd..94cded69e5a79d5536f0489d03a4717897a3ac4f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@ UNRELEASED
   * (bugfix)  Fix issue compliling on RHEL/Centos 7 (#95, @jbackman)
   * (bugfix) Lower -i limit to 1 instead of 10
   * (bugfix) Improve interval preciseness of -Q reporting
+  * (bugfix) Fix occasional false positive in interval reporting (#97)
 
 2015-10-21  David Schweikert  <david@schweikert.ch>
   * Version 3.13
index 19eacbeb7cd29e4f8df6c97d08172df050e89ec1..39c3bd4fb255ae05e0f49fdef2ca117e6d81624a 100644 (file)
@@ -1321,6 +1321,12 @@ void print_netdata( void )
             /* printf("DIMENSION lost '' absolute 1 1\n"); */
         }
 
+        /* if we just sent the probe and didn't receive a reply, we shouldn't count it */
+        if( h->waiting && timeval_diff(&current_time, &h->last_send_time) < h->timeout) {
+            if(h->num_sent_i) h->num_sent_i--;
+        }
+
+
         printf("BEGIN fping.%s_quality\n", h->name);
 /*
         if( h->num_recv_i <= h->num_sent_i )
@@ -1382,17 +1388,21 @@ void print_per_system_splits( void )
     if( verbose_flag || per_recv_flag )
         fprintf( stderr, "\n" );
 
+    gettimeofday( &current_time, &tz );
     curr_tm = localtime( ( time_t* )&current_time.tv_sec );
     fprintf( stderr, "[%2.2d:%2.2d:%2.2d]\n", curr_tm->tm_hour,
         curr_tm->tm_min, curr_tm->tm_sec );
 
-    for( i = 0; i < num_hosts; i++ )
-    {
+    for( i = 0; i < num_hosts; i++ ) {
         h = table[i];
         fprintf( stderr, "%s%s :", h->host, h->pad );
 
-        if( h->num_recv_i <= h->num_sent_i )
-        {
+        /* if we just sent the probe and didn't receive a reply, we shouldn't count it */
+        if( h->waiting && timeval_diff(&current_time, &h->last_send_time) < h->timeout) {
+            if(h->num_sent_i) h->num_sent_i--;
+        }
+
+        if( h->num_recv_i <= h->num_sent_i ) {
             fprintf( stderr, " xmt/rcv/%%loss = %d/%d/%d%%",
                 h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ?
                 ( ( h->num_sent_i - h->num_recv_i ) * 100 ) / h->num_sent_i : 0 );
@@ -1402,29 +1412,26 @@ void print_per_system_splits( void )
                 outage_ms_i = (h->num_sent_i - h->num_recv_i) * perhost_interval/100;
                 fprintf( stderr, ", outage(ms) = %d", outage_ms_i );
             }
-        }/* IF */
-        else
-        {
+        }
+        else {
             fprintf( stderr, " xmt/rcv/%%return = %d/%d/%d%%",
                 h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ?
                 ( ( h->num_recv_i * 100 ) / h->num_sent_i ) : 0 );
+        }
 
-        }/* ELSE */
-
-        if( h->num_recv_i )
-        {
+        if( h->num_recv_i ) {
             avg = h->total_time_i / h->num_recv_i;
             fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply_i ) );
             fprintf( stderr, "/%s", sprint_tm( avg ) );
             fprintf( stderr, "/%s", sprint_tm( h->max_reply_i ) );
         
-        }/* IF */
+        }
         
         fprintf( stderr, "\n" );
         h->num_sent_i = h->num_recv_i = h->max_reply_i =
             h->min_reply_i = h->total_time_i = 0;
     
-    }/* FOR */
+    }
 } /* print_per_system_splits() */