2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009 - 2012 Daniel Borkmann.
5 * Subject to the GPL, version 2.
7 * A tiny tool to provide top-like reliable networking statistics.
8 * Why? Well, some time ago I used iptraf to display network traffic
9 * statistics. During that time and probably also today, they are
10 * using libpcap to collect statistics. Well, bad idea since this
11 * will give you false statistics on high I/O load. Therefore, ifpps
12 * reads out the 'real' kernel statistics, so things your NIC sees
13 * and not some userland library.
15 * He had all the injured air of a liar suspected when for once he
16 * has told the truth, or part of it.
18 * -- The Lord of the Rings, On Gollum,
19 * Chapter 'The Black Gate is Closed'.
27 #include <sys/socket.h>
41 int16_t link_qual
, link_qual_max
;
42 int signal_level
, noise_level
;
46 uint64_t rx_bytes
, rx_packets
, rx_drops
, rx_errors
;
47 uint64_t rx_fifo
, rx_frame
, rx_multi
;
48 uint64_t tx_bytes
, tx_packets
, tx_drops
, tx_errors
;
49 uint64_t tx_fifo
, tx_colls
, tx_carrier
;
50 uint64_t irqs
[MAX_CPUS
], irqs_srx
[MAX_CPUS
], irqs_stx
[MAX_CPUS
];
51 int64_t cpu_user
[MAX_CPUS
], cpu_nice
[MAX_CPUS
], cpu_sys
[MAX_CPUS
];
52 int64_t cpu_idle
[MAX_CPUS
], cpu_iow
[MAX_CPUS
], mem_free
, mem_total
;
53 int32_t cswitch
, forks
, procs_run
, procs_iow
;
55 struct wifi_stat wifi
;
58 volatile sig_atomic_t sigint
= 0;
60 static struct ifstat stats_old
, stats_new
, stats_delta
;
62 static int stats_loop
= 0;
64 static WINDOW
*stats_screen
= NULL
;
66 static const char *short_options
= "d:t:vhclp";
67 static const struct option long_options
[] = {
68 {"dev", required_argument
, NULL
, 'd'},
69 {"interval", required_argument
, NULL
, 't'},
70 {"promisc", no_argument
, NULL
, 'p'},
71 {"csv", no_argument
, NULL
, 'c'},
72 {"loop", no_argument
, NULL
, 'l'},
73 {"version", no_argument
, NULL
, 'v'},
74 {"help", no_argument
, NULL
, 'h'},
78 static void signal_handler(int number
)
90 static inline char *snr_to_str(int level
)
93 return "very good signal";
94 if (level
> 25 && level
<= 40)
96 if (level
> 15 && level
<= 25)
98 if (level
> 10 && level
<= 15)
99 return "very poor signal";
106 static inline int iswireless(const struct ifstat
*stats
)
108 return stats
->wifi
.bitrate
> 0;
111 static void help(void)
113 printf("\nifpps %s, top-like kernel networking and system statistics\n",
115 puts("http://www.netsniff-ng.org\n\n"
116 "Usage: ifpps [options] || ifpps <netdev>\n"
118 " -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
119 " -t|--interval <time> Refresh time in ms (default 500 ms)\n"
120 " -p|--promisc Promiscuous mode\n"
121 " -c|--csv Output to terminal as CSV\n"
122 " E.g. post-processing with Gnuplot et al.\n"
123 " -l|--loop Continuous CSV output\n"
124 " -v|--version Print version\n"
125 " -h|--help Print this help\n\n"
129 " ifpps -lpcd wlan0 > plot.dat\n\n"
130 "Please report bugs to <bugs@netsniff-ng.org>\n"
131 "Copyright (C) 2009-2012 Daniel Borkmann <daniel@netsniff-ng.org>\n"
132 "License: GNU GPL version 2.0\n"
133 "This is free software: you are free to change and redistribute it.\n"
134 "There is NO WARRANTY, to the extent permitted by law.\n");
138 static void version(void)
140 printf("\nifpps %s, top-like kernel networking and system statistics\n",
142 puts("http://www.netsniff-ng.org\n\n"
143 "Please report bugs to <bugs@netsniff-ng.org>\n"
144 "Copyright (C) 2009-2012 Daniel Borkmann <daniel@netsniff-ng.org>\n"
145 "License: GNU GPL version 2.0\n"
146 "This is free software: you are free to change and redistribute it.\n"
147 "There is NO WARRANTY, to the extent permitted by law.\n");
151 static int stats_proc_net_dev(const char *ifname
, struct ifstat
*stats
)
157 fp
= fopen("/proc/net/dev", "r");
159 panic("Cannot open /proc/net/dev!\n");
161 /* Omit table header from procfs file */
162 if (fgets(buff
, sizeof(buff
), fp
));
163 if (fgets(buff
, sizeof(buff
), fp
));
165 memset(buff
, 0, sizeof(buff
));
167 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
168 buff
[sizeof(buff
) -1] = 0;
170 if (strstr(buff
, ifname
) == NULL
)
173 if (sscanf(buff
, "%*[a-z0-9 .-]:%lu%lu%lu%lu%lu%lu"
174 "%lu%*u%lu%lu%lu%lu%lu%lu%lu",
175 &stats
->rx_bytes
, &stats
->rx_packets
,
176 &stats
->rx_errors
, &stats
->rx_drops
,
177 &stats
->rx_fifo
, &stats
->rx_frame
,
178 &stats
->rx_multi
, &stats
->tx_bytes
,
179 &stats
->tx_packets
, &stats
->tx_errors
,
180 &stats
->tx_drops
, &stats
->tx_fifo
,
181 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
186 memset(buff
, 0, sizeof(buff
));
193 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
195 int ret
= -EINVAL
, i
, cpus
, try = 0;
196 char *ptr
, buff
[256];
197 struct ethtool_drvinfo drvinf
;
200 fp
= fopen("/proc/interrupts", "r");
202 panic("Cannot open /proc/interrupts!\n");
204 cpus
= get_number_cpus();
205 bug_on(cpus
> MAX_CPUS
);
207 fseek(fp
, 0, SEEK_SET
);
208 memset(buff
, 0, sizeof(buff
));
210 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
211 buff
[sizeof(buff
) - 1] = 0;
214 if (strstr(buff
, ifname
) == NULL
)
217 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
218 bug_on(stats
->irq_nr
== 0);
221 ptr
++; /* Skip ':' char */
222 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
223 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
230 memset(buff
, 0, sizeof(buff
));
233 /* We could get caught here in case of wireless devices which
234 * are not necessarily listed under 'wlan0' et al. in
235 * proc/interrupts. Therefore, we try once again with the
236 * ethtool driver name.
238 if (ret
== -EINVAL
&& try == 0) {
239 memset(&drvinf
, 0, sizeof(drvinf
));
240 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
243 ifname
= drvinf
.driver
;
253 static int stats_proc_softirqs(struct ifstat
*stats
)
256 char *ptr
, buff
[256];
262 } net_type
= softirqs_net_none
;
264 fp
= fopen("/proc/softirqs", "r");
266 panic("Cannot open /proc/softirqs!\n");
268 cpus
= get_number_cpus();
269 bug_on(cpus
> MAX_CPUS
);
271 memset(buff
, 0, sizeof(buff
));
273 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
274 buff
[sizeof(buff
) - 1] = 0;
276 if ((ptr
= strstr(buff
, "NET_TX:")))
277 net_type
= softirqs_net_tx
;
278 else if ((ptr
= strstr(buff
, "NET_RX:")))
279 net_type
= softirqs_net_rx
;
283 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
285 case softirqs_net_tx
:
286 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
288 case softirqs_net_rx
:
289 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
296 memset(buff
, 0, sizeof(buff
));
303 static int stats_proc_memory(struct ifstat
*stats
)
305 char *ptr
, buff
[256];
308 fp
= fopen("/proc/meminfo", "r");
310 panic("Cannot open /proc/meminfo!\n");
312 memset(buff
, 0, sizeof(buff
));
314 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
315 buff
[sizeof(buff
) - 1] = 0;
317 if ((ptr
= strstr(buff
, "MemTotal:"))) {
318 ptr
+= strlen("MemTotal:");
319 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
320 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
321 ptr
+= strlen("MemFree:");
322 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
325 memset(buff
, 0, sizeof(buff
));
332 static int stats_proc_system(struct ifstat
*stats
)
335 char *ptr
, buff
[256];
338 fp
= fopen("/proc/stat", "r");
340 panic("Cannot open /proc/stat!\n");
342 cpus
= get_number_cpus();
343 bug_on(cpus
> MAX_CPUS
);
345 memset(buff
, 0, sizeof(buff
));
347 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
348 buff
[sizeof(buff
) - 1] = 0;
350 if ((ptr
= strstr(buff
, "cpu"))) {
351 ptr
+= strlen("cpu");
355 cpu
= strtol(ptr
, &ptr
, 10);
358 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
359 &stats
->cpu_user
[cpu
],
360 &stats
->cpu_nice
[cpu
],
361 &stats
->cpu_sys
[cpu
],
362 &stats
->cpu_idle
[cpu
],
363 &stats
->cpu_iow
[cpu
]) != 5)
365 } else if ((ptr
= strstr(buff
, "ctxt"))) {
366 ptr
+= strlen("ctxt");
367 stats
->cswitch
= strtol(ptr
, &ptr
, 10);
368 } else if ((ptr
= strstr(buff
, "processes"))) {
369 ptr
+= strlen("processes");
370 stats
->forks
= strtol(ptr
, &ptr
, 10);
371 } else if ((ptr
= strstr(buff
, "procs_running"))) {
372 ptr
+= strlen("procs_running");
373 stats
->procs_run
= strtol(ptr
, &ptr
, 10);
374 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
375 ptr
+= strlen("procs_blocked");
376 stats
->procs_iow
= strtol(ptr
, &ptr
, 10);
379 memset(buff
, 0, sizeof(buff
));
386 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
389 struct iw_statistics ws
;
391 ret
= wireless_sigqual(ifname
, &ws
);
393 stats
->wifi
.bitrate
= 0;
397 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
399 stats
->wifi
.signal_level
=
400 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
401 stats
->wifi
.noise_level
=
402 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.noise
);
404 stats
->wifi
.link_qual
= ws
.qual
.qual
;
405 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
410 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
411 #define DIFF(member) do { \
412 if (sizeof(diff->member) != sizeof(new->member) || \
413 sizeof(diff->member) != sizeof(old->member)) \
415 bug_on((new->member - old->member) > (new->member)); \
419 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
444 DIFF1(wifi
.signal_level
);
445 DIFF1(wifi
.noise_level
);
447 DIFF1(wifi
.link_qual
);
452 cpus
= get_number_cpus();
453 bug_on(cpus
> MAX_CPUS
);
455 for (i
= 0; i
< cpus
; ++i
) {
468 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
470 if (stats_proc_net_dev(ifname
, stats
) < 0)
471 panic("Cannot fetch device stats!\n");
472 if (stats_proc_softirqs(stats
) < 0)
473 panic("Cannot fetch software interrupts!\n");
474 if (stats_proc_memory(stats
) < 0)
475 panic("Cannot fetch memory stats!\n");
476 if (stats_proc_system(stats
) < 0)
477 panic("Cannot fetch system stats!\n");
479 stats_proc_interrupts((char *) ifname
, stats
);
481 stats_wireless(ifname
, stats
);
484 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
486 memset(&stats_old
, 0, sizeof(stats_old
));
487 memset(&stats_new
, 0, sizeof(stats_new
));
488 memset(&stats_delta
, 0, sizeof(stats_delta
));
490 stats_fetch(ifname
, &stats_old
);
491 usleep(ms_interval
* 1000);
492 stats_fetch(ifname
, &stats_new
);
494 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
497 static void screen_init(WINDOW
**screen
)
499 (*screen
) = initscr();
502 nodelay((*screen
), TRUE
);
507 static void screen_header(WINDOW
*screen
, const char *ifname
, int *voff
,
508 uint64_t ms_interval
)
511 struct ethtool_drvinfo drvinf
;
512 const char *rate
= ethtool_bitrate_str(ethtool_bitrate(ifname
));
514 memset(&drvinf
, 0, sizeof(drvinf
));
515 ethtool_drvinf(ifname
, &drvinf
);
517 memset(buff
, 0, sizeof(buff
));
519 slprintf(buff
, sizeof(buff
), ", %s", rate
);
521 mvwprintw(screen
, (*voff
)++, 2,
522 "Kernel net/sys statistics for %s (%s%s), t=%lums",
523 ifname
, drvinf
.driver
, buff
, ms_interval
);
526 static void screen_net_dev_rel(WINDOW
*screen
, const struct ifstat
*rel
,
531 mvwprintw(screen
, (*voff
)++, 0,
532 " RX: %16.3lf MiB/t "
536 1.0 * rel
->rx_bytes
/ (1 << 20),
537 rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
539 mvwprintw(screen
, (*voff
)++, 0,
540 " TX: %16.3lf MiB/t "
544 1.0 * rel
->tx_bytes
/ (1 << 20),
545 rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
550 static void screen_net_dev_abs(WINDOW
*screen
, const struct ifstat
*abs
,
553 mvwprintw(screen
, (*voff
)++, 2,
558 1.0 * abs
->rx_bytes
/ (1 << 20),
559 abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
561 mvwprintw(screen
, (*voff
)++, 2,
566 1.0 * abs
->tx_bytes
/ (1 << 20),
567 abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
570 static void screen_sys_mem(WINDOW
*screen
, const struct ifstat
*rel
,
571 const struct ifstat
*abs
, int *voff
)
573 mvwprintw(screen
, (*voff
)++, 2,
579 100.0 * (abs
->mem_total
- abs
->mem_free
) / abs
->mem_total
,
580 abs
->procs_run
, abs
->procs_iow
);
583 static void screen_percpu_states(WINDOW
*screen
, const struct ifstat
*rel
,
589 for (i
= 0; i
< cpus
; ++i
) {
590 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] +
591 rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
593 mvwprintw(screen
, (*voff
)++, 2,
594 "CPU%d: %13.1lf%% usr/t "
597 "%11.1lf%% iow/t ", i
,
598 100.0 * (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
,
599 100.0 * rel
->cpu_sys
[i
] / all
,
600 100.0 * rel
->cpu_idle
[i
] / all
,
601 100.0 * rel
->cpu_iow
[i
] / all
);
605 static void screen_percpu_irqs_rel(WINDOW
*screen
, const struct ifstat
*rel
,
610 for (i
= 0; i
< cpus
; ++i
) {
611 mvwprintw(screen
, (*voff
)++, 2,
612 "CPU%d: %14ld irqs/t "
614 "%15ld soirq TX/t ", i
,
621 static void screen_percpu_irqs_abs(WINDOW
*screen
, const struct ifstat
*abs
,
626 for (i
= 0; i
< cpus
; ++i
) {
627 mvwprintw(screen
, (*voff
)++, 2,
628 "CPU%d: %14ld irqs", i
,
633 static void screen_wireless(WINDOW
*screen
, const struct ifstat
*rel
,
634 const struct ifstat
*abs
, int *voff
)
636 if (iswireless(abs
)) {
637 mvwprintw(screen
, (*voff
)++, 2,
638 "LinkQual: %7d/%d (%d/t) ",
640 abs
->wifi
.link_qual_max
,
641 rel
->wifi
.link_qual
);
643 mvwprintw(screen
, (*voff
)++, 2,
644 "Signal: %8d dBm (%d dBm/t) ",
645 abs
->wifi
.signal_level
,
646 rel
->wifi
.signal_level
);
648 mvwprintw(screen
, (*voff
)++, 2,
649 "Noise: %8d dBm (%d dBm/t) ",
650 abs
->wifi
.noise_level
,
651 rel
->wifi
.noise_level
);
653 mvwprintw(screen
, (*voff
)++, 2,
654 "SNR: %8d dBm (%s) ",
655 abs
->wifi
.signal_level
- abs
->wifi
.noise_level
,
656 snr_to_str(abs
->wifi
.signal_level
- abs
->wifi
.noise_level
));
660 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
661 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
663 int cpus
, voff
= 1, cvoff
= 2;
667 cpus
= get_number_cpus();
668 bug_on(cpus
> MAX_CPUS
);
670 screen_header(screen
, ifname
, &voff
, ms_interval
);
673 screen_net_dev_rel(screen
, rel
, &voff
);
676 screen_net_dev_abs(screen
, abs
, &voff
);
679 screen_sys_mem(screen
, rel
, abs
, &voff
);
682 screen_percpu_states(screen
, rel
, cpus
, &voff
);
685 screen_percpu_irqs_rel(screen
, rel
, cpus
, &voff
);
688 screen_percpu_irqs_abs(screen
, abs
, cpus
, &voff
);
691 screen_wireless(screen
, rel
, abs
, &voff
);
694 mvwprintw(screen
, cvoff
, 2, "Collecting data ...");
697 mvwprintw(screen
, cvoff
, 2, " ");
704 static void screen_end(void)
709 static int screen_main(const char *ifname
, uint64_t ms_interval
)
713 screen_init(&stats_screen
);
717 if (key
== 'q' || key
== 0x1b /* esq */)
720 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
721 &first
, ms_interval
);
723 stats_sample_generic(ifname
, ms_interval
);
731 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
732 const struct ifstat
*abs
, uint64_t ms_interval
)
736 printf("%ld ", time(0));
738 printf("%lu ", rel
->rx_bytes
);
739 printf("%lu ", rel
->rx_packets
);
740 printf("%lu ", rel
->rx_drops
);
741 printf("%lu ", rel
->rx_errors
);
743 printf("%lu ", abs
->rx_bytes
);
744 printf("%lu ", abs
->rx_packets
);
745 printf("%lu ", abs
->rx_drops
);
746 printf("%lu ", abs
->rx_errors
);
748 printf("%lu ", rel
->tx_bytes
);
749 printf("%lu ", rel
->tx_packets
);
750 printf("%lu ", rel
->tx_drops
);
751 printf("%lu ", rel
->tx_errors
);
753 printf("%lu ", abs
->tx_bytes
);
754 printf("%lu ", abs
->tx_packets
);
755 printf("%lu ", abs
->tx_drops
);
756 printf("%lu ", abs
->tx_errors
);
758 printf("%u ", rel
->cswitch
);
759 printf("%lu ", abs
->mem_free
);
760 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
761 printf("%lu ", abs
->mem_total
);
762 printf("%u ", abs
->procs_run
);
763 printf("%u ", abs
->procs_iow
);
765 cpus
= get_number_cpus();
766 bug_on(cpus
> MAX_CPUS
);
768 for (i
= 0; i
< cpus
; ++i
) {
769 printf("%lu ", rel
->cpu_user
[i
]);
770 printf("%lu ", rel
->cpu_nice
[i
]);
771 printf("%lu ", rel
->cpu_sys
[i
]);
772 printf("%lu ", rel
->cpu_idle
[i
]);
773 printf("%lu ", rel
->cpu_iow
[i
]);
775 printf("%lu ", rel
->irqs
[i
]);
776 printf("%lu ", abs
->irqs
[i
]);
778 printf("%lu ", rel
->irqs_srx
[i
]);
779 printf("%lu ", abs
->irqs_srx
[i
]);
781 printf("%lu ", rel
->irqs_stx
[i
]);
782 printf("%lu ", abs
->irqs_stx
[i
]);
785 if (iswireless(abs
)) {
786 printf("%u ", rel
->wifi
.link_qual
);
787 printf("%u ", abs
->wifi
.link_qual
);
788 printf("%u ", abs
->wifi
.link_qual_max
);
790 printf("%d ", rel
->wifi
.signal_level
);
791 printf("%d ", abs
->wifi
.signal_level
);
793 printf("%d ", rel
->wifi
.noise_level
);
794 printf("%d ", abs
->wifi
.noise_level
);
801 static void term_csv_header(const char *ifname
, const struct ifstat
*abs
,
802 uint64_t ms_interval
)
806 printf("# gnuplot dump (#col:description)\n");
807 printf("# networking interface: %s\n", ifname
);
808 printf("# sampling interval (t): %lu ms\n", ms_interval
);
809 printf("# %d:unixtime ", j
++);
811 printf("%d:rx-bytes-per-t ", j
++);
812 printf("%d:rx-pkts-per-t ", j
++);
813 printf("%d:rx-drops-per-t ", j
++);
814 printf("%d:rx-errors-per-t ", j
++);
816 printf("%d:rx-bytes ", j
++);
817 printf("%d:rx-pkts ", j
++);
818 printf("%d:rx-drops ", j
++);
819 printf("%d:rx-errors ", j
++);
821 printf("%d:tx-bytes-per-t ", j
++);
822 printf("%d:tx-pkts-per-t ", j
++);
823 printf("%d:tx-drops-per-t ", j
++);
824 printf("%d:tx-errors-per-t ", j
++);
826 printf("%d:tx-bytes ", j
++);
827 printf("%d:tx-pkts ", j
++);
828 printf("%d:tx-drops ", j
++);
829 printf("%d:tx-errors ", j
++);
831 printf("%d:context-switches-per-t ", j
++);
832 printf("%d:mem-free ", j
++);
833 printf("%d:mem-used ", j
++);
834 printf("%d:mem-total ", j
++);
835 printf("%d:procs-in-run ", j
++);
836 printf("%d:procs-in-iow ", j
++);
838 cpus
= get_number_cpus();
839 bug_on(cpus
> MAX_CPUS
);
841 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
842 printf("%d:cpu%i-usr-per-t ", j
++, i
);
843 printf("%d:cpu%i-nice-per-t ", j
++, i
);
844 printf("%d:cpu%i-sys-per-t ", j
++, i
);
845 printf("%d:cpu%i-idle-per-t ", j
++, i
);
846 printf("%d:cpu%i-iow-per-t ", j
++, i
);
848 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
849 printf("%d:cpu%i-net-irqs ", j
++, i
);
851 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
852 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
853 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
854 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
857 if (iswireless(abs
)) {
858 printf("%d:wifi-link-qual-per-t ", j
++);
859 printf("%d:wifi-link-qual ", j
++);
860 printf("%d:wifi-link-qual-max ", j
++);
862 printf("%d:wifi-signal-dbm-per-t ", j
++);
863 printf("%d:wifi-signal-dbm ", j
++);
865 printf("%d:wifi-noise-dbm-per-t ", j
++);
866 printf("%d:wifi-noise-dbm ", j
++);
874 static int term_main(const char *ifname
, uint64_t ms_interval
)
879 stats_sample_generic(ifname
, ms_interval
);
883 term_csv_header(ifname
, &stats_new
, ms_interval
);
886 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
887 } while (stats_loop
&& !sigint
);
892 int main(int argc
, char **argv
)
895 int c
, opt_index
, ret
, promisc
= 0;
896 uint64_t interval
= 1000;
898 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
900 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
901 &opt_index
)) != EOF
) {
910 ifname
= xstrndup(optarg
, IFNAMSIZ
);
913 interval
= strtol(optarg
, NULL
, 10);
922 func_main
= term_main
;
928 panic("Option -%c requires an argument!\n",
932 whine("Unknown option character "
933 "`0x%X\'!\n", optopt
);
945 ifname
= xstrndup(argv
[1], IFNAMSIZ
);
947 panic("No networking device given!\n");
949 if (!strncmp("lo", ifname
, IFNAMSIZ
))
950 panic("lo is not supported!\n");
951 if (device_mtu(ifname
) == 0)
952 panic("This is no networking device!\n");
954 register_signal(SIGINT
, signal_handler
);
955 register_signal(SIGHUP
, signal_handler
);
958 ifflags
= enter_promiscuous_mode(ifname
);
959 ret
= func_main(ifname
, interval
);
961 leave_promiscuous_mode(ifname
, ifflags
);