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 long long unsigned int rx_bytes
, rx_packets
, rx_drops
, rx_errors
;
47 long long unsigned int rx_fifo
, rx_frame
, rx_multi
;
48 long long unsigned int tx_bytes
, tx_packets
, tx_drops
, tx_errors
;
49 long long unsigned int tx_fifo
, tx_colls
, tx_carrier
;
50 long long unsigned int 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 uint32_t irq_nr
, procs_run
, procs_iow
, cswitch
, forks
;
54 struct wifi_stat wifi
;
57 volatile sig_atomic_t sigint
= 0;
59 static struct ifstat stats_old
, stats_new
, stats_delta
;
61 static int stats_loop
= 0;
63 static WINDOW
*stats_screen
= NULL
;
65 static const char *short_options
= "d:t:vhclp";
66 static const struct option long_options
[] = {
67 {"dev", required_argument
, NULL
, 'd'},
68 {"interval", required_argument
, NULL
, 't'},
69 {"promisc", no_argument
, NULL
, 'p'},
70 {"csv", no_argument
, NULL
, 'c'},
71 {"loop", no_argument
, NULL
, 'l'},
72 {"version", no_argument
, NULL
, 'v'},
73 {"help", no_argument
, NULL
, 'h'},
77 static void signal_handler(int number
)
89 static inline char *snr_to_str(int level
)
92 return "very good signal";
93 if (level
> 25 && level
<= 40)
95 if (level
> 15 && level
<= 25)
97 if (level
> 10 && level
<= 15)
98 return "very poor signal";
105 static inline int iswireless(const struct ifstat
*stats
)
107 return stats
->wifi
.bitrate
> 0;
110 static void help(void)
112 printf("\nifpps %s, top-like kernel networking and system statistics\n",
114 puts("http://www.netsniff-ng.org\n\n"
115 "Usage: ifpps [options] || ifpps <netdev>\n"
117 " -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
118 " -t|--interval <time> Refresh time in ms (default 1000 ms)\n"
119 " -p|--promisc Promiscuous mode\n"
120 " -c|--csv Output to terminal as CSV\n"
121 " E.g. post-processing with Gnuplot et al.\n"
122 " -l|--loop Continuous CSV output\n"
123 " -v|--version Print version\n"
124 " -h|--help Print this help\n\n"
128 " ifpps -lpcd wlan0 > plot.dat\n\n"
129 "Please report bugs to <bugs@netsniff-ng.org>\n"
130 "Copyright (C) 2009-2012 Daniel Borkmann <daniel@netsniff-ng.org>\n"
131 "License: GNU GPL version 2.0\n"
132 "This is free software: you are free to change and redistribute it.\n"
133 "There is NO WARRANTY, to the extent permitted by law.\n");
137 static void version(void)
139 printf("\nifpps %s, top-like kernel networking and system statistics\n",
141 puts("http://www.netsniff-ng.org\n\n"
142 "Please report bugs to <bugs@netsniff-ng.org>\n"
143 "Copyright (C) 2009-2012 Daniel Borkmann <daniel@netsniff-ng.org>\n"
144 "License: GNU GPL version 2.0\n"
145 "This is free software: you are free to change and redistribute it.\n"
146 "There is NO WARRANTY, to the extent permitted by law.\n");
150 static int stats_proc_net_dev(const char *ifname
, struct ifstat
*stats
)
156 fp
= fopen("/proc/net/dev", "r");
158 panic("Cannot open /proc/net/dev!\n");
160 /* Omit table header from procfs file */
161 if (fgets(buff
, sizeof(buff
), fp
));
162 if (fgets(buff
, sizeof(buff
), fp
));
164 memset(buff
, 0, sizeof(buff
));
166 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
167 buff
[sizeof(buff
) -1] = 0;
169 if (strstr(buff
, ifname
) == NULL
)
172 if (sscanf(buff
, "%*[a-z0-9 .-]:%llu%llu%llu%llu%llu%llu"
173 "%llu%*u%llu%llu%llu%llu%llu%llu%llu",
174 &stats
->rx_bytes
, &stats
->rx_packets
,
175 &stats
->rx_errors
, &stats
->rx_drops
,
176 &stats
->rx_fifo
, &stats
->rx_frame
,
177 &stats
->rx_multi
, &stats
->tx_bytes
,
178 &stats
->tx_packets
, &stats
->tx_errors
,
179 &stats
->tx_drops
, &stats
->tx_fifo
,
180 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
185 memset(buff
, 0, sizeof(buff
));
192 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
194 int ret
= -EINVAL
, i
, cpus
, try = 0;
195 char *ptr
, buff
[256];
196 struct ethtool_drvinfo drvinf
;
199 fp
= fopen("/proc/interrupts", "r");
201 panic("Cannot open /proc/interrupts!\n");
203 cpus
= get_number_cpus();
204 bug_on(cpus
> MAX_CPUS
);
206 fseek(fp
, 0, SEEK_SET
);
207 memset(buff
, 0, sizeof(buff
));
209 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
210 buff
[sizeof(buff
) - 1] = 0;
213 if (strstr(buff
, ifname
) == NULL
)
216 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
217 bug_on(stats
->irq_nr
== 0);
220 ptr
++; /* Skip ':' char */
221 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
222 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
229 memset(buff
, 0, sizeof(buff
));
232 /* We could get caught here in case of wireless devices which
233 * are not necessarily listed under 'wlan0' et al. in
234 * proc/interrupts. Therefore, we try once again with the
235 * ethtool driver name.
237 if (ret
== -EINVAL
&& try == 0) {
238 memset(&drvinf
, 0, sizeof(drvinf
));
239 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
242 ifname
= drvinf
.driver
;
252 static int stats_proc_softirqs(struct ifstat
*stats
)
255 char *ptr
, buff
[256];
261 } net_type
= softirqs_net_none
;
263 fp
= fopen("/proc/softirqs", "r");
265 panic("Cannot open /proc/softirqs!\n");
267 cpus
= get_number_cpus();
268 bug_on(cpus
> MAX_CPUS
);
270 memset(buff
, 0, sizeof(buff
));
272 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
273 buff
[sizeof(buff
) - 1] = 0;
275 if ((ptr
= strstr(buff
, "NET_TX:")))
276 net_type
= softirqs_net_tx
;
277 else if ((ptr
= strstr(buff
, "NET_RX:")))
278 net_type
= softirqs_net_rx
;
282 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
284 case softirqs_net_tx
:
285 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
287 case softirqs_net_rx
:
288 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
295 memset(buff
, 0, sizeof(buff
));
302 static int stats_proc_memory(struct ifstat
*stats
)
304 char *ptr
, buff
[256];
307 fp
= fopen("/proc/meminfo", "r");
309 panic("Cannot open /proc/meminfo!\n");
311 memset(buff
, 0, sizeof(buff
));
313 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
314 buff
[sizeof(buff
) - 1] = 0;
316 if ((ptr
= strstr(buff
, "MemTotal:"))) {
317 ptr
+= strlen("MemTotal:");
318 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
319 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
320 ptr
+= strlen("MemFree:");
321 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
324 memset(buff
, 0, sizeof(buff
));
331 static int stats_proc_system(struct ifstat
*stats
)
334 char *ptr
, buff
[256];
337 fp
= fopen("/proc/stat", "r");
339 panic("Cannot open /proc/stat!\n");
341 cpus
= get_number_cpus();
342 bug_on(cpus
> MAX_CPUS
);
344 memset(buff
, 0, sizeof(buff
));
346 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
347 buff
[sizeof(buff
) - 1] = 0;
349 if ((ptr
= strstr(buff
, "cpu"))) {
350 ptr
+= strlen("cpu");
354 cpu
= strtol(ptr
, &ptr
, 10);
357 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
358 &stats
->cpu_user
[cpu
],
359 &stats
->cpu_nice
[cpu
],
360 &stats
->cpu_sys
[cpu
],
361 &stats
->cpu_idle
[cpu
],
362 &stats
->cpu_iow
[cpu
]) != 5)
364 } else if ((ptr
= strstr(buff
, "ctxt"))) {
365 ptr
+= strlen("ctxt");
366 stats
->cswitch
= strtoul(ptr
, &ptr
, 10);
367 } else if ((ptr
= strstr(buff
, "processes"))) {
368 ptr
+= strlen("processes");
369 stats
->forks
= strtoul(ptr
, &ptr
, 10);
370 } else if ((ptr
= strstr(buff
, "procs_running"))) {
371 ptr
+= strlen("procs_running");
372 stats
->procs_run
= strtoul(ptr
, &ptr
, 10);
373 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
374 ptr
+= strlen("procs_blocked");
375 stats
->procs_iow
= strtoul(ptr
, &ptr
, 10);
378 memset(buff
, 0, sizeof(buff
));
385 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
388 struct iw_statistics ws
;
390 ret
= wireless_sigqual(ifname
, &ws
);
392 stats
->wifi
.bitrate
= 0;
396 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
398 stats
->wifi
.signal_level
=
399 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
401 stats
->wifi
.link_qual
= ws
.qual
.qual
;
402 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
407 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
408 #define DIFF(member) do { \
409 if (sizeof(diff->member) != sizeof(new->member) || \
410 sizeof(diff->member) != sizeof(old->member)) \
412 bug_on((new->member - old->member) > (new->member)); \
416 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
441 DIFF1(wifi
.signal_level
);
442 DIFF1(wifi
.link_qual
);
447 cpus
= get_number_cpus();
448 bug_on(cpus
> MAX_CPUS
);
450 for (i
= 0; i
< cpus
; ++i
) {
463 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
465 if (stats_proc_net_dev(ifname
, stats
) < 0)
466 panic("Cannot fetch device stats!\n");
467 if (stats_proc_softirqs(stats
) < 0)
468 panic("Cannot fetch software interrupts!\n");
469 if (stats_proc_memory(stats
) < 0)
470 panic("Cannot fetch memory stats!\n");
471 if (stats_proc_system(stats
) < 0)
472 panic("Cannot fetch system stats!\n");
474 stats_proc_interrupts((char *) ifname
, stats
);
476 stats_wireless(ifname
, stats
);
479 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
481 memset(&stats_old
, 0, sizeof(stats_old
));
482 memset(&stats_new
, 0, sizeof(stats_new
));
483 memset(&stats_delta
, 0, sizeof(stats_delta
));
485 stats_fetch(ifname
, &stats_old
);
486 usleep(ms_interval
* 1000);
487 stats_fetch(ifname
, &stats_new
);
489 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
492 static void screen_init(WINDOW
**screen
)
494 (*screen
) = initscr();
499 nodelay((*screen
), TRUE
);
501 keypad(stdscr
, TRUE
);
507 static void screen_header(WINDOW
*screen
, const char *ifname
, int *voff
,
508 uint64_t ms_interval
)
512 struct ethtool_drvinfo drvinf
;
513 u32 rate
= device_bitrate(ifname
);
514 int link
= ethtool_link(ifname
);
516 memset(&drvinf
, 0, sizeof(drvinf
));
517 ethtool_drvinf(ifname
, &drvinf
);
519 memset(buff
, 0, sizeof(buff
));
521 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " %uMbit/s", rate
);
523 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " link:%s",
524 link
== 0 ? "no" : "yes");
526 mvwprintw(screen
, (*voff
)++, 2,
527 "Kernel net/sys statistics for %s (%s%s), t=%lums"
529 ifname
, drvinf
.driver
, buff
, ms_interval
);
532 static void screen_net_dev_rel(WINDOW
*screen
, const struct ifstat
*rel
,
537 mvwprintw(screen
, (*voff
)++, 0,
538 " RX: %16.3llf MiB/t "
542 ((long double) rel
->rx_bytes
) / (1LLU << 20),
543 rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
545 mvwprintw(screen
, (*voff
)++, 0,
546 " TX: %16.3llf MiB/t "
550 ((long double) rel
->tx_bytes
) / (1LLU << 20),
551 rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
556 static void screen_net_dev_abs(WINDOW
*screen
, const struct ifstat
*abs
,
559 mvwprintw(screen
, (*voff
)++, 2,
564 ((long double) abs
->rx_bytes
) / (1LLU << 20),
565 abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
567 mvwprintw(screen
, (*voff
)++, 2,
572 ((long double) abs
->tx_bytes
) / (1LLU << 20),
573 abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
576 static void screen_sys_mem(WINDOW
*screen
, const struct ifstat
*rel
,
577 const struct ifstat
*abs
, int *voff
)
579 mvwprintw(screen
, (*voff
)++, 2,
585 (100.0 * (abs
->mem_total
- abs
->mem_free
)) / abs
->mem_total
,
586 abs
->procs_run
, abs
->procs_iow
);
589 static void screen_percpu_states(WINDOW
*screen
, const struct ifstat
*rel
,
595 for (i
= 0; i
< cpus
; ++i
) {
596 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] +
597 rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
599 mvwprintw(screen
, (*voff
)++, 2,
600 "CPU%d: %13.1lf%% usr/t "
603 "%11.1lf%% iow/t ", i
,
604 100.0 * (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
,
605 100.0 * rel
->cpu_sys
[i
] / all
,
606 100.0 * rel
->cpu_idle
[i
] / all
,
607 100.0 * rel
->cpu_iow
[i
] / all
);
611 static void screen_percpu_irqs_rel(WINDOW
*screen
, const struct ifstat
*rel
,
616 for (i
= 0; i
< cpus
; ++i
) {
617 mvwprintw(screen
, (*voff
)++, 2,
618 "CPU%d: %14llu irqs/t "
620 "%15llu soirq TX/t ", i
,
627 static void screen_percpu_irqs_abs(WINDOW
*screen
, const struct ifstat
*abs
,
632 for (i
= 0; i
< cpus
; ++i
) {
633 mvwprintw(screen
, (*voff
)++, 2,
634 "CPU%d: %14llu irqs", i
,
639 static void screen_wireless(WINDOW
*screen
, const struct ifstat
*rel
,
640 const struct ifstat
*abs
, int *voff
)
642 if (iswireless(abs
)) {
643 mvwprintw(screen
, (*voff
)++, 2,
644 "LinkQual: %7d/%d (%d/t) ",
646 abs
->wifi
.link_qual_max
,
647 rel
->wifi
.link_qual
);
649 mvwprintw(screen
, (*voff
)++, 2,
650 "Signal: %8d dBm (%d dBm/t) ",
651 abs
->wifi
.signal_level
,
652 rel
->wifi
.signal_level
);
654 mvwprintw(screen
, (*voff
)++, 2,
655 "Noise: %8d dBm (%d dBm/t) ",
656 abs
->wifi
.noise_level
,
657 rel
->wifi
.noise_level
);
658 mvwprintw(screen
, (*voff
)++, 2,
659 "SNR: %8d dBm (%s) ",
660 abs
->wifi
.signal_level
- abs
->wifi
.noise_level
,
661 snr_to_str(abs
->wifi
.signal_level
- abs
->wifi
.noise_level
));
666 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
667 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
669 int cpus
, voff
= 1, cvoff
= 2;
673 cpus
= get_number_cpus();
674 bug_on(cpus
> MAX_CPUS
);
676 screen_header(screen
, ifname
, &voff
, ms_interval
);
679 screen_net_dev_rel(screen
, rel
, &voff
);
682 screen_net_dev_abs(screen
, abs
, &voff
);
685 screen_sys_mem(screen
, rel
, abs
, &voff
);
688 screen_percpu_states(screen
, rel
, cpus
, &voff
);
691 screen_percpu_irqs_rel(screen
, rel
, cpus
, &voff
);
694 screen_percpu_irqs_abs(screen
, abs
, cpus
, &voff
);
697 screen_wireless(screen
, rel
, abs
, &voff
);
700 mvwprintw(screen
, cvoff
, 2, "Collecting data ...");
703 mvwprintw(screen
, cvoff
, 2, " ");
710 static void screen_end(void)
715 static int screen_main(const char *ifname
, uint64_t ms_interval
)
719 screen_init(&stats_screen
);
723 if (key
== 'q' || key
== 0x1b /* esq */ || key
== KEY_F(10))
726 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
727 &first
, ms_interval
);
729 stats_sample_generic(ifname
, ms_interval
);
737 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
738 const struct ifstat
*abs
, uint64_t ms_interval
)
742 printf("%ld ", time(0));
744 printf("%llu ", rel
->rx_bytes
);
745 printf("%llu ", rel
->rx_packets
);
746 printf("%llu ", rel
->rx_drops
);
747 printf("%llu ", rel
->rx_errors
);
749 printf("%llu ", abs
->rx_bytes
);
750 printf("%llu ", abs
->rx_packets
);
751 printf("%llu ", abs
->rx_drops
);
752 printf("%llu ", abs
->rx_errors
);
754 printf("%llu ", rel
->tx_bytes
);
755 printf("%llu ", rel
->tx_packets
);
756 printf("%llu ", rel
->tx_drops
);
757 printf("%llu ", rel
->tx_errors
);
759 printf("%llu ", abs
->tx_bytes
);
760 printf("%llu ", abs
->tx_packets
);
761 printf("%llu ", abs
->tx_drops
);
762 printf("%llu ", abs
->tx_errors
);
764 printf("%u ", rel
->cswitch
);
765 printf("%lu ", abs
->mem_free
);
766 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
767 printf("%lu ", abs
->mem_total
);
768 printf("%u ", abs
->procs_run
);
769 printf("%u ", abs
->procs_iow
);
771 cpus
= get_number_cpus();
772 bug_on(cpus
> MAX_CPUS
);
774 for (i
= 0; i
< cpus
; ++i
) {
775 printf("%lu ", rel
->cpu_user
[i
]);
776 printf("%lu ", rel
->cpu_nice
[i
]);
777 printf("%lu ", rel
->cpu_sys
[i
]);
778 printf("%lu ", rel
->cpu_idle
[i
]);
779 printf("%lu ", rel
->cpu_iow
[i
]);
781 printf("%llu ", rel
->irqs
[i
]);
782 printf("%llu ", abs
->irqs
[i
]);
784 printf("%llu ", rel
->irqs_srx
[i
]);
785 printf("%llu ", abs
->irqs_srx
[i
]);
787 printf("%llu ", rel
->irqs_stx
[i
]);
788 printf("%llu ", abs
->irqs_stx
[i
]);
791 if (iswireless(abs
)) {
792 printf("%u ", rel
->wifi
.link_qual
);
793 printf("%u ", abs
->wifi
.link_qual
);
794 printf("%u ", abs
->wifi
.link_qual_max
);
796 printf("%d ", rel
->wifi
.signal_level
);
797 printf("%d ", abs
->wifi
.signal_level
);
799 printf("%d ", rel
->wifi
.noise_level
);
800 printf("%d ", abs
->wifi
.noise_level
);
808 static void term_csv_header(const char *ifname
, const struct ifstat
*abs
,
809 uint64_t ms_interval
)
813 printf("# gnuplot dump (#col:description)\n");
814 printf("# networking interface: %s\n", ifname
);
815 printf("# sampling interval (t): %lu ms\n", ms_interval
);
816 printf("# %d:unixtime ", j
++);
818 printf("%d:rx-bytes-per-t ", j
++);
819 printf("%d:rx-pkts-per-t ", j
++);
820 printf("%d:rx-drops-per-t ", j
++);
821 printf("%d:rx-errors-per-t ", j
++);
823 printf("%d:rx-bytes ", j
++);
824 printf("%d:rx-pkts ", j
++);
825 printf("%d:rx-drops ", j
++);
826 printf("%d:rx-errors ", j
++);
828 printf("%d:tx-bytes-per-t ", j
++);
829 printf("%d:tx-pkts-per-t ", j
++);
830 printf("%d:tx-drops-per-t ", j
++);
831 printf("%d:tx-errors-per-t ", j
++);
833 printf("%d:tx-bytes ", j
++);
834 printf("%d:tx-pkts ", j
++);
835 printf("%d:tx-drops ", j
++);
836 printf("%d:tx-errors ", j
++);
838 printf("%d:context-switches-per-t ", j
++);
839 printf("%d:mem-free ", j
++);
840 printf("%d:mem-used ", j
++);
841 printf("%d:mem-total ", j
++);
842 printf("%d:procs-in-run ", j
++);
843 printf("%d:procs-in-iow ", j
++);
845 cpus
= get_number_cpus();
846 bug_on(cpus
> MAX_CPUS
);
848 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
849 printf("%d:cpu%i-usr-per-t ", j
++, i
);
850 printf("%d:cpu%i-nice-per-t ", j
++, i
);
851 printf("%d:cpu%i-sys-per-t ", j
++, i
);
852 printf("%d:cpu%i-idle-per-t ", j
++, i
);
853 printf("%d:cpu%i-iow-per-t ", j
++, i
);
855 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
856 printf("%d:cpu%i-net-irqs ", j
++, i
);
858 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
859 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
860 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
861 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
864 if (iswireless(abs
)) {
865 printf("%d:wifi-link-qual-per-t ", j
++);
866 printf("%d:wifi-link-qual ", j
++);
867 printf("%d:wifi-link-qual-max ", j
++);
869 printf("%d:wifi-signal-dbm-per-t ", j
++);
870 printf("%d:wifi-signal-dbm ", j
++);
872 printf("%d:wifi-noise-dbm-per-t ", j
++);
873 printf("%d:wifi-noise-dbm ", j
++);
882 static int term_main(const char *ifname
, uint64_t ms_interval
)
887 stats_sample_generic(ifname
, ms_interval
);
891 term_csv_header(ifname
, &stats_new
, ms_interval
);
894 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
895 } while (stats_loop
&& !sigint
);
900 int main(int argc
, char **argv
)
903 int c
, opt_index
, ret
, promisc
= 0;
904 uint64_t interval
= 1000;
906 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
908 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
909 &opt_index
)) != EOF
) {
918 ifname
= xstrndup(optarg
, IFNAMSIZ
);
921 interval
= strtol(optarg
, NULL
, 10);
930 func_main
= term_main
;
936 panic("Option -%c requires an argument!\n",
940 whine("Unknown option character "
941 "`0x%X\'!\n", optopt
);
953 ifname
= xstrndup(argv
[1], IFNAMSIZ
);
955 panic("No networking device given!\n");
957 if (!strncmp("lo", ifname
, IFNAMSIZ
))
958 panic("lo is not supported!\n");
959 if (device_mtu(ifname
) == 0)
960 panic("This is no networking device!\n");
962 register_signal(SIGINT
, signal_handler
);
963 register_signal(SIGHUP
, signal_handler
);
966 ifflags
= enter_promiscuous_mode(ifname
);
967 ret
= func_main(ifname
, interval
);
969 leave_promiscuous_mode(ifname
, ifflags
);