static void update_stats(int_status_t *intrnl, iterator_t *it) { intrnl->last_now = now(); intrnl->last_sent = iterator_get_sent(it); intrnl->last_recv_net_success = zrecv.success_unique; intrnl->last_recv_app_success = zrecv.app_success_unique; intrnl->last_pcap_drop = zrecv.pcap_drop + zrecv.pcap_ifdrop; intrnl->last_send_failures = zsend.sendto_failures; }
static void export_stats(int_status_t *intrnl, export_status_t *exp, iterator_t *it) { uint32_t total_sent = iterator_get_sent(it); uint32_t total_fail = iterator_get_fail(it); uint32_t total_recv = zrecv.pcap_recv; uint32_t recv_success = zrecv.success_unique; uint32_t app_success = zrecv.app_success_unique; double cur_time = now(); double age = cur_time - zsend.start; // time of entire scan double delta = cur_time - intrnl->last_now; // time since the last time we updated double remaining_secs = compute_remaining_time(age, total_sent); // export amount of time the scan has been running if (age < WARMUP_PERIOD) { exp->time_remaining_str[0] = '\0'; } else { char buf[20]; time_string(ceil(remaining_secs), 1, buf, sizeof(buf)); snprintf(exp->time_remaining_str, NUMBER_STR_LEN, " (%s left)", buf); } exp->time_past = age; exp->time_remaining = remaining_secs; time_string((int)age, 0, exp->time_past_str, NUMBER_STR_LEN); // export recv statistics exp->recv_rate = (recv_success - intrnl->last_recv_net_success)/delta; number_string(exp->recv_rate, exp->recv_rate_str, NUMBER_STR_LEN); exp->recv_avg = recv_success/age; number_string(exp->recv_avg, exp->recv_avg_str, NUMBER_STR_LEN); exp->recv_total_rate = (total_recv - intrnl->last_recv_total)/delta; exp->recv_total_avg = total_recv/age; // application level statistics if (zconf.fsconf.app_success_index >= 0) { exp->app_success_rate = (app_success - intrnl->last_recv_app_success)/delta; number_string(exp->app_success_rate, exp->app_success_rate_str, NUMBER_STR_LEN); exp->app_success_avg = (app_success/age); number_string(exp->app_success_avg, exp->app_success_avg_str, NUMBER_STR_LEN); } if (!total_sent) { exp->hitrate = 0; exp->app_hitrate = 0; } else { exp->hitrate = recv_success*100.0/total_sent; exp->app_hitrate = app_success*100.0/total_sent; } if (age > WARMUP_PERIOD && exp->hitrate < zconf.min_hitrate) { if (fabs(intrnl->min_hitrate_start) < .00001) { intrnl->min_hitrate_start = cur_time; } } else { intrnl->min_hitrate_start = 0.0; } if (fabs(intrnl->min_hitrate_start) < .00001) { exp->seconds_under_min_hitrate = 0; } else { exp->seconds_under_min_hitrate = cur_time - intrnl->min_hitrate_start; } if (!zsend.complete) { exp->send_rate = (total_sent - intrnl->last_sent)/delta; number_string(exp->send_rate, exp->send_rate_str, NUMBER_STR_LEN); exp->send_rate_avg = total_sent/age; number_string(exp->send_rate_avg, exp->send_rate_avg_str, NUMBER_STR_LEN); } else { exp->send_rate_avg = total_sent/(zsend.finish - zsend.start); number_string(exp->send_rate_avg, exp->send_rate_avg_str, NUMBER_STR_LEN); } // export other pre-calculated values exp->total_sent = total_sent; exp->percent_complete = 100.*age/(age + remaining_secs); exp->recv_success_unique = recv_success; exp->app_recv_success_unique = app_success; exp->total_recv = total_recv; exp->complete = zsend.complete; // pcap dropped packets exp->pcap_drop = zrecv.pcap_drop; exp->pcap_ifdrop = zrecv.pcap_ifdrop; exp->pcap_drop_total = exp->pcap_drop + exp->pcap_ifdrop; exp->pcap_drop_last = (exp->pcap_drop_total - intrnl->last_pcap_drop)/delta; exp->pcap_drop_avg = exp->pcap_drop_total/age; number_string(exp->pcap_drop_total, exp->pcap_drop_total_str, NUMBER_STR_LEN); number_string(exp->pcap_drop_last, exp->pcap_drop_last_str, NUMBER_STR_LEN); number_string(exp->pcap_drop_avg, exp->pcap_drop_avg_str, NUMBER_STR_LEN); zsend.sendto_failures = total_fail; exp->fail_total = zsend.sendto_failures; exp->fail_last = (exp->fail_total - intrnl->last_send_failures) / delta; exp->fail_avg = exp->fail_total/age; // misc exp->send_threads = iterator_get_curr_send_threads(it); // Update internal stats intrnl->last_now = cur_time; intrnl->last_sent = exp->total_sent; intrnl->last_recv_net_success = exp->recv_success_unique; intrnl->last_recv_app_success = exp->app_recv_success_unique; intrnl->last_pcap_drop = exp->pcap_drop_total; intrnl->last_send_failures = exp->fail_total; intrnl->last_recv_total = exp->total_recv; }
static void monitor_update(iterator_t *it, pthread_mutex_t *recv_ready_mutex) { uint32_t total_sent = iterator_get_sent(it); if (last_now > 0.0) { double age = now() - zsend.start; double delta = now() - last_now; double remaining_secs = compute_remaining_time(age, total_sent); double percent_complete = 100.*age/(age + remaining_secs); // ask pcap for fresh values pthread_mutex_lock(recv_ready_mutex); recv_update_pcap_stats(); pthread_mutex_unlock(recv_ready_mutex); // format times for display char time_left[20]; if (age < 5) { time_left[0] = '\0'; } else { char buf[20]; time_string(ceil(remaining_secs), 1, buf, sizeof(buf)); snprintf(time_left, sizeof(time_left), " (%s left)", buf); } char time_past[20]; time_string((int)age, 0, time_past, sizeof(time_past)); char send_rate[20], send_avg[20], recv_rate[20], recv_avg[20], pcap_drop[20], pcap_drop_avg[20]; // recv stats number_string((zrecv.success_unique - last_rcvd)/delta, recv_rate, sizeof(recv_rate)); number_string((zrecv.success_unique/age), recv_avg, sizeof(recv_avg)); // dropped stats number_string((zrecv.pcap_drop + zrecv.pcap_ifdrop - last_drop)/delta, pcap_drop, sizeof(pcap_drop)); number_string(((zrecv.pcap_drop + zrecv.pcap_ifdrop)/age), pcap_drop_avg, sizeof(pcap_drop_avg)); // Warn if we drop > 5% of our average receive rate uint32_t drop_rate = (uint32_t)((zrecv.pcap_drop + zrecv.pcap_ifdrop - last_drop) / delta); if (drop_rate > (uint32_t)((zrecv.success_unique - last_rcvd) / delta) / 20) { log_warn("monitor", "Dropped %d packets in the last second, (%d total dropped (pcap: %d + iface: %d))", drop_rate, zrecv.pcap_drop + zrecv.pcap_ifdrop, zrecv.pcap_drop, zrecv.pcap_ifdrop); } // Warn if we fail to send > 1% of our average send rate uint32_t fail_rate = (uint32_t)((zsend.sendto_failures - last_failures) / delta); // failures/sec if (fail_rate > ((total_sent / age) / 100)) { log_warn("monitor", "Failed to send %d packets/sec (%d total failures)", fail_rate, zsend.sendto_failures); } float hits; if (!total_sent) { hits = 0; } else { hits = zrecv.success_unique*100./total_sent; } if (!zsend.complete) { // main display (during sending) number_string((total_sent - last_sent)/delta, send_rate, sizeof(send_rate)); number_string((total_sent/age), send_avg, sizeof(send_avg)); fprintf(stderr, "%5s %0.0f%%%s; send: %u %sp/s (%sp/s avg); " "recv: %u %sp/s (%sp/s avg); " "drops: %sp/s (%sp/s avg); " "hits: %0.2f%%\n", time_past, percent_complete, time_left, total_sent, send_rate, send_avg, zrecv.success_unique, recv_rate, recv_avg, pcap_drop, pcap_drop_avg, hits); } else { // alternate display (during cooldown) number_string((total_sent/(zsend.finish - zsend.start)), send_avg, sizeof(send_avg)); fprintf(stderr, "%5s %0.0f%%%s; send: %u done (%sp/s avg); " "recv: %u %sp/s (%sp/s avg); " "drops: %sp/s (%sp/s avg); " "hits: %0.2f%%\n", time_past, percent_complete, time_left, total_sent, send_avg, zrecv.success_unique, recv_rate, recv_avg, pcap_drop, pcap_drop_avg, hits); } } last_now = now(); last_sent = total_sent; last_rcvd = zrecv.success_unique; last_drop = zrecv.pcap_drop + zrecv.pcap_ifdrop; last_failures = zsend.sendto_failures; }
static void export_stats(int_status_t *intrnl, export_status_t *exp, iterator_t *it) { uint32_t total_sent = iterator_get_sent(it); double age = now() - zsend.start; // time of entire scan double delta = now() - intrnl->last_now; // time since the last time we updated double remaining_secs = compute_remaining_time(age, total_sent); // export amount of time the scan has been running if (age < 5) { exp->time_remaining_str[0] = '\0'; } else { char buf[20]; time_string(ceil(remaining_secs), 1, buf, sizeof(buf)); snprintf(exp->time_remaining_str, NUMBER_STR_LEN, " (%s left)", buf); } exp->time_past = age; exp->time_remaining = remaining_secs; time_string((int)age, 0, exp->time_past_str, NUMBER_STR_LEN); // export recv statistics exp->recv_rate = (zrecv.success_unique - intrnl->last_recv_net_success)/delta; number_string(exp->recv_rate, exp->recv_rate_str, NUMBER_STR_LEN); exp->recv_avg = zrecv.success_unique/age; number_string(exp->recv_avg, exp->recv_avg_str, NUMBER_STR_LEN); // application level statistics if (zconf.fsconf.app_success_index >= 0) { exp->app_success_rate = (zrecv.app_success_unique - intrnl->last_recv_app_success)/delta; number_string(exp->app_success_rate, exp->app_success_rate_str, NUMBER_STR_LEN); exp->app_success_avg = (zrecv.app_success_unique/age); number_string(exp->app_success_avg, exp->app_success_avg_str, NUMBER_STR_LEN); } if (!total_sent) { exp->hitrate = 0; exp->app_hitrate = 0; } else { exp->hitrate = zrecv.success_unique*100./total_sent; exp->app_hitrate = zrecv.app_success_unique*100./total_sent; } if (!zsend.complete) { exp->send_rate = (total_sent - intrnl->last_sent)/delta; number_string(exp->send_rate, exp->send_rate_str, NUMBER_STR_LEN); exp->send_rate_avg = total_sent/age; number_string(exp->send_rate_avg, exp->send_rate_avg_str, NUMBER_STR_LEN); } else { exp->send_rate_avg = total_sent/(zsend.finish - zsend.start); number_string(exp->send_rate_avg, exp->send_rate_avg_str, NUMBER_STR_LEN); } // export other pre-calculated values exp->total_sent = total_sent; exp->percent_complete = 100.*age/(age + remaining_secs); exp->recv_success_unique = zrecv.success_unique; exp->app_recv_success_unique = zrecv.app_success_unique; exp->complete = zsend.complete; // pcap dropped packets exp->pcap_drop = zrecv.pcap_drop; exp->pcap_ifdrop = zrecv.pcap_ifdrop; exp->pcap_drop_total = zrecv.pcap_drop + zrecv.pcap_ifdrop; exp->pcap_drop_last = (zrecv.pcap_drop + zrecv.pcap_ifdrop - intrnl->last_pcap_drop)/delta; exp->pcap_drop_avg = (zrecv.pcap_drop + zrecv.pcap_ifdrop)/age; number_string(exp->pcap_drop_total, exp->pcap_drop_total_str, NUMBER_STR_LEN); number_string(exp->pcap_drop_last, exp->pcap_drop_last_str, NUMBER_STR_LEN); number_string(exp->pcap_drop_avg, exp->pcap_drop_avg_str, NUMBER_STR_LEN); exp->fail_total = zsend.sendto_failures; exp->fail_last = (zsend.sendto_failures - intrnl->last_send_failures) / delta; exp->fail_avg = zsend.sendto_failures/age; // misc exp->send_threads = iterator_get_curr_send_threads(it); }