Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print also timeouts #175

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ long timeval_diff(struct timeval* a, struct timeval* b);
void timeval_add(struct timeval* a, long t_10u);
void usage(int);
int wait_for_reply(long);
void handle_reply_timeouts();
void print_per_system_stats(void);
void print_per_system_splits(void);
void print_netdata(void);
Expand Down Expand Up @@ -626,7 +627,7 @@ int main(int argc, char** argv)

case 'x':
if (!(min_reachable = (unsigned int)atoi(optparse_state.optarg)))
usage(1);
usage(1);
break;

case 'f':
Expand Down Expand Up @@ -1281,6 +1282,9 @@ void main_loop()

gettimeofday(&current_time, &tz);

/* Replies without answers */
handle_reply_timeouts();

/* Print report */
if (report_interval && (loop_flag || count_flag) && (timeval_diff(&current_time, &next_report_time) >= 0)) {
if (netdata_flag)
Expand Down Expand Up @@ -2241,9 +2245,73 @@ int wait_for_reply(long wait_time)
}

fflush(stdout);
seqmap_clear(seq);
return num_jobs;
}

void handle_reply_timeouts()
{
unsigned int seq;
SEQMAP_VALUE * seqmap_value;
HOST_ENTRY* h;
long duration;
int ping_number;
int avg;

for(;;) {

seq = seqmap_get_oldest_id();
seqmap_value = seqmap_fetch(seq, &current_time);

if (seqmap_value == NULL) {
break;
}

h = table[seqmap_value->host_nr];

ping_number = seqmap_value->ping_count;
duration = timeval_diff(&current_time, &(seqmap_value->ping_ts));

/* not yet in a timeout */
if (duration <= h->timeout) {
break;
}

if (per_recv_flag) {
if (timestamp_flag) {
printf("[%lu.%06lu] ",
(unsigned long)current_time.tv_sec,
(unsigned long)current_time.tv_usec);
}

printf("%s%s : [%d], timed out",
h->host, h->pad, ping_number);

if (h->num_recv > 0) {
avg = h->total_time / h->num_recv;
printf(" (%s avg, ", sprint_tm(avg));
}
else {
printf(" (no avg, ");
}
if (h->num_recv <= h->num_sent) {
printf("%d%% loss)",
((h->num_sent - h->num_recv) * 100) / h->num_sent);
}
else {
printf("%d%% return)",
(h->num_recv_total * 100) / h->num_sent);
}

printf("\n");
fflush(stdout);
}

seqmap_clear(seq);
}
return;
}

/************************************************************

Function: add_name
Expand Down
23 changes: 23 additions & 0 deletions src/seqmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* description of the data structure used:
*
Expand All @@ -53,6 +54,7 @@

static SEQMAP_VALUE* seqmap_map = NULL;
static unsigned int seqmap_next_id = 0;
static unsigned int seqmap_first_id = 0;

#define SEQMAP_TIMEOUT_IN_S 10
#define SEQMAP_UNASSIGNED_HOST_NR UINT_MAX
Expand Down Expand Up @@ -114,3 +116,24 @@ SEQMAP_VALUE* seqmap_fetch(unsigned int id, struct timeval* now)

return value;
}

void seqmap_clear(unsigned int id)
{
if (id > SEQMAP_MAXSEQ) {
return;
}

memset(&seqmap_map[id], 0, sizeof(SEQMAP_VALUE));

while (seqmap_map[seqmap_first_id].ping_ts.tv_sec == 0
&& seqmap_first_id != seqmap_next_id ) {
seqmap_first_id = (seqmap_first_id + 1) % SEQMAP_MAXSEQ;
}

return;
}

unsigned int seqmap_get_oldest_id()
{
return seqmap_first_id;
}
2 changes: 2 additions & 0 deletions src/seqmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ typedef struct seqmap_value
void seqmap_init();
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval *now);
SEQMAP_VALUE *seqmap_fetch(unsigned int id, struct timeval *now);
void seqmap_clear(unsigned int id);
unsigned int seqmap_get_oldest_id();

#endif