Пример #1
0
void print_stats() {
  static u_int8_t print_all = 0;
  static struct timeval lastTime;
  static u_int64_t lastPkts = 0, lastBytes = 0, lastDrops = 0, lastSlavePkts = 0, lastSlaveDrops = 0; 
  unsigned long long nBytes = 0, nPkts = 0, nDrops = 0, nSlavePkts = 0, nSlaveDrops = 0;
  struct timeval endTime;
  char buf1[64], buf2[64], buf3[64], buf4[64], buf5[64];
  pfring_zc_stat stats; 
  int i;  

  if(startTime.tv_sec == 0)
    gettimeofday(&startTime, NULL);
  else
    print_all = 1;

  gettimeofday(&endTime, NULL);

  nPkts  = globals->numPkts;
  nBytes = globals->numBytes;
  if (pfring_zc_stats(inzq, &stats) == 0)
    nDrops = stats.drop;
  nSlavePkts  = globals->sentPkts;
  for (i = 0; i < num_slaves; i++) 
    if (pfring_zc_stats(outzq[i], &stats) == 0) 
      nSlaveDrops += stats.drop; 

  fprintf(stderr, "=========================\n"
	  "Absolute Stats: Recv %s pkts (%s drops) %s bytes - Forwarded %s pkts (%s drops)\n", 
	  pfring_format_numbers((double)nPkts, buf1, sizeof(buf1), 0),
	  pfring_format_numbers((double)nDrops, buf2, sizeof(buf2), 0),
	  pfring_format_numbers((double)nBytes, buf3, sizeof(buf3), 0),
	  pfring_format_numbers((double)nSlavePkts, buf4, sizeof(buf4), 0),
	  pfring_format_numbers((double)nSlaveDrops, buf5, sizeof(buf5), 0));

  if(print_all && lastTime.tv_sec > 0) {
    double deltaMillisec = delta_time(&endTime, &lastTime);
    double bytesDiff = ((double) (nBytes - lastBytes) * 8) / (1000*1000*1000);
    unsigned long long pktsDiff = nPkts-lastPkts;
    unsigned long long dropsDiff = nDrops - lastDrops;
    unsigned long long slavePktsDiff = nSlavePkts - lastSlavePkts;
    unsigned long long slaveDropsDiff = nSlaveDrops - lastSlaveDrops;

    fprintf(stderr,
	     "Actual Stats: Recv %s pps (%s drops) %s Gbps - Forwarded %s pps (%s drops)\n",
	     pfring_format_numbers(((double)pktsDiff/(double)(deltaMillisec/1000)), buf1, sizeof(buf1), 1),
	     pfring_format_numbers(((double)dropsDiff/(double)(deltaMillisec/1000)), buf2, sizeof(buf2), 1),
	     pfring_format_numbers(((double)bytesDiff/(double)(deltaMillisec/1000)), buf3, sizeof(buf3), 1),
	     pfring_format_numbers(((double)slavePktsDiff/(double)(deltaMillisec/1000)), buf4, sizeof(buf4), 1),
	     pfring_format_numbers(((double)slaveDropsDiff/(double)(deltaMillisec/1000)), buf5, sizeof(buf5), 1));
  }
    
  fprintf(stderr, "=========================\n\n");

  lastPkts = nPkts, lastBytes = nBytes, lastDrops = nDrops;
  lastSlavePkts = nSlavePkts, lastSlaveDrops = nSlaveDrops;
  lastTime.tv_sec = endTime.tv_sec, lastTime.tv_usec = endTime.tv_usec;
}
Пример #2
0
static int update_hw_stats(Pfring_Context_t *context) {
    pfring_zc_stat ps;
    int i;

    for (i = 0; i < context->num_devices; i++)
        if (context->rx_queues[i] == NULL)
            /* daq stopped - using last available stats */
            return DAQ_SUCCESS;

    context->stats.hw_packets_received = 0;
    context->stats.hw_packets_dropped = 0;

    for (i = 0; i < context->num_devices; i++) {
        memset(&ps, 0, sizeof(pfring_zc_stat));

        if (pfring_zc_stats(context->rx_queues[i], &ps) < 0) {
            DPE(context->errbuf, "%s: pfring_stats error [ring_idx = %d]", __FUNCTION__, i);
            return DAQ_ERROR;
        }

        context->stats.hw_packets_received += (ps.recv - context->base_recv[i]);
        context->stats.hw_packets_dropped  += (ps.drop - context->base_drop[i]);
    }

    return DAQ_SUCCESS;
}
Пример #3
0
void print_stats() {
  struct timeval endTime;
  double deltaMillisec;
  static u_int8_t print_all;
  static u_int64_t lastPkts = 0;
  static u_int64_t lastDrops = 0;
  static u_int64_t lastBytes = 0;
  double pktsDiff, dropsDiff, bytesDiff;
  static struct timeval lastTime;
  char buf1[64], buf2[64], buf3[64];
  unsigned long long nBytes = 0, nPkts = 0, nDrops = 0;
  pfring_zc_stat stats;

  if(startTime.tv_sec == 0) {
    gettimeofday(&startTime, NULL);
    print_all = 0;
  } else
    print_all = 1;

  gettimeofday(&endTime, NULL);
  deltaMillisec = delta_time(&endTime, &startTime);

  nBytes = globals->numBytes;
  nPkts = globals->numPkts;
  if (pfring_zc_stats(zq, &stats) == 0)
    nDrops = stats.drop;
  else
    printf("Error reading drop stats\n");

  fprintf(stderr, "=========================\n"
	  "Absolute Stats: %s pkts (%s drops) - %s bytes\n", 
	  pfring_format_numbers((double)nPkts, buf1, sizeof(buf1), 0),
	  pfring_format_numbers((double)nDrops, buf2, sizeof(buf2), 0),
	  pfring_format_numbers((double)nBytes, buf3, sizeof(buf3), 0));

  if(print_all && (lastTime.tv_sec > 0)) {
    char buf[256];

    deltaMillisec = delta_time(&endTime, &lastTime);
    pktsDiff = nPkts-lastPkts;
    dropsDiff = nDrops-lastDrops;
    bytesDiff = nBytes - lastBytes;
    bytesDiff /= (1000*1000*1000)/8;

    snprintf(buf, sizeof(buf),
	     "Actual Stats: %s pps (%s drops) - %s Gbps",
	     pfring_format_numbers(((double)pktsDiff/(double)(deltaMillisec/1000)),  buf1, sizeof(buf1), 1),
	     pfring_format_numbers(((double)dropsDiff/(double)(deltaMillisec/1000)),  buf2, sizeof(buf2), 1),
	     pfring_format_numbers(((double)bytesDiff/(double)(deltaMillisec/1000)),  buf3, sizeof(buf3), 1));
    fprintf(stderr, "%s\n", buf);
  }
    
  fprintf(stderr, "=========================\n\n");

  lastPkts = nPkts, lastDrops = nDrops, lastBytes = nBytes;
  lastTime.tv_sec = endTime.tv_sec, lastTime.tv_usec = endTime.tv_usec;
}
Пример #4
0
int recv_update_stats(void)
{
	if (!pf_recv) {
		return EXIT_FAILURE;
	}
	pfring_zc_stat pfst;
	if (pfring_zc_stats(pf_recv, &pfst)) {
		log_error("recv", "unable to retrieve pfring statistics");
		return EXIT_FAILURE;
	} else {
		zrecv.pcap_recv = pfst.recv;
		zrecv.pcap_drop = pfst.drop;
	}
	return EXIT_SUCCESS;
}
Пример #5
0
static void pfring_zc_daq_reset_stats(void *handle) {
    Pfring_Context_t *context =(Pfring_Context_t *) handle;
    pfring_zc_stat ps;
    int i;

    memset(&context->stats, 0, sizeof(DAQ_Stats_t));
    memset(&ps, 0, sizeof(pfring_zc_stat));

    for (i = 0; i < context->num_devices; i++) {
        if (context->rx_queues[i] && pfring_zc_stats(context->rx_queues[i], &ps) == 0) {
            context->base_recv[i] = ps.recv;
            context->base_drop[i] = ps.drop;
        }
    }
}
Пример #6
0
void print_stats() {
  static u_int8_t print_all = 0;
  static struct timeval last_time;
  static unsigned long long last_tot_recv = 0, last_tot_queues_recv = 0;
  unsigned long long tot_recv = 0, tot_drop = 0, tot_queues_recv = 0, tot_queues_drop = 0;
  struct timeval end_time;
  char buf1[64], buf2[64];
  pfring_zc_stat stats;
  int i;

  if(start_time.tv_sec == 0)
    gettimeofday(&start_time, NULL);
  else
    print_all = 1;

  gettimeofday(&end_time, NULL);

  fprintf(stderr, "=========================\nAbsolute Stats: ");

  if (in_device != NULL) {
    if (pfring_zc_stats(forwarder[RX_FWDR].inzq, &stats) == 0)
      tot_recv += stats.recv, tot_drop += stats.drop;

    fprintf(stderr, "Recv %s pkts [Drop %s pkts] ", 
      pfring_format_numbers((double)tot_recv, buf1, sizeof(buf1), 0),
      pfring_format_numbers((double)tot_drop, buf2, sizeof(buf2), 0)
    );
  }

  fprintf(stderr, "Processed ");

  for (i = 0; i < num_ipc_queues; i++) {
    if (pfring_zc_stats(ipczqs[i], &stats) == 0) {
      fprintf(stderr, "Q%u %s pkts ", i, pfring_format_numbers((double) stats.recv, buf1, sizeof(buf1), 0));
      tot_queues_recv += stats.recv, tot_queues_drop += stats.drop;
    }
  }

  /* Average */
  tot_queues_recv /= num_ipc_queues;
  tot_queues_drop /= num_ipc_queues;

  fprintf(stderr, "AVG %s pkts [Drop %s pkts]\n", 
    pfring_format_numbers((double)tot_queues_recv, buf1, sizeof(buf1), 0),
    pfring_format_numbers((double)tot_queues_drop, buf2, sizeof(buf2), 0)
  );

  if(print_all && last_time.tv_sec > 0) {
    double delta_msec = delta_time(&end_time, &last_time);
    unsigned long long diff_recv = tot_recv - last_tot_recv;
    unsigned long long diff_queues_recv = tot_queues_recv - last_tot_queues_recv;

    fprintf(stderr, "Actual Stats: Recv %s pps Processed AVG %s pps\n",
      pfring_format_numbers(((double)diff_recv/(double)(delta_msec/1000)), buf1, sizeof(buf1), 1),
      pfring_format_numbers(((double)diff_queues_recv/(double)(delta_msec/1000)), buf2, sizeof(buf2), 1)
    );
  }
  
  fprintf(stderr, "=========================\n\n");
 
  last_tot_recv = tot_recv, last_tot_queues_recv = tot_queues_recv;
  last_time.tv_sec = end_time.tv_sec, last_time.tv_usec = end_time.tv_usec;
}
Пример #7
0
void print_stats() {
  static u_int8_t print_all = 0;
  static struct timeval last_time;
  static unsigned long long last_tot_recv = 0, last_tot_sent = 0, last_tot_drop = 0;
  unsigned long long tot_recv = 0, tot_drop = 0, tot_sent = 0;
  struct timeval end_time;
  char buf1[64], buf2[64], buf3[64];
  pfring_zc_stat stats;
  char stats_buf[1024] = { '\0' };
  int i;
  u_int64_t tot_if_recv = 0, tot_if_drop = 0;

  if(start_time.tv_sec == 0)
    gettimeofday(&start_time, NULL);
  else
    print_all = 1;

  gettimeofday(&end_time, NULL);

  for(i = 0; i < num_in_devices; i++)
    if(pfring_zc_stats(inzqs[i], &stats) == 0)
      tot_recv += stats.recv, tot_drop += stats.drop;

  for(i = 0; i < num_out_devices; i++)
    if(pfring_zc_stats(outzqs[i], &stats) == 0)
      tot_sent += stats.sent;

  fprintf(stderr, "=========================\n"
          "Absolute Stats: Recv %s pkts (%s drops) - Forwarded %s pkts\n",
	  pfring_format_numbers((double)tot_recv, buf1, sizeof(buf1), 0),
	  pfring_format_numbers((double)tot_drop, buf2, sizeof(buf2), 0),
	  pfring_format_numbers((double)tot_sent, buf3, sizeof(buf3), 0)
	  );


  for(i = 0; i < num_in_devices; i++) {
    if(pfring_zc_stats(inzqs[i], &stats) == 0) {
      tot_if_recv += stats.recv, tot_if_drop += stats.drop;
      fprintf(stderr, "                %s RX %lu pkts Dropped %lu pkts (%.1f %%)\n",
	      in_devices[i], 
	      (long unsigned int)stats.recv,
	      (long unsigned int)stats.drop,
	      stats.recv == 0 ? 0 : ((double)(stats.drop*100)/(double)(stats.recv + stats.drop)));
    }
  }
  snprintf(&stats_buf[strlen(stats_buf)], sizeof(stats_buf)-strlen(stats_buf),
	   "IFPackets:         %lu\n"
	   "tot_if_dropped:         %lu\n",
	   (long unsigned int)tot_if_recv,
	   (long unsigned int)tot_if_drop);

  pfring_zc_set_proc_stats(zc, stats_buf);

  if(print_all && last_time.tv_sec > 0) {
    double delta_msec = delta_time(&end_time, &last_time);
    unsigned long long diff_recv = tot_recv - last_tot_recv;
    unsigned long long diff_drop = tot_drop - last_tot_drop;
    unsigned long long diff_sent = tot_sent - last_tot_sent;

    fprintf(stderr, "Actual Stats: Recv %s pps (%s drops) - Forwarded %s pps\n",
	    pfring_format_numbers(((double)diff_recv/(double)(delta_msec/1000)),  buf1, sizeof(buf1), 1),
	    pfring_format_numbers(((double)diff_drop/(double)(delta_msec/1000)),  buf2, sizeof(buf2), 1),
	    pfring_format_numbers(((double)diff_sent/(double)(delta_msec/1000)),  buf3, sizeof(buf3), 1)
	    );
  }

  fprintf(stderr, "=========================\n\n");

  last_tot_recv = tot_recv, last_tot_drop = tot_drop, last_tot_sent = tot_sent;
  last_time.tv_sec = end_time.tv_sec, last_time.tv_usec = end_time.tv_usec;
}