pax_global_header00006660000000000000000000000064134126703050014513gustar00rootroot0000000000000052 comment=bd6c8ad50dbfe22026051a71e5bab49c9d0e5876 bwm-ng-0.6.2/000077500000000000000000000000001341267030500127075ustar00rootroot00000000000000bwm-ng-0.6.2/.gitignore000066400000000000000000000005621341267030500147020ustar00rootroot00000000000000Makefile.in aclocal.m4 autom4te.cache/ compile config.h.in configure depcomp install-sh missing src/Makefile.in Makefile config.h config.log config.status src/.deps/ src/Makefile src/bwm-ng src/bwm-ng.o src/curses_tools.o src/help.o src/netstat.o src/options.o src/output.o src/proc_diskstats.o src/proc_net_dev.o src/process.o src/retrieve.o stamp-h1 src/libstatgrab.o bwm-ng-0.6.2/.travis.yml000066400000000000000000000000701341267030500150150ustar00rootroot00000000000000language: c script: ./autogen.sh && ./configure && make bwm-ng-0.6.2/AUTHORS000066400000000000000000000010341341267030500137550ustar00rootroot00000000000000-- AUTHORS of bwm-ng Author/Project leader: Volker Gropp Main developers: Volker Gropp Contributors: all authors from github merge requests and: Tim Bishop Alexey Zakharov Ricardo James Westby Bastian Riehl - curses2 output Michael Eckhoff - bit/s display Daniel Elstner Daniel Holbach - autogen.sh bwm-ng-0.6.2/COPYING000066400000000000000000000431101341267030500137410ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. bwm-ng-0.6.2/ChangeLog000066400000000000000000000417541341267030500144740ustar00rootroot000000000000002019-01-01 14:50 (0.6.2) Volker Gropp * Merge pull request #22 from vgropp/issue-#13 to fix windows build * Merge pull request #20 from dreibh/master CSV file output: fix for timestamp inaccuracy and Y-2038 problem * Merge pull request #21 from vgropp/travisci add travisci * Merge pull request #17 from Himura2la/master Add the started time in "sum" mode * Merge pull request #18 from Himura2la/fix-dynamic Fix DYNAMIC and ANSIOUT in config * Merge pull request #10 from SoapGentoo/fixes Use `static inline` instead of `inline` * Merge pull request #9 from adventureloop/master Always fflush the pipe * Merge pull request #7 from samueloph/fsf_address_clean Update FSF address * Merge pull request #6 from samueloph/master Fix typos * fix nan and inf values on fast refresh (fixes debian bug #532331) 2015-07-25 13:40 (0.6.1) Volker Gropp * cleanups for 0.6.1 release * fix g++5 warnings and errors * fallback to auto libstatgrab check if no other input found * libstatgrab no longer default configure option, remove dependency on most distributions * add more buildfiles to ignore * Fix to work with libstatgrab-0.90 From http://svnweb.freebsd.org/ports/head/net-mgmt/bwm-ng/files/patch-src__input__libstatgrab.c?view=markup Original patch by Tim Bishop * Makefile.am, README, autogen.sh, bwm-ng.1, configure.in, src/input/libkstat.c, src/input/netstat.c: cleanups for 0.6 release 2007-02-28 13:37 Volker Gropp * Makefile.am, src/input/sysctl.c, src/process.c: fix strange netbsd behavior 2007-02-28 12:33 Volker Gropp * Makefile.am, README, acinclude.m4, autogen.sh, configure.in, src/Makefile.am: fix automake issues 2007-02-28 03:03 Volker Gropp * autogen.sh, configure.in, src/Makefile.am, src/bwm-ng.h, src/input, src/input/devstat.c, src/input/devstat.h, src/input/getifaddrs.c, src/input/getifaddrs.h, src/input/ioservice.c, src/input/ioservice.h, src/input/libkstat.c, src/input/libkstat.h, src/input/libstatgrab.c, src/input/libstatgrab.h, src/input/netstat.c, src/input/netstat.h, src/input/proc_diskstats.c, src/input/proc_diskstats.h, src/input/proc_net_dev.c, src/input/proc_net_dev.h, src/input/retrieve.c, src/input/retrieve.h, src/input/sysctl.c, src/input/sysctl.h, src/input/win32.c, src/input/win32.h, src/retrieve.c, src/retrieve.h: split src/retrieve.[ch] into src/input/*.[ch] 2007-02-28 01:02 Volker Gropp * autogen.sh: using autoreconf if applicable 2007-02-27 20:35 Volker Gropp * bwm-ng.1, bwm-ng.conf-example, src/bwm-ng.c, src/global_vars.h, src/options.c, src/retrieve.c, src/retrieve.h: default to bsd names on ioservice input, optional long disknames 2007-02-26 20:42 Volker Gropp * README, autogen.sh, bwm-ng.1, configure.in, src/defines.h, src/options.c, src/output.c, src/retrieve.c, src/retrieve.h: add IOKit disk input on Darwin 2007-02-23 18:30 Volker Gropp * bwm-ng.1, bwm-ng.conf-example, src/bwm-ng.c, src/defines.h, src/global_vars.h, src/help.c, src/options.c, src/output.c, src/process.c: add option to disable ANSI Codes on plain output 2007-02-23 12:52 Volker Gropp * README, autogen.sh, bwm-ng.1, configure.in, src/defines.h, src/options.c, src/output.c, src/retrieve.c, src/retrieve.h: add devstat (FreeBSD) disk input 2007-02-23 10:07 Volker Gropp * src/defines.h, src/options.c, src/output.c, src/retrieve.c, src/retrieve.h: remove SYSCTLDISK_IN depends on SYSCTL define 2007-02-23 09:07 Volker Gropp * autogen.sh, configure.in: fix removed file check when given --with-diskstats 2007-02-23 08:45 Volker Gropp * autogen.sh, configure.in: fix autogen on openbsd without AUTOCONF_VERSION set. check for sysctldisk input without sysctl(net) 2007-02-22 22:20 Volker Gropp * README, bwm-ng.1, configure.in, src/defines.h, src/options.c, src/output.c, src/retrieve.c, src/retrieve.h: added netbsd/openbsd sysctl disk io input 2007-02-22 12:59 Volker Gropp * autogen.sh: readd aclocal and automake scan to autogen.sh, runs better on openbsd this way 2007-02-22 11:32 Volker Gropp * README, src/output.c, src/retrieve.c: some cleanup in proc/partitions code 2007-02-20 11:47 Volker Gropp * src/retrieve.c: simplify parsing of /proc/stat disk_io: 2007-02-20 00:34 Volker Gropp * configure.in, src/retrieve.c: add early linux kernel 2.4 disk io support (/proc/stat) 2007-02-19 23:35 Volker Gropp * README, configure.in, src/bwm-ng.c, src/curses_tools.c, src/curses_tools.h, src/retrieve.c: clean dirty ifdefs a little 2007-02-19 13:34 Volker Gropp * configure.in, src/curses_tools.h: fix solaris compiling issues 2007-02-19 13:11 Volker Gropp * configure.in: add libs to correct var 2007-02-19 13:07 Volker Gropp * configure.in: fix missing defines and add of linker flags (buggy autotools?) 2007-02-19 12:48 Volker Gropp * autogen.sh: simplify autogen.sh, we dont check for autotools version anymore, if it fails, it fails. its more portable now 2007-02-19 12:26 Volker Gropp * configure.in, src/retrieve.c: fix kstat configure and disk input 2007-02-19 11:19 Volker Gropp * src/defines.h: fix libkstat typos 2007-02-18 12:29 Volker Gropp * src/curses_tools.c, src/defines.h, src/options.c, src/output.c, src/retrieve.c: add kstatdisk (solaris disk input) 2007-02-16 21:53 Volker Gropp * src/bwm-ng.c: fix handle failure of usleep 2007-02-16 17:19 Volker Gropp * configure.in, src/bwm-ng.c, src/defines.h, src/global_vars.h, src/help.c, src/options.c, src/output.c, src/process.c, src/retrieve.c: add proc/partitions disk input support (linux 2.4) and fix devfs device names 2007-02-16 06:56 Volker Gropp * src/bwm-ng.c, src/curses_tools.c, src/global_vars.h: dont use SCREEN anymore in curses, fix usleep error handling 2007-02-16 05:19 Volker Gropp * src/bwm-ng.c: some ncurses version will segfault, usw delscreen as last call 2007-02-16 00:30 Volker Gropp * README, src/Makefile.am, src/bwm-ng.h, src/help.c, src/help.h, src/options.c, src/retrieve.c, src/types.h: fix win compile and win32 missing input 2007-02-14 17:55 Volker Gropp * configure.in, src/bwm-ng.c, src/defines.h, src/options.c, src/output.c, src/process.c, src/retrieve.c, src/retrieve.h, src/types.h: make bwm-ng compile with gcc -ansi -pedantic in linux 2007-02-14 15:10 Volker Gropp * bwm-ng.1, src/bwm-ng.c, src/bwm-ng.h, src/curses_tools.c, src/curses_tools.h, src/defines.h, src/global_vars.h, src/help.c, src/help.h, src/options.c, src/options.h, src/output.c, src/output.h, src/process.c, src/process.h, src/retrieve.c, src/retrieve.h, src/types.h: reorganize header files and global vars 2007-02-14 10:54 Volker Gropp * README, src/output.c, src/process.c, src/retrieve.c: fix output of max,sum,avg in csv and curses2 output. fix libstatdisk input. more checks for failed malloc in inputs 2007-02-13 14:56 Volker Gropp * ChangeLog, README, configure.in, src/defines.h, src/process.c, src/retrieve.c: fix libstatgrab disk-bytes, hide loop devices on linux disk input 2007-02-13 12:49 Volker Gropp * README, bwm-ng.1, bwm-ng.conf-example, configure.in, src/bwm-ng.c, src/bwm-ng.h, src/curses_tools.c, src/defines.h, src/help.c, src/options.c, src/options.h, src/output.c, src/process.c, src/retrieve.c, src/retrieve.h: add diskio stats using linux 2.6 /proc/diskstats and libstatgrab 2007-02-11 12:51 Volker Gropp * acinclude.m4, configure.in: only check for libstat if no other net-input found 2007-02-10 19:03 Volker Gropp * src/output.c, src/retrieve.c, src/types.h: fix csv output didnt respect --type 2006-12-15 16:43 Volker Gropp * ChangeLog, src/options.c: fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=403099 2006-10-13 15:25 Volker Gropp * .: ignore eclipse project files 2006-10-13 15:16 Volker Gropp * src/bwm-ng.c: changed copyright years (svn test) 2006-10-10 23:25 Volker Gropp * src/output.c: fixed length of string, was broken in OpenBSD aswell 2006-10-10 23:07 Volker Gropp * src/defines.h, src/output.c, src/retrieve.c: added strlcpy makro for systems without it builtin 2006-10-10 22:41 Volker Gropp * configure.in, src/output.c, src/retrieve.c: merged OpenBSD patches for strlcpy by niallo 2006-10-08 11:05 Volker Gropp * README: small url and platforms update 2006-04-23 18:56 Volker Gropp * src/help.c, src/output.c: indent fixes 2006-04-23 15:44 Volker Gropp * src/bwm-ng.c, src/bwm-ng.h, src/retrieve.c, src/retrieve.h: readded win32 functions which were accidently removed 2006-04-23 15:17 Volker Gropp * src/bwm-ng.c: fix win32 Sleep 2006-04-23 15:11 Volker Gropp * configure.in, src/bwm-ng.c, src/bwm-ng.h, src/curses_tools.h, src/help.h, src/options.h, src/output.h, src/process.h, src/retrieve.c, src/retrieve.h, src/types.h: fix win32 compile (mingw gcc) 2006-04-22 20:24 Volker Gropp * src/curses_tools.c: fixed small curses2 issues 2006-04-22 19:18 Volker Gropp * src/bwm-ng.c, src/bwm-ng.h, src/defines.h, src/retrieve.c, src/retrieve.h: added win32 input 2006-04-21 14:36 Volker Gropp * src/bwm-ng.c, src/curses_tools.c, src/curses_tools.h, src/options.c, src/options.h, src/process.h, src/retrieve.c, src/retrieve.h: fixed set error code to 1 on exit with error 2006-04-19 14:22 Volker Gropp * bwm-ng.1: fixed more typos in manpage, thx to D. Viano 2006-04-19 14:17 Volker Gropp * bwm-ng.1, src/curses_tools.c: fixed typo in manpage 05-12-2005 (0.6-pre2-cvs) Bastian Riehl * src/bwm-ng.c,src/curses_tools.c,src/curses_tools.h,src/defines.h, src/help.c,src/help.h,src/options.c,src/options.h, src/output.c,src/output.h: added first curses2 support, some nice bar chart (submitted by Bastian Riehl) 04-12-2005 (0.6-pre1-cvs) Volker Gropp * acinclude.m4, configure.in, aclocal.m4, Makefile.in, Makefile.am: added full auto* support for a proper `make install` * defines.h: removed MAJOR, MINOR, EXTRA and changed to VERSION from config.h and configure * changelog: renamed to ChangeLog and changed to a proper format * THANKS: added * process.c: fixed avg was wrong on startup and when delay was changed while running * retrieve.c: small cleanup of check_if_up(). * bwm-ng.c: fixed memleak of if_name and myscr in deinit(). * src/output.c: fixed from single to double quotes in order to valide with w3c (reported by -f ) * bwm-ng.conf-example: fixed default procfile to /proc/net/dev (reported by -f ) * src/options.c: fixed error and exit if outfile cant be open (reported by -f ) * src/bwm-ng.c: fixed html footer output to stdout when deamon, header and outfile set (reported by -f ) * src/options.c: hopefully fixed segfault when empty lines in config in openbsd 3.8 (reply is welcome) (reported by -f ) * src/defines.h,src/help.c,src/options.c: fixed return codes 02-20-2005 (0.5) Volker Gropp * added: outfile and daemonize for html output * fixes: for IRIX * added: bit/second output (Michael Eckhoff ) * added: errors/s output * removed: -p and -b, added -u/--unit * added: max stats (--type,-T and 't') * added: sum stats * moved: alot functions from retrieve.c into process.c * added: average stats * output.c: moved help output into help.c * help.c,curses.c: added onlinehelp for curses output (key 'h') * curses.c,bwm-ng.c: resize term in curses output * fixed: libstatgrab input segfault * fixed: /etc/bwm-ng.conf and ~/.bwm-ng.conf were not skipped if configfile was specified in cmdline * added: optional argument for -D, -S and -d * bwm-ng.1: added manpage * configure.in: added configure --disable-extendedstats to compile w/o avg, sum and max * fixed: compile on MacOSX 10.1 * curses.c: fallback to plain output if curses init fails * configure.in: added --enable-debug for -g3 and future use #define DEBUG 01-18-2005 (0.5-pre1) Volker Gropp * fixed: invalid option msg showed up twice * added: --sumhidden, by default hidden ifaces dont count for total anymore * added: show iface cycle for gui (curses yet) modes up and not hidden, up and hidden, all * process.c: if ifacelist (-I) is prefaced with % it behaves like a blacklist * options.c: get_options (long_options) cleanup * fixed: wrong values on proc/net/dev wrap around. * fixed: several configure and compile issues * added: output correct error messages * added: Solaris support (kstat and netstat) * fixed: segfault with getifaddrs on MacOSX < 10.3 * fixed: NetBSD/OpenBSD compile * added: NetBSD/OpenBSD netstat support * fixed: netstat parsing if address field missing * fixed: showing same iface twice on netstat input 12-20-2004 (0.4) Volker Gropp * added: configure script and config.h * changed: input_method handling (cycling while running works now for all methods) * added: sysctl input (mostly for BSD), the old sysctl was getiffaddrs() actually * fixed: netstat input for BSD * changed: html cleanup and header is now opt: --htmlheader * added: using real time elapsed since last probe to calc byte/s old method is backup if no gettimeofday is available * changed: switched in and out in plain, curses and html output * added: support for configfiles 10-31-2004 (0.4-pre3) Volker Gropp * added: BSD support via sysctl (only fbsd tested yet) * fixed: gcc warnings on old/non x86 systems * added: errors output (inverse in curses) * added: libstatgrap support * another: get_iface_stats cleanup/split * Makefile: added options * fixed: removed interfaces can cause a blank line * added: -D__CURSES, if not defined, you can build without libcurses * changed: plain output with count>1 to almost the same as curses output except inputkeys and errors support * added: -D__HTML and -D__CSV to select output at compiletime 10-21-2004 (0.4-pre2) Volker Gropp * added: html output, bwm-ng.css prolly needs alot of tweaking 10-17-2004 (0.4-pre1) Volker Gropp * changed: get_iface_stats cleanup * added: plain and csv output * splited: the big bwm-ng.c * added: interface list (whitelist) * changed: -lncurses instead of -lcurses, hope this will work on more boxes 09-16-2004 (0.3) Volker Gropp * fixed: cosmetic changes, KB/s is now default (again) * added: netstat input * added: packet output * added: show only-up-interfaces or all 09-07-2004 (0.2) Volker Gropp * changed: rewrote parsing * changed: cosmetic changes * changed: to dynamic allocated and displayed interfaces * added: possible to auto switch Byte KB and MB per second 09-07-2004 (0.1) Volker Gropp * added: initial release, almost if not all features of old bwm bwm-ng-0.6.2/INSTALL000066400000000000000000000366101341267030500137460ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell command `./configure && make && make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. HP-UX `make' updates targets which have the same time stamps as their prerequisites, which makes it generally unusable when shipped generated files such as `configure' are involved. Use GNU `make' instead. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf limitation. Until the limitation is lifted, you can use this workaround: CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. bwm-ng-0.6.2/LICENSE000066400000000000000000001063751341267030500137300ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. {signature of Ty Coon}, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. {signature of Ty Coon}, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. bwm-ng-0.6.2/Makefile.am000066400000000000000000000003171341267030500147440ustar00rootroot00000000000000## Process this file with automake to produce Makefile.in SUBDIRS = src # man page man_MANS = bwm-ng.1 # we want these in the dist tarball EXTRA_DIST = bwm-ng.1 bwm-ng.conf-example bwm-ng.css autogen.sh bwm-ng-0.6.2/NEWS000066400000000000000000000014211341267030500134040ustar00rootroot00000000000000Changes in 0.6.2: - Merge pull request #22 from vgropp/issue-#13 to fix windows build - Merge pull request #20 from dreibh/master CSV file output: fix for timestamp inaccuracy and Y-2038 problem - Merge pull request #21 from vgropp/travisci add travisci - Merge pull request #17 from Himura2la/master Add the started time in "sum" mode - Merge pull request #18 from Himura2la/fix-dynamic Fix DYNAMIC and ANSIOUT in config - Merge pull request #10 from SoapGentoo/fixes Use `static inline` instead of `inline` - Merge pull request #9 from adventureloop/master Always fflush the pipe - Merge pull request #7 from samueloph/fsf_address_clean Update FSF address - Merge pull request #6 from samueloph/master Fix typos - fix nan and inf values on fast refresh (fixes debian bug #532331) bwm-ng-0.6.2/README000066400000000000000000000123601341267030500135710ustar00rootroot00000000000000bwm-ng v0.6.2 Copyright (C) 2004-2019 Volker Gropp (bwmng@gropp.org) http://www.gropp.org/?id=projects&sub=bwm-ng What is this? ============= Bandwidth Monitor NG is a small and simple console-based live network and disk io bandwidth monitor for Linux, BSD, Solaris, Mac OS X and others. Short list of features: - supports /proc/net/dev, netstat, getifaddr, sysctl, kstat, /proc/diskstats /proc/partitions, IOKit, devstat and libstatgrab - unlimited number of interfaces/devices supported - interfaces/devices are added or removed dynamically from list - white-/blacklist of interfaces/devices - output of KB/s, Kb/s, packets, errors, average, max and total sum - output in curses, plain console, CSV or HTML - configfile This was influenced by the old bwm util written by written by Barney (barney@freewill.tzo.com) which had some issues with faster interfaces and was very simple. Since i had almost all code done anyway for other projects, i decided to create my own version. I actually dont know if netstat input is usefull at all. I saw this elsewhere, so i added it. Its target is "netstat 1.42 (2001-04-15)" linux or Free/Open/NetBSD. If there are other formats i would be happy to add them. For info about libstatgrab please refer to http://www.i-scream.org/libstatgrab/ Supported Platforms =================== network routines sucessfully tested on: Linux 2.4 and above* FreeBSD 4.8, 5.3, 6.2* MacOS X 10.1 and above* Solaris 10 x86* SunOS 5.9 sparc Solaris 9 OpenBSD 3.4, 3.6, 4.0* NetBSD 1.6.1, 2.0, 3.0* IRIX64 6.5 Win2000, WinXP, Windows Vista *disk monitoring working aswell please email me of working or not working platforms. Disk IO might work only on a limited number of platforms. INSTALL ======= Autotools are used to build this. Run the autogen.sh to generate the configure script. For detailed decription please read INSTALL ./configure --help for a list of options ./configure make to install use as root: make install WIN32 ===== To compile the Windows version in Linux (debian): ./configure --with-win32 --without-procnetdev --without-diskstats --without-curses --without-netstatlinux --build i686-pc-linux-gnu --host i586-mingw32msvc make get ansi.sys for better output: http://en.wikipedia.org/wiki/ANSI.SYS Specs ===== csv output format: Type rate: unix timestamp;iface_name;bytes_out/s;bytes_in/s;bytes_total/s;bytes_in;bytes_out;packets_out/s;packets_in/s;packets_total/s;packets_in;packets_out;errors_out/s;errors_in/s;errors_in;errors_out\n Type svg, sum, max: unix timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in\n Use --count 0 to skip the all zero output after start. html output format: edit the bwm-ng.css to modify the output. Please note the htmlrefresh only modifies the META refresh, you maybe wanna sync --timeout and --htmlrefresh USAGE ===== USAGE: bwm-ng [OPTION] ... [CONFIGFILE] Please read the manpage or `bwm-ng -h` for a list and explanation of options. Keybindings (curses only): 'h' show help 'q' exit '+' increases timeout by 100ms '-' decreases timeout by 100ms 'k','d' switch KB and auto assign Byte/KB/MB/GB 'a' cycle: show all interfaces, only those which are up, only up and not hidden 's' sum hidden ifaces to total aswell or not 'n' cycle: input methods 'u' cycle: bytes,bits,packets,errors 't' cycle: current rate, max, sum since start, average for last 30 sec Configfile ========== either via cmdline or /etc/bwm-ng.conf or ~/.bwm-ng.conf it consists of: longoption=value with 1 or 0 as values for keys without a value in cmdline options. For more help take a look at bwm-ng.conf-example Misc ==== Bugs/Known Problems: - curses output coredumps on netbsd 1.6.1 (maybe others) with unknown TERM set and configfile support compiled in - no other yet, wow ;) (please report if you found one) Todo: - Docs - checking options to be valid - mysql output (ipac-ng compatible) - setting which stats to output for csv/sql - distributed gathering of stats (client/server) - whatever you can think of ****************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * ****************************************************************************** bwm-ng-0.6.2/THANKS000066400000000000000000000012541341267030500136240ustar00rootroot00000000000000thanks and praises go to: Packaging (Gentoo) Benedikt Boehm Adrian von Buttlar (Ubuntu) Daniel Holbach (rh/fc spec) Michael Lang General input / clues Daniel Holbach Adrian von Buttlar Charley Krooß Testing Jens Mayer Markus Nospers Thanks to all merge requests, mailing me and help me improving bwm-ng bwm-ng-0.6.2/acinclude.m4000066400000000000000000000110051341267030500150750ustar00rootroot00000000000000# aclocal.m4 generated automatically by aclocal 1.6.3 -*- Autoconf -*- # Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 # Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. AC_DEFUN([AC_CHECK_WORKING_GETIFADDRS], [ AC_MSG_CHECKING([whether getifaddrs returns correct values]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #if STDC_HEADERS # include # include #else # if HAVE_STDLIB_H # include # endif #endif #if HAVE_SYS_SOCKET_H # include #endif #include #include #include int main() { struct ifaddrs *net; if (getifaddrs(&net) != 0) return 1; if (net!=NULL) if (net->ifa_data==NULL) { freeifaddrs(net); return 1; } freeifaddrs(net); return 0; } ]])],[ AC_MSG_RESULT(yes) AC_DEFINE_UNQUOTED([HAVE_WORKING_GETIFADDRS],[1],[getifaddrs works as espected]) INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM getifaddrs.$OBJEXT" ],[ AC_MSG_RESULT(no) ],[ AC_MSG_RESULT(cross-compiling, assume yes) AC_DEFINE_UNQUOTED([HAVE_WORKING_GETIFADDRS],[1],[getifaddrs works as espected]) INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM getifaddrs.$OBJEXT" ]) ]) # AC_CHECK_CC_OPT # --------------------- # Check whether the C compiler accepts the given option AC_DEFUN([AC_CHECK_CC_OPT], [AC_MSG_CHECKING([whether ${CC-cc} accepts -[$1]]) echo 'void f(){}' > conftest.c if test -z "`${CC-cc} -c -$1 conftest.c 2>&1`"; then AC_MSG_RESULT(yes) CFLAGS="$CFLAGS -$1" else AC_MSG_RESULT(no) fi rm -f conftest* ]) # Usage: # AC_ASK_OPTLIB(library, function, header, description, packagename, libdefine, headerdefine) # Only the last argument is optional, because they will only be defined if both the lib # and header are found # Example: # AC_ASK_OPTLIB(z, compress2, zlib.h, [ Support zlib], zlib, HAVE_LIBZ, HAVE_ZLIB_H) AC_DEFUN([AC_ASK_OPTLIB], [ AC_ARG_WITH($5, [ --with-$5 $4], [ # Specified LIBSPEC=$withval ], [ # Not specified LIBSPECFLAGS=`pkg-config --libs $5 2>/dev/null` LIBSPECCFLAGS=`pkg-config --cflags $5 2>/dev/null` AC_CHECK_LIB($1, $2, [ OLDCPPFLAGS="$CPPFLAGS" OLDCFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS $LIBSPECCFLAGS" CFLAGS="$CFLAGS $LIBSPECCFLAGS" AC_CHECK_HEADER($3, [ LIBSPEC=yes ], [ LIBSPEC=no ]) CPPFLAGS="$OLDCPPFLAGS" CFLAGS="$OLDCFLAGS" ], [ LIBSPEC=no dnl AC_MSG_WARN(Didn't find $5) ], $LIBSPECFLAGS) ]) case $LIBSPEC in no) dnl AC_MSG_WARN(Support for $5 disabled) ;; *) if test "${LIBSPEC}" = "yes"; then true else LIBSPECFLAGS="-L${LIBSPEC}/lib ${LIBSPECFLAGS}" LIBSPECCFLAGS="-I${LIBSPEC}/include ${LIBSPECCFLAGS}" fi AC_CHECK_LIB($1, $2, [ OLDCFLAGS="$CFLAGS" OLDCPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS ${LIBSPECCFLAGS}" CFLAGS="$CFLAGS ${LIBSPECCFLAGS}" AC_CHECK_HEADER($3, [ if test -n "$7"; then AC_DEFINE($7, [1], [Define to 1 if you have the <$3> header file.]) fi if test -n "$6"; then AC_DEFINE($6, [1], [Define to 1 if you have $2 from $5]) fi LDFLAGS="$LDFLAGS $LIBSPECFLAGS" LIBS="$LIBS -l$1" ], [ CFLAGS="$OLDCFLAGS" CPPFLAGS="$OLDCPPFLAGS" AC_MSG_ERROR(Could not find $3) ]) ], [ AC_MSG_ERROR(Could not find $5) ], $LIBSPECFLAGS) ;; esac ]) AC_DEFUN([AC_QEF_C_NORETURN], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts noreturn attribute) AC_CACHE_VAL(qef_cv_c_noreturn, [qef_cv_c_noreturn=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include void f (void) __attribute__ ((noreturn)); void f (void) { exit (1); } ]], [[ f (); ]])],[qef_cv_c_noreturn="yes"; FUNCATTR_NORETURN_VAL="__attribute__ ((noreturn))"],[qef_cv_c_noreturn="no"; FUNCATTR_NORETURN_VAL="/* will not return */"]) ]) AC_MSG_RESULT($qef_cv_c_noreturn) AC_DEFINE_UNQUOTED([FUNCATTR_NORETURN], [$FUNCATTR_NORETURN_VAL],[cc knows about noreturn]) ])dnl bwm-ng-0.6.2/autogen.sh000077500000000000000000000112101341267030500147030ustar00rootroot00000000000000#! /bin/sh # Copyright (c) 2002 Daniel Elstner # * minor changes by Daniel Holbach # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License VERSION 2 as # published by the Free Software Foundation. You are not allowed to # use any other version of the license; unless you got the explicit # permission from the author to do so. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # Be Bourne compatible. (stolen from autoconf) if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then set -o posix fi PROJECT=bwm-ng autoconf=autoconf autoheader=autoheader aclocal= automake= auto_version=0 srcdir=`dirname "$0"` test -n "$srcdir" || srcdir=. origdir=`pwd` cd "$srcdir" AUTOMAKE_FLAGS="--add-missing --gnu $AUTOMAKE_FLAGS" if test -z "$AUTOGEN_SUBDIR_MODE" && test "x$*" = x then echo "I am going to run ./configure with no arguments - if you wish " echo "to pass any to it, please specify them on the $0 command line." fi if test -n "$AUTOCONF_VERSION" then echo "test for autoconf version" for suffix in "" -2.62 -2.61 -2.60 -2.59 -2.58 -2.57 -2.56 -2.55 -2.54 -2.53 -2.52 -2.51 do autoconf_version=`autoconf$suffix --version /dev/null | head -n1 | cut -d " " -f 4` autoheader_version=`autoheader$suffix --version /dev/null | head -n1 | cut -d " " -f 4` version=`echo "$autoconf_version" | cut -c-3 | tr -d .` if test -n "$autoconf_version" && test -n "$autoheader_version" && test "$autoconf_version" = "$autoheader_version" && \ test -n "$version" && \ test -z "`echo -n $version | sed -n s/[0-9]*//p`" then autoconf=autoconf$suffix autoheader=autoheader$suffix if test -n "$suffix" then echo "found version `echo $suffix | cut -c2-`" export AUTOCONF_VERSION=`echo $suffix | cut -c2-` fi break fi done fi if test -n "$AUTOMAKE_VERSION" then echo "test for automake version" for suffix in "" -1.9 -1.8 -1.7 do aclocal_version=`aclocal$suffix --version /dev/null | head -n1 | cut -d " " -f 4` automake_version=`automake$suffix --version /dev/null | head -n1 | cut -d " " -f 4` if test -n "$aclocal_version" && test -n "$automake_version" && test "$aclocal_version" = "$automake_version" && \ test -n `echo "$aclocal_version" | cut -c-3 | tr -d .` then auto_version=`echo "$aclocal_version" | cut -c-3 | tr -d .` if test -z "`echo -n $auto_version | sed -n s/[0-9]*//p`" && test $auto_version -ge 16 then aclocal=aclocal$suffix automake=automake$suffix if test -n "$suffix" then echo "found version `echo $suffix | cut -c2-`" export AUTOMAKE_VERSION=`echo $suffix | cut -c2-` fi break fi fi done else aclocal=aclocal automake=automake fi if test -z "$aclocal" || test -z "$automake" then echo "*******************************" echo "AT LEAST automake 1.7 REQUIRED!" echo "*******************************" exit 1 fi set_option=':' test -n "${BASH_VERSION+set}" && set_option='set' $set_option -x echo trying autoreconf to setup build enviroment autoreconf -v -i -s -W all if test $? -eq 0 then echo running configure now if test -z "$AUTOGEN_SUBDIR_MODE" then "$srcdir/configure" ${1+"$@"} || exit 1 $set_option +x echo echo "Now type 'make' to compile $PROJECT." fi exit 0 fi echo looks like there is no autoreconf, trying to setup all now rm -f config.guess config.sub depcomp install-sh missing mkinstalldirs rm -f config.cache acconfig.h rm -rf autom4te.cache WARNINGS=all export WARNINGS "$aclocal" $ACLOCAL_FLAGS || exit 1 "$autoheader" || exit 1 "$automake" $AUTOMAKE_FLAGS || exit 1 "$autoconf" || exit 1 cd "$origdir" || exit 1 if test -z "$AUTOGEN_SUBDIR_MODE" then "$srcdir/configure" ${1+"$@"} || exit 1 $set_option +x echo echo "Now type 'make' to compile $PROJECT." fi exit 0 bwm-ng-0.6.2/bwm-ng.1000066400000000000000000000241611341267030500141640ustar00rootroot00000000000000.TH bwm-ng 1 "2007-03-01" "" "Bandwidth Monitor NG" .\" .\" Man page written by Volker Gropp (Feb 2005) .\" It was inspired by the iptables manpage .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or .\" (at your option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with this program; if not, write to the Free Software .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. .\" .\" .SH NAME bwm-ng \- Bandwidth Monitor NG (Next Generation), a live bandwidth monitor for network and disk io. .SH SYNOPSIS .BI "bwm-ng "[options] " ... "[configfile] " .SH DESCRIPTION .B bwm-ng can be used to monitor the current bandwidth of all or some specific network interfaces or disks (or partitions). It shows total of in and out as well as total of all interfaces/devices. Several different output methods are supported (curses, curses2, plain, csv and html). \fBbwm-ng\fP is not limited in the number of interfaces or disks and can handle new ones dynamically while its running or hide those which are not up. .SH INPUT METHODS The input methods used pretty much depends on your OS and system. You can choose the preferred method either at start or in curses during run-time. Each method can only be used if .B bwm-ng was compiled with support for it. Currently supported .B network input methods: .RS .TP .4i .BR "proc" : This is the default for \fILinux\fP based systems. It parses the special procfs file \fB/proc/net/dev\fP. This should be used if in doubt in \fILinux\fP. .TP .BR "getifaddrs" : This is the default on \fIBSD\fP systems like \fIFreeBSD\fP, \fINetBSD\fP, \fIOpenBSD\fP and recent \fIMac OS X\fP (>=10.3). This should be used if in doubt on those systems. It uses the getifaddrs systemcall. .TP .BR "kstat" : This is the default for \fISolaris\fP. It uses the kstat systemcall. .TP .BR "sysctl" : This is the default on Systems like \fIIRIX\fP and other \fIUNIX\fP. It can be used on many other systems like early \fIMac OS X\fP as well. It uses the sysctl systemcall. .TP .BR "netstat" : This is a Backup for systems without the above, or other problems. .TP .BR "libstatgrab" : .B bwm-ng can use the external library libstatgrab to gather the data. please refer to \fIhttp://www.i-scream.org/libstatgrab\fP for more info about this. .RE Currently supported .B disk input methods: .RS .TP .4i .BR "disk" : Shows the diskio on Linux 2.6+ systems using /proc/diskstats. Instead of packets the number of read/writes will be shown. .TP .BR "kstatdisk" : same as .B kstat network input but for disk io. It uses the kstat systemcall from Solaris. .TP .BR "sysctl" : Written for \fINetBSD\fP and \fIOpenBSD\fP, but maybe working on other Platforms aswell. .TP .BR "devstat" : devstat library based input. You can find this on FreeBSD based systems. .TP .BR "ioservice" : framework IOKit based input. You can find this on Darwin systems like MacOSX. .TP .BR "libstatdisk" : same as .B libstatgrab but for disk io (\fIhttp://www.i-scream.org/libstatgrab/\fP). .RE .SH OUTPUT METHODS You can select several different ways to output the data gathered by \fBbwm-ng\fP. You can use one of: .RS .TP .4i .BR "curses" : This is the default output method. Usually this fits you the most. In \fIcurses\fP mode you can control \fBbwm-ng\fP with several keys. Press 'h' for a online help. To quit using this mode either press 'q' or ctrl-c. .TP .BR "curses2" : Shows bar charts of the current IO, using curses output. .TP .BR "plain" : \fIPlain\fP or \fIASCII\fP is mostly a backup if curses is not available. You cannot control \fBbwm-ng\fP at all in this mode. To quit press ctrl-c. But for one single single output using .ns bwm-ng -o plain -c 1 this is the mode that fits the best. .TP .BR "csv" : \fICSV\fP is designed to use with scripts for easy parsing. .sp .BR "Type rate" : .br .nf unix timestamp;iface_name;bytes_out/s;bytes_in/s;bytes_total/s;bytes_in;bytes_out;packets_out/s;packets_in/s;packets_total/s;packets_in;packets_out;errors_out/s;errors_in/s;errors_in;errors_out\\n .fi .sp .BR "Type svg, sum, max" : .br .nf unix timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in\\n .fi .sp To skip the first output with only zeros use: .nf bwm-ng -o csv -c 0 .fi .TP .BR "html" : This is designed for use in the WWW. It uses the CSS file bwm-ng.css in current working dir. "--htmlrefresh" only affects the refresh of the page by the browser. For best results use the same value for --timeout and --htmlrefresh. .RE .SH OPTIONS The options that are recognized by .B bwm-ng can be divided into 3 different groups. The long versions can only be used if bwm-ng was compiled with getopt_long. .SS INPUT These options specify the method to gather the data as well as different options for them. .TP .BI "-i, --input " "method" selects which method to use. It can be one of the above (see \fBINPUT METHODS\fP) if support for it was compiled in. .TP .BI "-f, --procfile " "filename" selects the file to parse in \fBproc input method\fP. This is usually \fI/proc/net/dev\fP. .TP .BI " --diskstatsfile " "filename" selects the file to parse in \fBdisk input method\fP. This is usually \fI/proc/diskstats\fP. .TP .BI " --partitionsfile " "filename" selects the file to parse in \fBdisk input method\fP on older Kernel. This is usually \fI/proc/partitions\fP. .TP .BI "-n, --netstat " "path" specifies the binary to execute for \fBnetstat input method\fP. Because this may be a security flaw support for this option is \fInot\fP compiled in .B bwm-ng by default. .SS OUTPUT These options select the way to output the data and several options for the output. .TP .BI "-o, --output " "method" selects which method to use for output. It can be one of the above (see \fBOUTPUT METHODS\fP) if support for it was compiled in. .TP .BI "-u, --unit " "value" selects which unit to show. It can be one of \fIbytes\fP, \fIbits\fP, \fIpackets\fP or \fIerrors\fP. .TP .BI "-T, --type " "value" specifies the type of stats to show. Use one of \fIrate\fP for the current rate/s, \fImax\fP for the maximal value achieved since startup of \fBbwm-ng\fP, \fIsum\fP for the total sum counted since startup of \fBbwm-ng\fP or \fIavg\fP for the average over the last 30 seconds. .TP .BI "-c, --count " "number" number of outputs for \fIPlain\fP and \fICSV\fP output mode. Use '1' for once single output. Using '0' in \fICSV\fP mode will skip first output that always consists of zero values. .TP .BI "-C, --csvchar " "char" specifies the delimiter char for \fICSV\fP mode. The default is ';'. .TP .BI "-F, --outfile " "filename" specifies the use of a \fIoutfile\fP instead of \fIstdout\fP. This option only affects \fICSV\fP and \fIHTML\fP mode. .TP .BI "-R, --htmlrefresh " "seconds" sets the \fIHTML\fP Meta refresh field to seconds in \fIHTML\fP mode. This will result in a reload of the page every \fIn\fP seconds by the browser. If this is set you want to use \fI--htmlheader\fP as well. .TP .BI "-H, --htmlheader " "[value]" if this option is used, \fBbwm-ng\fP will print the correct \fIHTML\fP header () including Meta fields before and after data. This is only useful in \fIHTML\fP mode. \fIvalue\fP can be 0 (off) or 1 (on), if the value is not given '1' is used. .TP .BI "-N, --ansiout " disable ANSI Codes for Plain output. .TP .BI " --longdisknames " show long realnames of disks in Darwin (ioservice input) .SS OTHER These options specify the general behavior of \fBbwm-ng\fP. .TP .BI "-t, --timeout " "msec" displays and gathers stats every \fIn\fP msec (1msec = 1/1000sec). The default is 500msec. .TP .BI "-d, --dynamic " "[value]" shows bytes and bits with dynamic unit like K, M or G (Kilo, Mega, Giga). \fIvalue\fP can be 0 (off) or 1 (on), without a value '1' is used. .TP .BI "-a, --allif " "[mode]" specifies whether only up and selected interfaces (\fImode\fP=0), all which are up but maybe not selected (\fImode\fP=1) or all, even down and not selected interfaces (\fImode\fP=2). If no interface list given (\fI--interfaces\fP) \fImode\fP=1 and \fImode\fP=2 are the same. .TP .BI "-I, --interfaces " "list" show only interfaces which are in this comma separated list (\fBwhitelist\fP). If the list is prefixed by a '%' its meaning is negated and interfaces in this list are hidden from output (\fBblacklist\fP). (Example: %eth0,tun0) .TP .BI "-S, --sumhidden " "[value]" if given and the optional value is not 0, count also hidden and not shown interfaces for total value. .TP .BI "-A, --avglength " "seconds" sets the span in which the stats for average mode are collected. Default is 30 seconds or 2*\fItimeout\fP. .TP .BI "-D, --daemon " "[value]" fork into background and daemonize if given and the optional value is not 0. This only affects \fIHTML\fP and \fICSV\fP mode and \fI--outfile\fP is required. .TP .BI "-h, --help " "" show a help of command line options. .TP .BI "-V, --version " "" print version info .SH CONFIGFILE The behavior of \fBbwm-ng\fP can be also controlled by a \fIconfigfile\fP. By default \fBbwm-ng\fP first reads /etc/bwm-ng.conf and then ~/.bwm-ng.conf. If specified on command line \fBbwm-ng\fP skips those. It consists of the same long-options as used for command line as keys followed by a '=' and the value. Lines starting with a # or unknown key will be ignored. For example: .nf DYNAMIC=1 UNIT=bits PROCFILE=/proc/net/dev OUTPUT=plain .fi .SH OTHER FILES .BR "bwm-ng.css" the CSS file used for html output. .SH SEE ALSO bwm-ng.conf-example for an example of the configfile, README for other comments and hints about bwm-ng. .br \fIhttp://www.gropp.org/\fP for new version or further help and links. .SH AUTHORS Volker Gropp wrote bwm-ng and is current maintainer. .br For further Authors please refer to AUTHORS file which should come with \fBbwm-ng\fP. bwm-ng-0.6.2/bwm-ng.conf-example000066400000000000000000000004641341267030500164020ustar00rootroot00000000000000DYNAMIC=1 UNIT=bits PROCFILE=/proc/net/dev DISKSTATSFILE=/proc/diskstats PARTITIONSFILE=/proc/partitions LONGDISKNAMES=0 ANSIOUT=0 OUTPUT=plain TIMEOUT=666 NETSTAT=netstat INPUT=proc ALLIF=0 INTERFACES=eth0 OUTPUT=curses CSVCHAR=; #OUTFILE= COUNT=0 DAEMON=0 HTMLREFRESH=5 HTMLHEADER=0 TYPE=rate AVGLENGTH=30 bwm-ng-0.6.2/bwm-ng.css000066400000000000000000000011331341267030500146060ustar00rootroot00000000000000 BODY { font: 10pt Arial, Helvetica, sans-serif; text-decoration: none; } .bwm-ng-output { padding: 3px 10px 0.5ex 10px; margin: 10px; width: 50ex; border-width: 1px; border-style: solid; } .bwm-ng-header { margin: 10px; font: 12pt Arial, Helvetica, sans-serif; font-weight: bold; } .bwm-ng-head { font-weight: bold; } .bwm-ng-name { margin-left: 10px; width: 10ex; font-weight: bold; } .bwm-ng-in { width: 10ex; } .bwm-ng-out { width: 10ex; } .bwm-ng-total { width: 10ex; font-weight: bold; } .bwm-ng-errors { color: #FF0000; } .bwm-ng-dummy { } bwm-ng-0.6.2/configure.in000066400000000000000000000664671341267030500152430ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_INIT([bwm-ng],[0.6.2],[bwmng@gropp.org],[bwm-ng]) AC_CONFIG_SRCDIR(src/bwm-ng.c) AM_INIT_AUTOMAKE([gnu]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_MACRO_DIR(./) AC_LANG([C]) AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[enable debug (default: no)]),[ echo "enable debugging info: $enableval" if [ test $enableval = "yes" ]; then if test -z ${CFLAGS}; then CFLAGS="-g3 -Wall" else CFLAGS="-g3 ${CFLAGS}" fi DEBUG="1" fi ],[ if test -z "${CFLAGS}"; then CFLAGS="-O2 -Wall" fi ]) AC_OBJEXT AC_CHECK_TYPES(unsigned long long) # Checks for libraries. CURSES_CHECKED="0" AC_ARG_WITH([curses],AS_HELP_STRING([--with-curses],[with curses (ARG=PATH)]),[ if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_LIB([curses],[newterm,timeout],,[ CPPFLAGS=$OLD_CPPFLAGS ]) CURSES_CHECKED="1" else CURSES_CHECKED="1" fi ]) if [ test $CURSES_CHECKED != "1" ]; then AC_ARG_WITH([ncurses],AS_HELP_STRING([--with-ncurses],[prefer ncurses over curses (ARG=PATH)]),[ if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_LIB([ncurses],[newterm,timeout],,[ CPPFLAGS=$OLD_CPPFLAGS ]) CURSES_CHECKED="1" else CURSES_CHECKED="1" fi ]) fi if [ test $CURSES_CHECKED != "1" ]; then AC_CHECK_LIB([curses],[initscr,timeout],,[ AC_CHECK_LIB([ncurses],[newterm,timeout]) ]) fi AC_CHECK_FUNCS([wattron]) AC_CHECK_FUNCS([curs_set]) AC_CHECK_FUNCS([usleep]) AC_CHECK_FUNCS([strlcpy]) AC_ARG_WITH([time],AS_HELP_STRING([--with-time],[enable accurate time calculating (ARG=PATH)]),[ AC_MSG_CHECKING([for accurate time calc]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_HEADER([time.h],[ AC_CHECK_HEADER([sys/time.h],[ AC_CHECK_FUNCS([gettimeofday],,[ CPPFLAGS=$OLD_CPPFLAGS ]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi ],[ AC_MSG_CHECKING([for accurate time calc]) echo "yes" AC_CHECK_HEADER([time.h],[ AC_CHECK_HEADER([sys/time.h],[ AC_CHECK_FUNCS([gettimeofday]) ]) ]) ]) AC_ARG_WITH([getopt_long],AS_HELP_STRING([--with-getopt_long],[enable getopt_long for long options (ARG=PATH)]),[ AC_MSG_CHECKING([for getopt_long]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_HEADERS([getopt.h],[ AC_CHECK_FUNCS([getopt_long],,[ CPPFLAGS=$OLD_CPPFLAGS ]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi ],[ AC_CHECK_HEADERS([getopt.h],[ AC_CHECK_FUNCS([getopt_long]) ]) ]) ##################################################### # check for inputs ##################################################### INPUT_FOUND=0 DISK_INPUT_FOUND=0 INPUT_SYSTEM="" SYSCTL_ADDED=0 #check for getifaddrs net_if_h_includes=" #include #if STDC_HEADERS # include # include #else # if HAVE_STDLIB_H # include # endif #endif #if HAVE_SYS_SOCKET_H # include #endif " AC_ARG_WITH([getifaddrs],AS_HELP_STRING([--with-getifaddrs],[enable getifaddrs input (ARG=PATH)]),[ AC_MSG_CHECKING([for getifaddrs input]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_HEADER([ifaddrs.h],[ AC_CHECK_FUNCS([getifaddrs],[ AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([net/if.h], [ AC_CHECK_MEMBERS([struct if_data.ifi_ibytes],[ AC_DEFINE_UNQUOTED([HAVE_WORKING_GETIFADDRS],[1],[getifaddrs works as espected]) INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM getifaddrs.$OBJEXT" ],[ CPPFLAGS=$OLD_CPPFLAGS ],[ $net_if_h_includes #include ]) ], [ CPPFLAGS=$OLD_CPPFLAGS ], [$net_if_h_includes]) ],[CPPFLAGS=$OLD_CPPFLAGS]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi ],[ AC_CHECK_HEADER([ifaddrs.h],[ AC_CHECK_FUNCS([getifaddrs],[ AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([net/if.h], [ AC_CHECK_MEMBERS([struct if_data.ifi_ibytes],[ AC_CHECK_WORKING_GETIFADDRS() ],,[ $net_if_h_includes #include ]) ], [], [$net_if_h_includes]) ]) ]) ]) AC_ARG_WITH([sysctl],AS_HELP_STRING([--with-sysctl],[enable sysctl input (ARG=PATH)]),[ AC_MSG_CHECKING([for sysctl input]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_FUNCS([sysctl],[ AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([net/if.h], [ AC_CHECK_MEMBERS([struct if_msghdr.ifm_data],[ INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM sysctl.$OBJEXT" SYSCTL_ADDED=1 AC_DEFINE_UNQUOTED([HAVE_STRUCT_IF_MSGHDR_IFM_DATA],[1],[sysctl input fully available]) ],[ CPPFLAGS=$OLD_CPPFLAGS ],[ $net_if_h_includes #include ]) ], [ CPPFLAGS=$OLD_CPPFLAGS ], [$net_if_h_includes]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi ],[ AC_CHECK_FUNCS([sysctl],[ AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([net/if.h], [ AC_CHECK_MEMBERS([struct if_msghdr.ifm_data],[ INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM sysctl.$OBJEXT" SYSCTL_ADDED=1 AC_DEFINE_UNQUOTED([HAVE_STRUCT_IF_MSGHDR_IFM_DATA],[1],[sysctl input fully available]) ],,[ $net_if_h_includes #include ]) ],,[$net_if_h_includes]) ]) ]) AC_ARG_WITH([sysctldisk],AS_HELP_STRING([--with-sysctldisk],[enable sysctl disk input (ARG=PATH)]),[ AC_MSG_CHECKING([for sysctl disk input]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_FUNCS([sysctl],[ AC_CHECK_HEADERS([sys/disk.h],[ SYSCTL_DISK=0 AC_CHECK_TYPES([struct diskstats],[ DISK_INPUT_FOUND=1 if [ test $SYSCTL_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM sysctl.$OBJEXT" fi AC_DEFINE_UNQUOTED([HAVE_STRUCT_DISKSTATS],[1],[sysctl diskinput available]) AC_CHECK_MEMBERS([struct diskstats.ds_rbytes],,,[#include ]) AC_CHECK_MEMBERS([struct diskstats.ds_name],,,[#include ]) ],[ AC_CHECK_TYPES([struct disk_sysctl],[ DISK_INPUT_FOUND=1 if [ test $SYSCTL_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM sysctl.$OBJEXT" fi AC_DEFINE_UNQUOTED([HAVE_STRUCT_DISK_SYSCTL],[1],[sysctl diskinput available]) AC_CHECK_MEMBERS([struct disk_sysctl.dk_rbytes],,,[#include ]) ],[ CPPFLAGS=$OLD_CPPFLAGS ],[#include ]) ],[#include ]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi ],[ AC_CHECK_FUNCS([sysctl],[ AC_CHECK_HEADERS([sys/disk.h],[ AC_CHECK_TYPES([struct diskstats],[ DISK_INPUT_FOUND=1 if [ test $SYSCTL_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM sysctl.$OBJEXT" fi AC_DEFINE_UNQUOTED([HAVE_STRUCT_DISKSTATS],[1],[sysctl diskinput available]) AC_CHECK_MEMBERS([struct diskstats.ds_rbytes],,,[#include ]) AC_CHECK_MEMBERS([struct diskstats.ds_name],,,[#include ]) ],[ AC_CHECK_TYPES([struct disk_sysctl],[ DISK_INPUT_FOUND=1 if [ test $SYSCTL_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM sysctl.$OBJEXT" fi AC_DEFINE_UNQUOTED([HAVE_STRUCT_DISK_SYSCTL],[1],[sysctl diskinput available]) AC_CHECK_MEMBERS([struct disk_sysctl.dk_rbytes],,,[#include ]) ],,[#include ]) ],[#include ]) ]) ]) ]) AC_ARG_WITH([kstat],AS_HELP_STRING([--with-kstat],[enable kstat (Solaris) input (ARG=PATH)]),[ AC_MSG_CHECKING([for kstat input]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_LIB([kstat],[kstat_open],[ AC_DEFINE_UNQUOTED([HAVE_LIBKSTAT],[1],[Define to 1 if you have the 'kstat' library (-lkstat).]) LIBS="$LIBS -lkstat" DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM libkstat.$OBJEXT" INPUT_FOUND=1 ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi ],[ AC_CHECK_LIB([kstat],[kstat_open],[ AC_DEFINE_UNQUOTED([HAVE_LIBKSTAT],[1],[Define to 1 if you have the 'kstat' library (-lkstat).]) LIBS="$LIBS -lkstat" INPUT_SYSTEM="$INPUT_SYSTEM libkstat.$OBJEXT" INPUT_FOUND=1 DISK_INPUT_FOUND=1 ]) ]) AC_ARG_WITH([win32],AS_HELP_STRING([--with-win32],[enable win32 input]),[ echo "enable win32 support" AC_DEFINE_UNQUOTED([WIN32],[1],[enable win32 support]) LIBS="$LIBS -liphlpapi" INPUT_SYSTEM="$INPUT_SYSTEM win32.$OBJEXT" INPUT_FOUND=1 ]) AC_ARG_WITH([procnetdev],AS_HELP_STRING([--with-procnetdev],[enable /proc/net/dev input (ARG=PATH)]),[ AC_MSG_CHECKING([for /proc/net/dev input]) AC_MSG_RESULT($withval) if [ test $withval = "yes" ]; then AC_DEFINE_UNQUOTED([HAVE__PROC_NET_DEV],[1],[enable /proc/net/dev support]) INPUT_SYSTEM="$INPUT_SYSTEM proc_net_dev.$OBJEXT" INPUT_FOUND=1 else if [ test $withval != "no" ]; then AC_CHECK_FILES([$withval],[ AC_DEFINE_UNQUOTED([PROC_NET_DEV_PATH],["$withval"],[set path to /proc/net/dev raw-file]) AC_DEFINE_UNQUOTED([HAVE__PROC_NET_DEV],[1],[enable /proc/net/dev support]) INPUT_SYSTEM="$INPUT_SYSTEM proc_net_dev.$OBJEXT" INPUT_FOUND=1 ]) fi fi ],[ if test "$cross_compiling" != yes; then AC_CHECK_FILES([/proc/net/dev],[ INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_net_dev.$OBJEXT" ]) fi ]) AC_ARG_WITH([diskstats],AS_HELP_STRING([--with-diskstats],[enable /proc/diskstats input (diskio) (ARG=PATH)]),[ AC_MSG_CHECKING([for /proc/diskstats input]) AC_MSG_RESULT($withval) if [ test $withval = "yes" ]; then AC_DEFINE_UNQUOTED([HAVE__PROC_DISKSTATS],[1],[enable /proc/diskstats|/proc/partitions support]) DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_diskstats.$OBJEXT" else if [ test $withval != "no" ]; then AC_DEFINE_UNQUOTED([PROC_DISKSTATS_PATH],["$withval"],[set path to /proc/disktstats raw-file]) AC_DEFINE_UNQUOTED([HAVE__PROC_DISKSTATS],[1],[enable /proc/diskstats|/proc/partitions support]) DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_diskstats.$OBJEXT" fi fi ]) # check for diskstats on ac_arg_with partitions down below AC_ARG_WITH([partitions],AS_HELP_STRING([--with-partitions],[enable /proc/partitions input (diskio) (ARG=PATH)]),[ AC_MSG_CHECKING([for /proc/diskstats|/proc/partitions input]) AC_MSG_RESULT($withval) if [ test $withval = "yes" ]; then AC_DEFINE_UNQUOTED([HAVE__PROC_DISKSTATS],[1],[enable /proc/diskstats|/proc/partitions support]) DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_diskstats.$OBJEXT" else if [ test $withval != "no" ]; then AC_DEFINE_UNQUOTED([PROC_PARTITIONS_PATH],["$withval"],[set path to /proc/partitions raw-file]) AC_DEFINE_UNQUOTED([HAVE__PROC_DISKSTATS],[1],[enable /proc/diskstats|/proc/partitions support]) DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_diskstats.$OBJEXT" fi fi ],[ if test "$cross_compiling" != yes; then AC_CHECK_FILES([/proc/diskstats],[ DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_diskstats.$OBJEXT" ],[ AC_CHECK_FILES([/proc/partitions],[ AC_DEFINE_UNQUOTED([HAVE__PROC_DISKSTATS],[1],[enable /proc/diskstats|/proc/partitions support]) DISK_INPUT_FOUND=1 INPUT_SYSTEM="$INPUT_SYSTEM proc_diskstats.$OBJEXT" ]) ]) fi ]) AC_ARG_WITH([devstat],AS_HELP_STRING([--with-devstat],[enable devstat input (ie FreeBSD) (ARG=PATH)]),[ AC_MSG_CHECKING([for devstat input]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi AC_CHECK_HEADERS([sys/dkstat.h],[ AC_CHECK_HEADERS([devstat.h],[ AC_CHECK_LIB([devstat],[devstat_getdevs],[ DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_DEVSTAT_GETDEVS],[1],[Define to 1 if you have the 'devstat' library (-ldevstat).]) LIBS="$LIBS -ldevstat" INPUT_SYSTEM="$INPUT_SYSTEM devstat.$OBJEXT" ],[ AC_CHECK_LIB([devstat],[getdevs],[ DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_GETDEVS],[1],[Define to 1 if you have the 'devstat' library (-ldevstat).]) LIBS="$LIBS -ldevstat" INPUT_SYSTEM="$INPUT_SYSTEM devstat.$OBJEXT" ]) ]) ],,[#include ]) ]) fi ],[ AC_CHECK_HEADERS([sys/dkstat.h],[ AC_CHECK_HEADERS([devstat.h],[ AC_CHECK_LIB([devstat],[devstat_getdevs],[ DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_DEVSTAT_GETDEVS],[1],[Define to 1 if you have the 'devstat' library (-ldevstat).]) LIBS="$LIBS -ldevstat" INPUT_SYSTEM="$INPUT_SYSTEM devstat.$OBJEXT" ],[ AC_CHECK_LIB([devstat],[getdevs],[ DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_GETDEVS],[1],[Define to 1 if you have the 'devstat' library (-ldevstat).]) LIBS="$LIBS -ldevstat" INPUT_SYSTEM="$INPUT_SYSTEM devstat.$OBJEXT" ]) ]) ],,[#include ]) ]) ]) AC_ARG_WITH([ioservice],AS_HELP_STRING([--with-ioservice],[Use darwin IOService to gather statistics]),[ AC_MSG_CHECKING([for ioservice input]) AC_MSG_RESULT($withval) if [ test $withval != "no" ]; then OLD_CPPFLAGS=$CPPFLAGS if [ test $withval != "yes" ]; then CPPFLAGS="$CPPFLAGS -I$withval" fi OLDLIBS=$LIBS LIBS="$LIBS -framework IOKit -framework CoreFoundation" HAVE_IOSERVICE=0 AC_CHECK_FUNCS([IOServiceGetMatchingServices],[ AC_CHECK_FUNCS([IOMasterPort],[ AC_CHECK_FUNCS([IORegistryEntryCreateCFProperties],[ DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_IOSERVICE],[1],[Define to 1 if you have Darwin IOService support]) HAVE_IOSERVICE=1 INPUT_SYSTEM="$INPUT_SYSTEM ioservice.$OBJEXT" ]) ]) ],,[ #include #include #include ]) if [ test $HAVE_IOSERVICE -eq 0 ]; then LIBS=$OLDLIBS CPPFLAGS=$OLD_CPPFLAGS fi fi ],[ dnl evil hack to check for -framework gcc option, i love apple!!!!111 AC_MSG_CHECKING([whether cc and linker accepts -framework IOKit -framework CoreFoundation]) echo 'int main(){}' > conftest.c if test -z "`${CC-cc} -o conftest conftest.c -framework IOKit -framework CoreFoundation 2>&1`"; then AC_MSG_RESULT(yes) OLDLIBS=$LIBS LIBS="$LIBS -framework IOKit -framework CoreFoundation" AC_CHECK_FUNCS([IOServiceGetMatchingServices],[ AC_CHECK_FUNCS([IOMasterPort],[ AC_CHECK_FUNCS([IORegistryEntryCreateCFProperties],[ DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_IOSERVICE],[1],[Define to 1 if you have Darwin IOService support]) HAVE_IOSERVICE=1 INPUT_SYSTEM="$INPUT_SYSTEM ioservice.$OBJEXT" ]) ]) ]) if [ test $HAVE_IOSERVICE -eq 0 ]; then LIBS=$OLDLIBS fi else AC_MSG_RESULT(no) fi rm -f conftest* ]) AC_ARG_WITH([libstatgrab],AS_HELP_STRING([--without-libstatgrab],[Use libstatgrab to gather statistics])) CHECK_LIBSTAT=0 if [ test "x$with_libstatgrab" != "xno" ] && [ test $INPUT_FOUND -ne 1 ]; then CHECK_LIBSTAT=1 fi if [ test "x$with_libstatgrab" != "xno" ] && [ test $DISK_INPUT_FOUND -ne 1 ]; then CHECK_LIBSTAT=1 fi if [test "x$with_libstatgrab" = "xyes"] || [ test $CHECK_LIBSTAT -eq 1 ]; then OLD_CPPFLAGS=$CPPFLAGS AC_CHECK_LIB([statgrab],[sg_get_network_io_stats,sg_get_disk_io_stats],[ INPUT_FOUND=1 DISK_INPUT_FOUND=1 AC_DEFINE_UNQUOTED([HAVE_LIBSTATGRAB],[1],[Define to 1 if you have the 'statgrab' library (-lstatgrab).]) LIBS="$LIBS -lstatgrab" INPUT_SYSTEM="$INPUT_SYSTEM libstatgrab.$OBJEXT" ],[ CPPFLAGS=$OLD_CPPFLAGS ]) fi if [ test $INPUT_FOUND -ne 1 ] && [ test $DISK_INPUT_FOUND -ne 1 ]; then AC_MSG_ERROR(["NO INPUT FOUND"]); fi ################################################# # inputs check done ################################################# #check for getifaddrs linux_if_h_includes=" #if HAVE_SYS_SOCKET_H # include #endif " AC_CHECK_FUNCS([ioctl]) AC_CHECK_HEADERS([sys/socket.h linux/if.h],,,[$linux_if_h_includes]) AC_CHECK_HEADERS([sys/tty.h]) AC_CHECK_HEADERS([linux/tty.h]) AC_CHECK_HEADERS([stropts.h]) AC_ARG_ENABLE([html],AS_HELP_STRING([--enable-html],[enable html output (default: yes)]),[ echo "enable html output: $enableval" if [ test $enableval = "yes" ]; then AC_DEFINE_UNQUOTED([HTML],[1],[enable html output]) fi ],[ echo "enable html output: yes" AC_DEFINE_UNQUOTED([HTML],[1],[enable html output]) ]) AC_ARG_ENABLE([csv],AS_HELP_STRING([--enable-csv],[enable csv output (default: yes)]),[ echo "enable csv output: $enableval" if [ test $enableval = "yes" ]; then AC_DEFINE_UNQUOTED([CSV],[1],[enable CSV output]) fi ],[ echo "enable csv output: yes" AC_DEFINE_UNQUOTED([CSV],[1],[enable CSV output]) ]) AC_ARG_ENABLE([extendedstats],AS_HELP_STRING([--enable-extendedstats],[enable max, sum and avg stats (default: yes)]),[ echo "enable extended stats: $enableval" if [ test $enableval = "yes" ]; then AC_DEFINE_UNQUOTED([EXTENDED_STATS],[1],[enable max, sum and avg stats]) fi ],[ echo "enable extended stats: yes" AC_DEFINE_UNQUOTED([EXTENDED_STATS],[1],[enable max, sum and avg stats]) ]) AC_ARG_ENABLE([configfile],AS_HELP_STRING([--enable-configfile],[enable configfile support (default: yes)]),[ echo "enable config-file support: $enableval" if [ test $enableval = "yes" ]; then AC_DEFINE_UNQUOTED([CONFIG_FILE],[1],[enable use of configfile]) fi ],[ echo "enable config-file support: yes" AC_DEFINE_UNQUOTED([CONFIG_FILE],[1],[enable use of configfile]) ]) AC_ARG_ENABLE([64bit],AS_HELP_STRING([--enable-64bit],[enable 64bit support (default: no)]),[ echo "enable 64bit support: $enableval" if [ test $enableval = "yes" ]; then AC_DEFINE_UNQUOTED([SYS_64BIT],[1],[enable 64bit support]) fi ]) AC_CHECK_HEADERS([pwd.h],[ AC_CHECK_FUNCS([getpwuid],[ AC_DEFINE_UNQUOTED([HAVE_GETPWUID],[1],[enable use of getbwuid]) ]) ]) NETSTAT_ADDED=0 AC_ARG_ENABLE([netstatpath],AS_HELP_STRING([--enable-netstatpath],[enable path to netstat as runtime option (default: no), WARNING THIS IS A SECURITY FLAW!]),[ echo "enable path to netstat as option: $enableval" if [ test $enableval = "yes" ]; then AC_DEFINE_UNQUOTED([ALLOW_NETSTATPATH],[1],[allow set path to netstat at runtime]) fi ],[ echo "enable path to netstat as option: no" ]) NETSTAT_BYTE="0" AC_ARG_ENABLE([netstatbyte],AS_HELP_STRING([--enable-netstatbyte],[enable netstat with byte info (default: no)]),[ echo "enable netstat with byte info: $enableval" if [ test $enableval = "yes" ]; then NETSTAT_BYTE="1" fi ]) NETSTAT_LINK="0" AC_ARG_ENABLE([netstatlink],AS_HELP_STRING([--enable-netstatlink],[enable netstat with link limit (default: no)]),[ echo "enable netstat with link limit: $enableval" if [ test $enableval = "yes" ]; then NETSTAT_LINK="1" fi ]) NETSTAT_DEFINED="0" AC_ARG_WITH([netstatbsd],AS_HELP_STRING([--with-netstatbsd],[enable bsd like netstat -i (ARG=PATH)]),[ if [ test $withval != "no" ]; then if [ test $withval != "yes" ]; then echo "bsd like version with byte info forced: $withval" AC_DEFINE_UNQUOTED([HAVE_NETSTAT_PATH],[$withval],[set path to netstat]) else echo "bsd like version with byte info forced" fi if [ test $NETSTAT_BYTE != "1" ]; then AC_DEFINE_UNQUOTED([NETSTAT_BSD],[1],[use bsd like netstat]) NETSTAT_DEFINED="1" if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else AC_DEFINE_UNQUOTED([NETSTAT_BSD_BYTES],[1],[use bsd like netstat including bytes info]) NETSTAT_DEFINED="1" if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi fi if [ test $NETSTAT_LINK != "0" ]; then AC_DEFINE_UNQUOTED([NETSTAT_BSD_LINK],[1],[use bsd like netstat with link switch]) NETSTAT_DEFINED="1" if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi fi else NETSTAT_DEFINED="1" echo "disable netstat: bsd like version" fi ]) AC_ARG_WITH([netstatlinux],AS_HELP_STRING([--with-netstatlinux],[enable linux like netstat -i (ARG=PATH)]),[ if [ test $withval != "no" ]; then if [ test $withval != "yes" ]; then echo "GNU net-tools like version forced: $withval" AC_DEFINE_UNQUOTED([HAVE_NETSTAT_PATH],[$withval],[set path to netstat]) else echo "GNU net-tools like version forced" fi AC_DEFINE_UNQUOTED([NETSTAT_LINUX],[1],[use GNU net-tools netstat]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi NETSTAT_DEFINED="1" else NETSTAT_DEFINED="1" echo "disable netstat: GNU net-tools like version" fi ]) AC_ARG_WITH([netstatsolaris],AS_HELP_STRING([--with-netstatsolaris],[enable solaris like netstat -i (ARG=PATH)]),[ if [ test $withval != "no" ]; then if [ test $withval != "yes" ]; then echo "solaris like version forced: $withval" AC_DEFINE_UNQUOTED([HAVE_NETSTAT_PATH],[$withval],[set oath to netstat]) else echo "solaris like version forced" fi AC_DEFINE_UNQUOTED([NETSTAT_SOLARIS],[1],[use Solaris netstat theme]) NETSTAT_DEFINED="1" if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else NETSTAT_DEFINED="1" echo "disable netstat: solaris like version" fi ]) AC_ARG_WITH([netstatnetbsd],AS_HELP_STRING([--with-netstatnetbsd],[enable NetBSD/OpenBSD like netstat -i (ARG=PATH)]),[ if [ test $withval != "no" ]; then if [ test $withval != "yes" ]; then echo "NetBSD/OpenBSD like version forced: $withval" AC_DEFINE_UNQUOTED([HAVE_NETSTAT_PATH],[$withval],[set path to netstat]) else echo "NetBSD/OpenBSD like version forced" fi AC_DEFINE_UNQUOTED([NETSTAT_NETBSD],[1],[use NetBSD/OpenBSD like netstat]) NETSTAT_DEFINED="1" if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else NETSTAT_DEFINED="1" echo "disable netstat: NetBSD/OpenBSD like version" fi ]) if [ test $NETSTAT_DEFINED != "1" ]; then AC_PROG_EGREP if [ test "${EGREP}" ]; then AC_CHECK_PROGS([NETSTAT_CMD],[netstat]) if [ test "${NETSTAT_CMD}" ]; then AC_MSG_CHECKING([for netstat version]) net_test=`${NETSTAT_CMD} -ia 2>/dev/null | ${EGREP} "Iface +MTU +Met +RX-OK +RX-ERR +RX-DRP +RX-OVR +TX-OK +TX-ERR +TX-DRP +TX-OVR +Flg"` if [ test "${net_test}" ]; then AC_MSG_RESULT([GNU net-tools like version found]) AC_DEFINE_UNQUOTED([NETSTAT_LINUX],[1],[use GNU net-tools netstat]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else net_test=`${NETSTAT_CMD} -iW 2>/dev/null | ${EGREP} "Name +Mtu +Network +Address +Ipkts +Ierrs +Opkts +Oerrs +Coll"` if [ test "${net_test}" ]; then net_test2=`${NETSTAT_CMD} -iW -b 2>/dev/null | ${EGREP} "Name +Mtu +Network +Address +Ipkts +Ierrs +Ibytes +Opkts +Oerrs +Obytes +Coll"` if [ test "${net_test2}" ]; then AC_MSG_RESULT([BSD like version with byte info found]) AC_DEFINE_UNQUOTED([NETSTAT_BSD_BYTES],[1],[bsd like version with byte info]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else AC_MSG_RESULT([BSD like version found]) AC_DEFINE_UNQUOTED([NETSTAT_BSD],[1],[BSD like netstat]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi fi AC_MSG_CHECKING([for netstat -f link]) net_test3=`${NETSTAT_CMD} -iW -f link 2>/dev/null | ${EGREP} "Name +Mtu +Network +Address +Ipkts +Ierrs +Opkts +Oerrs +Coll"` if [ test "${net_test3}" ]; then AC_MSG_RESULT([yes]) AC_DEFINE_UNQUOTED([NETSTAT_BSD_LINK],[1],[enable link info for netstat]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else AC_MSG_RESULT([no]) fi else net_test=`${NETSTAT_CMD} -i -f inet -f inet6 2>/dev/null | ${EGREP} "Name +Mtu +Net/Dest +Address +Ipkts +Ierrs +Opkts +Oerrs +Collis +Queue"` if [ test "${net_test}" ]; then AC_MSG_RESULT([solaris version found]) AC_DEFINE_UNQUOTED([NETSTAT_SOLARIS],[1],[use Solaris netstat]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else net_test=`${NETSTAT_CMD} -ibd 2>/dev/null | ${EGREP} "Name +Mtu +Network +Address +Ibytes +Obytes +Drop"` if [ test "${net_test}" ]; then AC_MSG_RESULT([Net/OpenBSD version found]) AC_DEFINE_UNQUOTED([NETSTAT_NETBSD],[1],[Use Net/OpenBSD netstat]) if [ test $NETSTAT_ADDED -eq 0 ]; then INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT" NETSTAT_ADDED=1 fi else AC_MSG_RESULT([unknown netstat version - disabled]) echo "********************************************* please mail 'netstat -i' output to author *********************************************" fi fi fi fi fi fi fi AC_QEF_C_NORETURN AC_C_INLINE if [ test -z ${DEBUG} ]; then AC_ARG_WITH([strip],AS_HELP_STRING([--with-strip],[use strip after make (ARG=PATH)]),[ echo "enable strip... " AC_MSG_RESULT($enableval) if [ test $withval != "no" ]; then if [ test $withval != "yes" ]; then STRIP="${withval} \${TARGET}" else if test "$cross_compiling" != yes; then AC_CHECK_FILES([/usr/ccs/bin/strip],[ AC_CHECK_PROGS([STRIP],[strip],,,[/usr/ccs/bin]) ]) fi if [ test "${STRIP}" ]; then STRIP="${STRIP} \${TARGET}" else AC_CHECK_PROGS([STRIP],[strip]) if [ test "${STRIP}" ]; then STRIP="${STRIP} \${TARGET}" fi fi fi fi ],[ if test "$cross_compiling" != yes; then AC_CHECK_FILES([/usr/ccs/bin/strip],[ AC_CHECK_PROGS([STRIP],[strip],,,[/usr/ccs/bin]) ]) fi if [ test "${STRIP}" ]; then STRIP="/usr/ccs/bin/${STRIP} \${TARGET}" else AC_CHECK_PROGS([STRIP],[strip]) if [ test "${STRIP}" ]; then STRIP="${STRIP} \${TARGET}" fi fi ]) else STRIP="@echo DEBUG mode enabled." fi #AC_CHECK_CC_OPT(Wno-long-double) #AC_CHECK_CC_OPT(Wno-long-long) AC_SUBST([INPUT_SYSTEM]) AC_CONFIG_FILES([ Makefile src/Makefile ]) AC_OUTPUT bwm-ng-0.6.2/src/000077500000000000000000000000001341267030500134765ustar00rootroot00000000000000bwm-ng-0.6.2/src/Makefile.am000066400000000000000000000014331341267030500155330ustar00rootroot00000000000000 ## Process this file with automake to produce Makefile.in bin_PROGRAMS = bwm-ng bwm_ng_SOURCES = bwm-ng.c process.c output.c options.c help.c curses_tools.c EXTRA_bwm_ng_SOURCES = input/retrieve.c input/devstat.c input/libkstat.c input/netstat.c input/proc_net_dev.c input/sysctl.c input/ioservice.c input/libstatgrab.c input/proc_diskstats.c input/win32.c input/getifaddrs.c bwm_ng_LDADD = retrieve.$(OBJEXT) $(INPUT_SYSTEM) bwm_ng_DEPENDENCIES = retrieve.$(OBJEXT) $(INPUT_SYSTEM) noinst_HEADERS = bwm-ng.h process.h output.h options.h help.h curses_tools.h types.h defines.h global_vars.h input/devstat.h input/libkstat.h input/netstat.h input/proc_net_dev.h input/sysctl.h input/ioservice.h input/libstatgrab.h input/proc_diskstats.h input/retrieve.h input/win32.h input/getifaddrs.h bwm-ng-0.6.2/src/bwm-ng.c000066400000000000000000000220561341267030500150360ustar00rootroot00000000000000/****************************************************************************** * bwm-ng * * * * Copyright (C) 2004-2006 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "global_vars.h" #include "bwm-ng.h" /* handle interrupt signal */ void sigint(int sig) FUNCATTR_NORETURN; static inline void init(void); /* clear stuff and exit */ #ifdef __STDC__ void deinit(int code, const char *error_msg, ...) { #else void deinit(int code, ...) { #endif va_list ap; #if EXTENDED_STATS int local_if_count; struct double_list *list_p; #endif #ifdef HAVE_CURSES if (mywin!=NULL && (output_method==CURSES_OUT || output_method==CURSES2_OUT)) { /* first close curses, so we dont leave mess behind */ #if HAVE_CURS_SET curs_set(1); #endif endwin(); } #endif #ifdef IOCTL /* close socket if we opened it for ioctl */ if (skfd >= 0) { close(skfd); } #endif /* we should clean if_state, the data array */ if (if_stats!=NULL) { #if EXTENDED_STATS /* clean avg list for each iface */ for (local_if_count=0;local_if_countnext; free(list_p); } } #endif free(if_stats); } /* free the opt iface_list, ifaces to show or hide */ if (iface_list!=NULL) free(iface_list); #if CSV || HTML /* close the out_file */ if (out_file!=NULL) fclose(out_file); if (out_file_path!=NULL) free(out_file_path); #endif #ifdef __STDC__ /* output errormsg if given */ if (error_msg!=NULL) { va_start(ap, error_msg); vprintf(error_msg,ap); } #else va_start(ap); vprintf(ap); #endif /* we are done, say goodbye */ exit(code); } /* sigint handler */ void sigint(int sig) { /* we got a sigint, call deinit and exit */ deinit(0, NULL); } static inline void init(void) { if_count=0; delay=500; #if EXTENDED_STATS avg_length=0; #endif output_unit=BYTES_OUT; output_type=RATE_OUT; show_all_if=0; #ifdef HAVE_CURSES output_method=CURSES_OUT; mywin=NULL; max_rt=32; scale=0; show_only_if=0; #else output_method=PLAIN_OUT; #endif iface_list=NULL; #ifdef CSV csv_char=';'; #endif #if CSV || HTML out_file=NULL; out_file_path=NULL; #endif output_count=-1; daemonize=0; sumhidden=0; /* gcc doesnt support #elifdef so we have to use this ugly piece */ #ifdef PROC_NET_DEV input_method=PROC_IN; #elif defined(GETIFADDRS) input_method=GETIFADDRS_IN; #elif defined(LIBSTATGRAB) input_method=LIBSTAT_IN; #elif defined(SYSCTL) input_method=SYSCTL_IN; #elif defined(HAVE_LIBKSTAT) input_method=KSTAT_IN; #elif defined(NETSTAT) input_method=NETSTAT_IN; #elif defined(WIN32) input_method=WIN32_IN; #elif defined(HAVE_PROC_DISKSTATS) input_method=DISKLINUX_IN; #else #error "NO INPUT DEFINED!" input_method=0; #endif ansi_output=1; #ifdef HTML html_refresh=5; html_header=0; #endif #ifdef IOCTL skfd=-1; #endif if_stats=NULL; #ifdef PROC_NET_DEV strncpy(PROC_FILE,PROC_NET_DEV,PATH_MAX); #endif #ifdef PROC_DISKSTATS strncpy(PROC_DISKSTATS_FILE,PROC_DISKSTATS,PATH_MAX); #endif #ifdef PROC_PARTITIONS strncpy(PROC_PARTITIONS_FILE,PROC_PARTITIONS,PATH_MAX); #endif #if IOSERVICE_IN long_darwin_disk_names = 0; #endif time_t t = time(NULL); strftime(start_time, sizeof(start_time), "%c", localtime(&t)); } /* do the main thing */ int main (int argc, char *argv[]) { unsigned char idle_chars_p=0; char ch; init(); /* handle all cmd line and configfile options */ get_cmdln_options(argc,argv); /* check them */ if (output_method<0) deinit(1,"invalid output selected\n"); if (input_method<0) deinit(1,"invalid input selected\n"); #ifdef LIBSTATGRAB if (sg_init(0) != 0) { deinit(1,"libstatgrab failed to initialise\n"); } #endif /* init total stats to zero */ memset(&if_stats_total,0,(size_t)sizeof(t_iface_stats)); #ifdef HAVE_CURSES if (output_method==CURSES_OUT || output_method==CURSES2_OUT) { /* init curses */ if (init_curses()) signal(SIGWINCH,sigwinch); } #endif /* end of init curses, now set a sigint handler to deinit the screen on ctrl-break */ signal(SIGINT,sigint); signal(SIGTERM,sigint); #ifdef CSV /* get stats without verbose if cvs */ if (output_method==CSV_OUT && output_count>-1) { get_iface_stats(0); #ifdef HAVE_USLEEP if (usleep(delay*1000) != 0) { if (errno == EINVAL) { errno = 0; /* there seems to be systems where 1million usecs is max */ usleep(999999); } } #else Sleep(delay); #endif } #endif #ifdef HAVE_FORK if (daemonize) { int nbyt = 0; /* lets fork into background */ if ((nbyt = fork()) == -1) { deinit(1,"could not fork into background: %s\n",strerror(errno)); } if (nbyt != 0) { /* nbyt is the new child pid here */ deinit(1,"forking into background\n"); } setsid(); } #endif if (output_count==0) output_count=-1; if (output_method==PLAIN_OUT && output_count==1) output_method=PLAIN_OUT_ONCE; if (output_method==PLAIN_OUT) printf("\033[2J"); /* clear screen for plain out */ while (1) { /* do the main loop */ #ifdef HTML /* open the output file */ if (output_method==HTML_OUT && out_file_path) { if (out_file) fclose(out_file); out_file=fopen(out_file_path,"w"); } #endif /* check if we will output anything */ ch=!(output_method==PLAIN_OUT_ONCE #ifdef HTML || (output_method==HTML_OUT && !daemonize) #endif ); /* print the header (info) if verbose */ if (ch) idle_chars_p=print_header(idle_chars_p); /* do the actual work, get and print stats */ get_iface_stats(ch); #if HTML /* close html tags */ if (output_method==HTML_OUT && html_header && daemonize) fprintf((out_file==NULL ? stdout : out_file),"\n\n\n"); /* close the output file, so we dont sit on it and block it */ if (out_file && output_method==HTML_OUT && daemonize) { fclose(out_file); out_file=NULL; } #endif /* handle the number of max outputs if set */ if (( #ifdef CSV output_method==CSV_OUT || #endif output_method==PLAIN_OUT) && output_count>0) { output_count--; /* go to exit if we are done, will break the while(1) */ if (output_count==0) break; } /* either refresh the output and handle gui input */ #ifdef HAVE_CURSES if (output_method==CURSES_OUT || output_method==CURSES2_OUT) { refresh(); handle_gui_input(getch()); } else #endif /* or just wait delay ms */ #ifdef HAVE_USLEEP if (usleep(delay*1000)==EINVAL) { usleep(999999); delay=999; } #else Sleep(delay); #endif /* quit if we should only output once */ if (output_method==PLAIN_OUT_ONCE #ifdef HTML || (output_method==HTML_OUT && !daemonize) #endif ) break; /* dont loop when we have plain output */ } #ifdef HTML /* do we need to output for html? */ if (output_method==HTML_OUT && !daemonize) { print_header(0); get_iface_stats(1); if (html_header) fprintf(out_file==NULL ? stdout : out_file,"\n\n\n"); } #endif /* do we need to output for plain? */ if (output_method==PLAIN_OUT_ONCE) { print_header(0); get_iface_stats(1); } deinit(0,NULL); return 0; /* only to avoid gcc warning */ } bwm-ng-0.6.2/src/bwm-ng.h000066400000000000000000000042151341267030500150400ustar00rootroot00000000000000/****************************************************************************** * bwm-ng * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __BWM_NG_H #define __BWM_NG_H #include "defines.h" #include "types.h" #include "curses_tools.h" #include "options.h" #include "output.h" #include "input/retrieve.h" #include "help.h" #ifdef WIN32 #include #endif #ifdef __STDC__ #include void deinit(int code, const char *error_msg, ...) FUNCATTR_NORETURN; #else #include void deinit(int code, ...) FUNCATTR_NORETURN; #endif #endif bwm-ng-0.6.2/src/curses_tools.c000066400000000000000000000120701341267030500163660ustar00rootroot00000000000000/****************************************************************************** * bwm-ng curses stuff * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "global_vars.h" #include "curses_tools.h" #ifdef HAVE_CURSES /* handle key input by user in gui (curses) mode */ void handle_gui_input(char c) { switch (c) { /* lets check for known keys */ case '+': /* increase delay */ delay+=100; timeout(delay); break; case '-': /* decrease delay */ if (delay>100) { delay+=-100; timeout(delay); } break; case 'a': case 'A': show_all_if++; if (show_all_if>2) { show_all_if=0; clean_down_ifaces(); } if (iface_list==NULL && show_all_if==1) show_all_if=2; /* get stats so all values are uptodate */ get_iface_stats(0); break; case 's': case 'S': sumhidden=!sumhidden; /* get stats so all values are uptodate */ get_iface_stats(0); break; case 'n': case 'N': do { input_method=input_method<<1; if (input_method>INPUT_MASK) input_method=1; } while (!(input_method & INPUT_MASK)); /* switched input, reset iface stats */ free(if_stats); if_stats=NULL; if_count=0; memset(&if_stats_total,0,(size_t)sizeof(t_iface_stats)); break; case 'q': case 'Q': /* we are asked to exit */ deinit(0, NULL); break; case 'd': case 'D': case 'k': case 'K': if (output_method==CURSES2_OUT) /* cycle through interfaces */ show_only_if++; else /* switch kilobyte/autoassign */ dynamic=!dynamic; break; case 'u': case 'U': if (output_method==CURSES_OUT) { if (output_unit<(!net_input_method(input_method) ? (input_method==LIBSTATDISK_IN ? 2 : 3) : 4)) output_unit++; else output_unit=1; }; break; #if EXTENDED_STATS case 't': case 'T': if (output_type #endif #include #ifdef HAVE_LINUX_TTY_H #include #else #ifdef HAVE_SYS_TTY_H #include #endif #endif /* handle key input by user in gui (curses) mode */ void handle_gui_input(char c); int init_curses(void); void sigwinch(int sig); #endif #endif bwm-ng-0.6.2/src/defines.h000066400000000000000000000200361341267030500152650ustar00rootroot00000000000000/****************************************************************************** * bwm-ng * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __HAVE_DEFINE_H #define __HAVE_DEFINE_H #include #include #include #include #include #include #include #include #include "../config.h" /* ugly defines to handle different compile time options */ #if HAVE_STRUCT_IF_MSGHDR_IFM_DATA #define SYSCTL #endif #if NETSTAT_LINUX || NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD #define NETSTAT 1 #endif #if HAVE_LIBSTATGRAB #define LIBSTATGRAB #endif #if HAVE_LIBCURSES || HAVE_LIBNCURSES #define HAVE_CURSES #endif #if HAVE_WORKING_GETIFADDRS #define GETIFADDRS #endif #if HAVE_GETOPT_LONG #define LONG_OPTIONS #endif #if HAVE_IOCTL #include #ifdef SIOCGIFFLAGS #define IOCTL #endif #endif #ifdef HAVE_CURSES #include #ifndef ACS_VLINE #define ACS_VLINE '|' #endif #ifndef ACS_HLINE #define ACS_HLINE '-' #endif #endif #ifdef LONG_OPTIONS #include #endif #if HAVE_GETTIMEOFDAY #include #include #endif #ifdef NETSTAT #if HAVE_NETSTAT_PATH #define NETSTAT_PATH HAVE_NETSTAT_PATH #else #define NETSTAT_PATH "netstat" #endif #endif #if HAVE__PROC_NET_DEV #ifdef PROC_NET_DEV_PATH #define PROC_NET_DEV PROC_NET_DEV_PATH #else #define PROC_NET_DEV "/proc/net/dev" #endif #endif #if HAVE__PROC_DISKSTATS #ifdef PROC_DISKSTATS_PATH #define PROC_DISKSTATS PROC_DISKSTATS_PATH #else #define PROC_DISKSTATS "/proc/diskstats" #endif #ifdef PROC_PARTITIONS_PATH #define PROC_PARTITIONS PROC_PARTITIONS_PATH #else #define PROC_PARTITIONS "/proc/partitions" #endif #endif /* prepare input methods */ #ifdef NETSTAT #define NETSTAT_IN 1 #define INPUT_METHODS_NETSTAT " netstat" #else #define NETSTAT_IN 0 #define INPUT_METHODS_NETSTAT #endif #ifdef PROC_NET_DEV #define PROC_IN 2 #define INPUT_METHODS_PROC " proc" #else #define PROC_IN 0 #define INPUT_METHODS_PROC #endif #ifdef GETIFADDRS #define GETIFADDRS_IN 4 #define INPUT_METHODS_GETIFADDRS " getifaddrs" #else #define GETIFADDRS_IN 0 #define INPUT_METHODS_GETIFADDRS #endif #ifdef LIBSTATGRAB #define LIBSTAT_IN 8 #define LIBSTATDISK_IN 256 #define INPUT_METHODS_LIBSTATGRAB " libstatgrab" #define INPUT_METHODS_LIBSTATDISK " libstatdisk" #else #define LIBSTAT_IN 0 #define INPUT_METHODS_LIBSTATGRAB #define LIBSTATDISK_IN 0 #define INPUT_METHODS_LIBSTATDISK #endif #ifdef SYSCTL #define SYSCTL_IN 16 #define INPUT_METHODS_SYSCTL " sysctl" #else #define SYSCTL_IN 0 #define INPUT_METHODS_SYSCTL #endif #if defined(HAVE_STRUCT_DISKSTATS) || defined(HAVE_STRUCT_DISK_SYSCTL) #define SYSCTLDISK_IN 1024 #define INPUT_METHODS_SYSCTLDISK " sysctldisk" #else #define SYSCTLDISK_IN 0 #define INPUT_METHODS_SYSCTLDISK #endif #if HAVE_LIBKSTAT #define KSTAT_IN 32 #define KSTATDISK_IN 512 #define INPUT_METHODS_KSTAT " kstat" #define INPUT_METHODS_KSTATDISK " kstatdisk" #else #define KSTAT_IN 0 #define KSTATDISK_IN 0 #define INPUT_METHODS_KSTAT #define INPUT_METHODS_KSTATDISK #endif #ifdef WIN32 #define WIN32_IN 64 #define INPUT_METHODS_WIN32 " win32" #else #define WIN32_IN 0 #define INPUT_METHODS_WIN32 #endif #ifdef PROC_DISKSTATS #define DISKLINUX_IN 128 #define INPUT_METHODS_DISK_LINUX " disk" #else #define DISKLINUX_IN 0 #define INPUT_METHODS_DISK_LINUX #endif #if defined(HAVE_DEVSTAT_GETDEVS) || defined(HAVE_GETDEVS) #define DEVSTAT_IN 2048 #define INPUT_METHODS_DEVSTAT " devstat" #else #define DEVSTAT_IN 0 #define INPUT_METHODS_DEVSTAT #endif #ifdef HAVE_IOSERVICE #define IOSERVICE_IN 4096 #define INPUT_METHODS_IOSERVICE " ioservice" #else #define IOSERVICE_IN 0 #define INPUT_METHODS_IOSERVICE #endif #define INPUT_MASK (NETSTAT_IN | PROC_IN | GETIFADDRS_IN | LIBSTAT_IN | SYSCTL_IN | KSTAT_IN | KSTATDISK_IN | WIN32_IN | DISKLINUX_IN | LIBSTATDISK_IN | SYSCTLDISK_IN | DEVSTAT_IN | IOSERVICE_IN) #define NET_INPUT (NETSTAT_IN | PROC_IN | GETIFADDRS_IN | LIBSTAT_IN | SYSCTL_IN | KSTAT_IN | WIN32_IN) #define INPUT_METHODS INPUT_METHODS_PROC INPUT_METHODS_GETIFADDRS INPUT_METHODS_SYSCTL INPUT_METHODS_KSTAT INPUT_METHODS_NETSTAT INPUT_METHODS_WIN32 INPUT_METHODS_LIBSTATGRAB INPUT_METHODS_DISK_LINUX INPUT_METHODS_LIBSTATDISK INPUT_METHODS_KSTATDISK INPUT_METHODS_SYSCTLDISK INPUT_METHODS_DEVSTAT INPUT_METHODS_IOSERVICE #define net_input_method(_n) (_n & NET_INPUT) /* used for this nice spinning wheel */ #define IDLE_CHARS "-\\|/" /* build output methods string: curses, plain, csv, html */ #ifdef HAVE_CURSES #define CURSES_OUTPUT_METHODS ", curses, curses2" #define CURSES_OUT 0 #define CURSES2_OUT 5 #define IDLE_CHARS2 " >--< " #else #define CURSES_OUTPUT_METHODS #endif #ifdef CSV #define CSV_OUTPUT_METHODS ", csv" #define CSV_OUT 2 #else #define CSV_OUTPUT_METHODS #endif #ifdef HTML #define HTML_OUTPUT_METHODS ", html" #define HTML_OUT 3 #else #define HTML_OUTPUT_METHODS #endif #define OUTPUT_METHODS "plain" CURSES_OUTPUT_METHODS CSV_OUTPUT_METHODS HTML_OUTPUT_METHODS #define PLAIN_OUT 1 #define PLAIN_OUT_ONCE 4 /* build short options */ #ifdef PROC_NET_DEV #define PROC_SHORT_OPT "f:" #else #define PROC_SHORT_OPT #endif #ifdef HTML #define HTML_SHORT_OPT "H:R:" #else #define HTML_SHORT_OPT #endif #if NETSTAT && NETSTAT_OPTION #define NETSTAT_SHORT_OPT "n:" #else #define NETSTAT_SHORT_OPT #endif #ifdef CSV #define CSV_SHORT_OPT "C:F:" #else #define CSV_SHORT_OPT #endif #if EXTENDED_STATS #define EXTENDED_STATS_SHORT_OPT "A:T:" #else #define EXTENDED_STATS_SHORT_OPT #endif #define SHORT_OPTIONS ":ht:d:Va:u:I:i:o:c:D:S:N" EXTENDED_STATS_SHORT_OPT PROC_SHORT_OPT HTML_SHORT_OPT NETSTAT_SHORT_OPT CSV_SHORT_OPT #define BYTES_OUT 1 #define BITS_OUT 2 #define PACKETS_OUT 3 #define ERRORS_OUT 4 #define RATE_OUT 1 #if EXTENDED_STATS #define MAX_OUT 2 #define SUM_OUT 3 #define AVG_OUT 4 #define TYPE_OUT_MAX 4 #else #define TYPE_OUT_MAX 1 #endif /* default length of avg in 1/1000sec */ #define AVG_LENGTH 30000 #ifndef PATH_MAX #define PATH_MAX 4096 #endif #define WRAP_AROUND ULONG_MAX #define WRAP_32BIT 4294967295ul #ifdef SYS_64BIT #ifdef HAVE_UNSIGNED_LONG_LONG #undef WRAP_AROUND #define WRAP_AROUND 18446744073709551615ull #endif #endif #define print_version printf("Bandwidth Monitor NG (" PACKAGE_NAME ") v" VERSION "\nCopyright (C) 2004-2007 Volker Gropp <" PACKAGE_BUGREPORT ">\n"); #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif #ifndef HAVE_STRLCPY #define strlcpy(_a,_b,_c) strncpy((_a),(_b),(_c)); (_a)[(_c) - 1]='\0'; #endif #endif bwm-ng-0.6.2/src/global_vars.h000066400000000000000000000060761341267030500161530ustar00rootroot00000000000000/****************************************************************************** * bwm-ng global variables * * * * Copyright (C) 2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __GLOBAL_VARS #define __GLOBAL_VARS #ifndef EXTERN #define EXTERN extern #endif #include "defines.h" #include "types.h" EXTERN int if_count; #ifdef PROC_NET_DEV EXTERN char PROC_FILE[PATH_MAX]; #endif #ifdef PROC_DISKSTATS EXTERN char PROC_DISKSTATS_FILE[PATH_MAX]; EXTERN char PROC_PARTITIONS_FILE[PATH_MAX]; #endif #ifdef NETSTAT EXTERN char NETSTAT_FILE[PATH_MAX]; #endif EXTERN unsigned int delay; #if EXTENDED_STATS EXTERN unsigned int avg_length; #endif EXTERN char output_unit; EXTERN char output_type; EXTERN char dynamic; EXTERN char show_all_if; #ifdef HAVE_CURSES EXTERN int output_method; EXTERN WINDOW *mywin; EXTERN unsigned short cols; EXTERN unsigned short rows; EXTERN unsigned int max_rt; EXTERN unsigned int scale; EXTERN unsigned int show_only_if; #else EXTERN int output_method; #endif EXTERN char *iface_list; #ifdef CSV EXTERN char csv_char; #endif #if CSV || HTML EXTERN FILE *out_file; EXTERN char *out_file_path; #endif EXTERN int output_count; EXTERN char daemonize; EXTERN char sumhidden; EXTERN char ansi_output; EXTERN int input_method; #ifdef HTML EXTERN int html_refresh; EXTERN int html_header; #endif #ifdef IOCTL EXTERN int skfd; #endif #if IOSERVICE_IN EXTERN char long_darwin_disk_names; #endif EXTERN t_iface_stats *if_stats; /* total struct */ EXTERN t_iface_stats if_stats_total; #endif EXTERN char start_time[30];bwm-ng-0.6.2/src/help.c000066400000000000000000000153141341267030500145760ustar00rootroot00000000000000/****************************************************************************** * bwm-ng online help * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "global_vars.h" #include "help.h" static inline void print_help_line(const char *short_c,const char * long_c,const char *descr); static inline void print_help_line(const char *short_c,const char * long_c,const char *descr) { #ifdef LONG_OPTIONS printf(" %-23s",long_c); #else printf(" %-23s",short_c); #endif printf(" %s\n",descr); } /* prints a helpscreen and exists */ inline void cmdln_printhelp(void) FUNCATTR_NORETURN; inline void cmdln_printhelp() { print_version; printf("USAGE: bwm-ng [OPTION] ..."); #if CONFIG_FILE printf(" [CONFIGFILE]\n"); #else printf("\n"); #endif printf("displays current ethernet interfaces stats\n\n"); printf("Options:\n"); print_help_line("-t ","-t, --timeout ","displays stats every (1msec = 1/1000sec)"); print_help_line("","","default: 500"); print_help_line("-d","-d, --dynamic [value]","show values dynamically (Byte KB or MB)"); print_help_line("-a [mode]","-a, --allif [mode]","where mode is one of:"); print_help_line("","","0=show only up (and selected) interfaces"); print_help_line("","","1=show all up interfaces (default)"); print_help_line("","","2=show all and down interfaces"); print_help_line("-I ","-I, --interfaces ","show only interfaces in (comma separated), or"); print_help_line("","","if list is prefaced with % show all but interfaces"); print_help_line("","","in list"); print_help_line("-S","-S, --sumhidden [value]","count hidden interfaces for total"); #if EXTENDED_STATS print_help_line("-A","-A, --avglength ","sets the span of average stats (Default 30s)"); #endif print_help_line("-D","-D, --daemon [value]","fork into background and daemonize"); print_help_line("-h","-h, --help","displays this help"); print_help_line("-V","-V, --version","print version info"); printf("\nInput:\n"); print_help_line("-i ","-i, --input ","input method, one of:" INPUT_METHODS); #ifdef PROC_NET_DEV print_help_line("-f ","-f, --procfile ","filename to read raw data from. (" PROC_NET_DEV ")"); #endif #ifdef PROC_DISKSTATS print_help_line(""," --diskstatsfile ","filename to read diskstats (Linux 2.6+) from. (" PROC_DISKSTATS ")"); print_help_line(""," --partitionsfile ","filename to read diskstats (Linux 2.4) from. (" PROC_PARTITIONS ")"); #endif #if ALLOW_NETSTATPATH #ifdef NETSTAT print_help_line("-n ","-n, --netstat ","use as netstat binary"); #endif #endif printf("\nOutput:\n"); print_help_line("-o ","-o, --output ","output method, one of: "); print_help_line("","",OUTPUT_METHODS); print_help_line("-u","-u, --unit ","unit to show. one of bytes, bits, packets, errors"); #if EXTENDED_STATS print_help_line("-T","-T, --type ","type of stats. one of rate, max, sum, avg"); #endif #ifdef CSV print_help_line("-C ","-C, --csvchar ","delimiter for csv"); #endif #if CSV || HTML print_help_line("-F ","-F, --outfile ","output file for csv and html (default stdout)"); #endif #ifdef HTML print_help_line("-R ","-R, --htmlrefresh ","meta refresh for html output"); print_help_line("-H","-H, --htmlheader","show and frame for html output"); #endif print_help_line("-c ","-c, --count ","number of query/output for plain & csv"); print_help_line("-N","-N, --ansiout","disable ansi codes for plain output"); print_help_line("","","(ie 1 for one single output)"); printf("\n"); exit(EXIT_SUCCESS); } #ifdef HAVE_CURSES void print_online_help() { WINDOW *helpwin; helpwin=newwin(15,76,0,1); box(helpwin,ACS_VLINE, ACS_HLINE); mvwprintw(helpwin,0,2,"bwm-ng v" VERSION " - Keybindings:"); mvwprintw(helpwin,2,2,"'h' show this help"); mvwprintw(helpwin,3,2,"'q' exit"); mvwprintw(helpwin,4,2,"'+' increases timeout by 100ms"); mvwprintw(helpwin,5,2,"'-' decreases timeout by 100ms"); if (output_method==CURSES_OUT) mvwprintw(helpwin,6,2,"'d' switch KB and auto assign Byte/KB/MB/GB"); else mvwprintw(helpwin,6,2,"'d' cycle: show interfaces step by step"); mvwprintw(helpwin,7,2,"'a' cycle: show all interfaces, only those which are up,"); mvwprintw(helpwin,8,2," only up and not hidden"); mvwprintw(helpwin,9,2,"'s' sum hidden ifaces to total aswell or not"); mvwprintw(helpwin,10,2,"'n' cycle: input methods"); if (output_method==CURSES_OUT) { mvwprintw(helpwin,11,2,"'u' cycle: bytes,bits,packets,errors"); #if EXTENDED_STATS mvwprintw(helpwin,12,2,"'t' cycle: current rate, max, sum since start, average for last 30s"); #endif } else { #if EXTENDED_STATS mvwprintw(helpwin,11,2,"'t' cycle: current rate, max, sum since start, average for last 30s"); #endif }; mvwprintw(helpwin,14,2," press any key to continue... "); wrefresh(helpwin); timeout(-1); getch(); timeout(delay); delwin(helpwin); } #endif bwm-ng-0.6.2/src/help.h000066400000000000000000000036711341267030500146060ustar00rootroot00000000000000/****************************************************************************** * bwm-ng help header * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __HELP_H #define __HELP_H #include "defines.h" #include "types.h" #include "options.h" /* print cmdline help */ void cmdln_printhelp(void); #ifdef HAVE_CURSES void print_online_help(void); #endif #endif bwm-ng-0.6.2/src/input/000077500000000000000000000000001341267030500146355ustar00rootroot00000000000000bwm-ng-0.6.2/src/input/devstat.c000066400000000000000000000074601341267030500164620ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "devstat.h" #if DEVSTAT_IN #ifndef HAVE_DEVSTAT_GETDEVS #define devstat_getdevs(_n,_m) getdevs(_m) #define devstat_selectdevs selectdevs #endif void get_iface_stats_devstat (char verbose) { int current_if_num=0,hidden_if=0; struct statinfo dev_stats; struct device_selection *dev_sel = NULL; int n_selected, n_selections; long sel_gen; struct devstat *dev_ptr; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ if (!(dev_stats.dinfo=malloc(sizeof(struct devinfo)))) deinit(1,"malloc failure\n"); bzero(dev_stats.dinfo, sizeof(struct devinfo)); if ((devstat_getdevs(NULL, (struct statinfo *)&dev_stats)) < 0) { free(dev_stats.dinfo); deinit(1,"getdevs failed: %s\n",devstat_errbuf); } if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, dev_stats.dinfo->generation, dev_stats.dinfo->devices, dev_stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, dev_stats.dinfo->numdevs, 1) < 0) { free(dev_stats.dinfo); deinit(1,"selectdevs failed: %s\n",devstat_errbuf); } for(current_if_num=0;current_if_numnumdevs;current_if_num++){ dev_ptr=&dev_stats.dinfo->devices[dev_sel[current_if_num].position]; #ifdef HAVE_STRUCT_DEVSTAT_BYTES_READ tmp_if_stats.bytes.in=dev_ptr->bytes_read; tmp_if_stats.bytes.out=dev_ptr->bytes_written; tmp_if_stats.packets.in=dev_ptr->num_read; tmp_if_stats.packets.out=dev_ptr->num_written; #else tmp_if_stats.bytes.in=dev_ptr->bytes[DEVSTAT_READ]; tmp_if_stats.bytes.out=dev_ptr->bytes[DEVSTAT_WRITE]; tmp_if_stats.packets.in=dev_ptr->operations[DEVSTAT_READ]; tmp_if_stats.packets.out=dev_ptr->operations[DEVSTAT_WRITE]; #endif tmp_if_stats.errors.in = tmp_if_stats.errors.out = 0; hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, dev_ptr->device_name, current_if_num, verbose,(tmp_if_stats.bytes.in != 0 || tmp_if_stats.bytes.out != 0)); } finish_iface_stats (verbose, stats, hidden_if,current_if_num); free(dev_stats.dinfo); return; } #endif bwm-ng-0.6.2/src/input/devstat.h000066400000000000000000000036351341267030500164670ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __DEVSTAT_H #define __DEVSTAT_H #include "retrieve.h" #if DEVSTAT_IN #include #include void get_iface_stats_devstat (char verbose); #endif #endif bwm-ng-0.6.2/src/input/getifaddrs.c000066400000000000000000000074541341267030500171270ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "getifaddrs.h" #ifdef GETIFADDRS /* do the actual work, get and print stats if verbose */ void get_iface_stats_getifaddrs (char verbose) { char *name=NULL; struct ifaddrs *net, *net_ptr=NULL; struct if_data *net_data; int hidden_if=0,current_if_num=0; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ /* dont open proc_net_dev if netstat_i is requested, else try to open and if it fails fallback */ if (getifaddrs(&net) != 0) { deinit(1, "getifaddr failed: %s\n",strerror(errno)); } net_ptr=net; /* loop either while netstat enabled and still lines to read * or still buffer (buf) left */ while (net_ptr!=NULL) { /* move getifaddr data to my struct */ if (net_ptr->ifa_addr==NULL || net_ptr->ifa_addr->sa_family != AF_LINK) { net_ptr=net_ptr->ifa_next; continue; } if (net_ptr->ifa_name!=NULL) name=strdup(net_ptr->ifa_name); else name=strdup(""); if (net_ptr->ifa_data!=NULL) { net_data=(struct if_data *)net_ptr->ifa_data; tmp_if_stats.bytes.in=net_data->ifi_ibytes; tmp_if_stats.bytes.out=net_data->ifi_obytes; tmp_if_stats.packets.in=net_data->ifi_ipackets; tmp_if_stats.packets.out=net_data->ifi_opackets; tmp_if_stats.errors.in=net_data->ifi_ierrors; tmp_if_stats.errors.out=net_data->ifi_oerrors; } else { net_ptr=net_ptr->ifa_next; continue; } /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose, (show_all_if || (net_ptr->ifa_flags & IFF_UP))); net_ptr=net_ptr->ifa_next; free(name); current_if_num++; } /* fgets done (while) */ /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); /* close input stream */ freeifaddrs(net); return; } #endif bwm-ng-0.6.2/src/input/getifaddrs.h000066400000000000000000000037231341267030500171270ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __GETIFADDRS_H #define __GETIFADDRS_H #include "retrieve.h" #ifdef GETIFADDRS #include #include #include #include void get_iface_stats_getifaddrs (char verbose); #endif #endif bwm-ng-0.6.2/src/input/ioservice.c000066400000000000000000000126541341267030500170010ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "ioservice.h" #if IOSERVICE_IN void get_disk_stats_ioservice (char verbose) { int current_if_num=0,hidden_if=0; io_iterator_t dlist = 0; mach_port_t port = 0; io_registry_entry_t disk = 0; CFDictionaryRef props = 0; CFDictionaryRef props2 = 0; CFDictionaryRef dstats = 0; CFNumberRef value = NULL; CFMutableDictionaryRef match; io_registry_entry_t parent; io_name_t name; char deviceFilePath[MAXPATHLEN]; //MAXPATHLEN is defined in sys/param.h CFStringRef name_str; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ if (IOMasterPort(MACH_PORT_NULL, &port)) deinit(1,"failure while initializing disk port\n"); match = IOServiceMatching("IOMedia"); CFDictionaryAddValue(match, CFSTR(kIOMediaWholeKey), kCFBooleanTrue); if (IOServiceGetMatchingServices(port, match, &dlist)!=KERN_SUCCESS) deinit(1,"failure while getting disk list\n"); while ( (disk = IOIteratorNext(dlist)) ) { IORegistryEntryCreateCFProperties (disk,(CFMutableDictionaryRef *) &props,kCFAllocatorDefault,kNilOptions); if (props) { if (!long_darwin_disk_names) { name_str = (CFStringRef)CFDictionaryGetValue(props, CFSTR(kIOBSDNameKey)); if (name_str) { CFStringGetCString(name_str, deviceFilePath, MAXPATHLEN-1, CFStringGetSystemEncoding()); } else { snprintf((char *)deviceFilePath,MAXPATHLEN-1,"unknown%i",current_if_num); deviceFilePath[MAXPATHLEN-1]=0; } } else { if (IORegistryEntryGetName(disk, name )!=KERN_SUCCESS) { snprintf((char *)name,sizeof(name)-1,"unknown%i",current_if_num); name[sizeof(name)-1]=0; } } if (IORegistryEntryGetParentEntry(disk, kIOServicePlane, &parent)!=KERN_SUCCESS) { CFRelease(props); IOObjectRelease(disk); IOIteratorReset(dlist); deinit(1,"disk has no parent\n"); } IORegistryEntryCreateCFProperties(parent, (CFMutableDictionaryRef *)&props2,kCFAllocatorDefault, kNilOptions); if (props2) { dstats = CFDictionaryGetValue(props2, CFSTR(kIOBlockStorageDriverStatisticsKey)); if (dstats) { value = CFDictionaryGetValue (dstats,CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)); if (value) CFNumberGetValue(value, kCFNumberSInt64Type, &tmp_if_stats.bytes.in); value = CFDictionaryGetValue (dstats,CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)); if (value) CFNumberGetValue(value, kCFNumberSInt64Type, &tmp_if_stats.bytes.out); value = CFDictionaryGetValue (dstats,CFSTR(kIOBlockStorageDriverStatisticsReadsKey)); if (value) CFNumberGetValue(value, kCFNumberSInt64Type, &tmp_if_stats.packets.in); value = CFDictionaryGetValue (dstats,CFSTR(kIOBlockStorageDriverStatisticsWritesKey)); if (value) CFNumberGetValue(value, kCFNumberSInt64Type, &tmp_if_stats.packets.out); value = CFDictionaryGetValue (dstats,CFSTR(kIOBlockStorageDriverStatisticsReadErrorsKey)); if (value) CFNumberGetValue(value, kCFNumberSInt64Type, &tmp_if_stats.errors.in); value = CFDictionaryGetValue (dstats,CFSTR(kIOBlockStorageDriverStatisticsWriteErrorsKey)); if (value) CFNumberGetValue(value, kCFNumberSInt64Type, &tmp_if_stats.errors.out); hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, long_darwin_disk_names ? (char *)name : deviceFilePath , current_if_num, verbose,(tmp_if_stats.bytes.in != 0 || tmp_if_stats.bytes.out != 0)); current_if_num++; } CFRelease(props2); } IOObjectRelease(parent); CFRelease(props); props = 0; } IOObjectRelease(disk); disk = 0; } finish_iface_stats (verbose, stats, hidden_if,current_if_num); IOObjectRelease(dlist); } #endif bwm-ng-0.6.2/src/input/ioservice.h000066400000000000000000000041411341267030500167760ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __IOSERVICE_H #define __IOSERVICE_H #include "retrieve.h" #if IOSERVICE_IN #include #include #include #include #ifndef LONG_DARWIN_DEV_NAMES #include #include #endif void get_disk_stats_ioservice (char verbose); #endif #endif bwm-ng-0.6.2/src/input/libkstat.c000066400000000000000000000111471341267030500166220ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "libkstat.h" #if HAVE_LIBKSTAT void get_iface_stats_kstat (char verbose) { kstat_ctl_t *kc; kstat_t *ksp; kstat_io_t kio; kstat_named_t *i_bytes=NULL,*o_bytes=NULL,*i_packets=NULL,*o_packets=NULL,*i_errors=NULL,*o_errors=NULL; char *name; int hidden_if=0,current_if_num=0,my_errno=0; t_iface_speed_stats tmp_if_stats; t_iface_speed_stats stats; /* local struct, used to calc total values */ memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ kc = kstat_open(); if (kc==NULL) deinit(1, "kstat failed: %s\n",strerror(my_errno)); name=(char *)malloc(KSTAT_STRLEN); if (!name) { kstat_close(kc); deinit(1,"mem alloc failed: %s\n",strerror(errno)); } /* loop for interfaces */ for (ksp = kc->kc_chain;ksp != NULL;ksp = ksp->ks_next) { if ((strcmp(ksp->ks_class, "net") != 0 && input_method==KSTAT_IN) || (strcmp(ksp->ks_class, "disk") != 0 && input_method==KSTATDISK_IN && ksp->ks_type != KSTAT_TYPE_IO)) continue; /* skip all other stats */ strncpy(name,ksp->ks_name,KSTAT_STRLEN); name[KSTAT_STRLEN-1]='\0'; if (KSTAT_IN==input_method) { kstat_read(kc, ksp, NULL); i_bytes=(kstat_named_t *)kstat_data_lookup(ksp, "rbytes"); o_bytes=(kstat_named_t *)kstat_data_lookup(ksp, "obytes"); i_packets=(kstat_named_t *)kstat_data_lookup(ksp, "ipackets"); o_packets=(kstat_named_t *)kstat_data_lookup(ksp, "opackets"); i_errors=(kstat_named_t *)kstat_data_lookup(ksp, "ierrors"); o_errors=(kstat_named_t *)kstat_data_lookup(ksp, "oerrors"); if (!i_bytes || !o_bytes || !i_packets || !o_packets || !i_errors || !o_errors) continue; /* use ui32 values, the 64 bit values return strange (very big) differences */ tmp_if_stats.bytes.in=i_bytes->value.ui32; tmp_if_stats.bytes.out=o_bytes->value.ui32; tmp_if_stats.packets.in=i_packets->value.ui32; tmp_if_stats.packets.out=o_packets->value.ui32; tmp_if_stats.errors.in=i_errors->value.ui32; tmp_if_stats.errors.out=o_errors->value.ui32; } else if (KSTATDISK_IN==input_method) { kstat_read(kc, ksp, &kio); tmp_if_stats.bytes.in=kio.nread; tmp_if_stats.bytes.out=kio.nwritten; tmp_if_stats.packets.in=kio.reads; tmp_if_stats.packets.out=kio.writes; tmp_if_stats.errors.in=tmp_if_stats.errors.out=0; } else { free(name); kstat_close(kc); deinit(1,"im confused about kstat input methods!\n"); } /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose, (tmp_if_stats.bytes.in != 0 || tmp_if_stats.bytes.out != 0)); current_if_num++; } /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); /* clean buffers */ free(name); kstat_close(kc); return; } #endif bwm-ng-0.6.2/src/input/libkstat.h000066400000000000000000000036071341267030500166310ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __LIBKSTAT_H #define __LIBKSTAT_H #include "retrieve.h" #ifdef HAVE_LIBKSTAT #include void get_iface_stats_kstat (char verbose); #endif #endif bwm-ng-0.6.2/src/input/libstatgrab.c000066400000000000000000000077261341267030500173130ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "libstatgrab.h" #ifdef LIBSTATGRAB /* do the actual work, get and print stats if verbose */ void get_iface_stats_libstat (char verbose) { sg_network_io_stats *network_stats=NULL; size_t num_network_stats; int current_if_num=0,hidden_if=0; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ network_stats = sg_get_network_io_stats(&num_network_stats); if (network_stats == NULL){ deinit(1, "libstatgrab error!\n"); } for (current_if_num=0;current_if_numrx; tmp_if_stats.bytes.out=network_stats->tx; tmp_if_stats.packets.in=network_stats->ipackets; tmp_if_stats.packets.out=network_stats->opackets; tmp_if_stats.errors.in=network_stats->ierrors; tmp_if_stats.errors.out=network_stats->oerrors; hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, network_stats->interface_name, current_if_num, verbose #ifdef IOCTL ,check_if_up(network_stats->interface_name) #else ,1 #endif ); network_stats++; } finish_iface_stats (verbose, stats, hidden_if,current_if_num); return; } void get_iface_stats_libstatdisk (char verbose) { sg_disk_io_stats *disk_stats=NULL; size_t num_disk_stats; int current_if_num=0,hidden_if=0; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ disk_stats = sg_get_disk_io_stats(&num_disk_stats); if (disk_stats == NULL){ deinit(1, "libstatgrab error!\n"); } for (current_if_num=0;current_if_numread_bytes; tmp_if_stats.bytes.out=disk_stats->write_bytes; tmp_if_stats.packets.in=0; tmp_if_stats.packets.out=0; tmp_if_stats.errors.in=0; tmp_if_stats.errors.out=0; hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, disk_stats->disk_name, current_if_num, verbose,1); disk_stats++; } finish_iface_stats (verbose, stats, hidden_if,current_if_num); return; } #endif bwm-ng-0.6.2/src/input/libstatgrab.h000066400000000000000000000037011341267030500173050ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __LIBSTATGRAB_H #define __LIBSTATGRAB_H #include "retrieve.h" #ifdef LIBSTATGRAB #include void get_iface_stats_libstat (char verbose); void get_iface_stats_libstatdisk (char verbose); #endif #endif bwm-ng-0.6.2/src/input/netstat.c000066400000000000000000000167511341267030500164750ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "netstat.h" #if NETSTAT_BSD || NETSTAT_SOLARIS || NETSTAT_BSD_BYTES || NETSTAT_NETBSD /* counts the tokens in a string */ long count_tokens(char *in_str) { long tokens=0; long i=0; char in_a_token=0; char *str; if (in_str==NULL) return 0; str=in_str; while (str[i]!='\0') { if (str[i]>32) { if (!in_a_token) { tokens++; in_a_token=1; } } else { if (in_a_token) in_a_token=0; } i++; } return tokens; } #endif #ifdef NETSTAT /* do the actual work, get and print stats if verbose */ void get_iface_stats_netstat (char verbose) { int current_if_num=0,hidden_if=0; char *buffer=NULL,*name=NULL; #if NETSTAT_NETBSD char *str_buf=NULL; char *test_buf; char *buffer2=NULL; FILE *f2=NULL; #endif #if NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD char *last_name=NULL; #endif FILE *f=NULL; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ if (!(f=(FILE *)popen( #if NETSTAT_BSD || NETSTAT_BSD_BYTES #if NETSTAT_BSD_LINK NETSTAT_PATH " -iW -f link" #else NETSTAT_PATH " -iW" #endif #if NETSTAT_BSD_BYTES " -b" #endif #endif #if NETSTAT_LINUX show_all_if ? NETSTAT_PATH " -ia" : NETSTAT_PATH " -i" #endif #if NETSTAT_SOLARIS NETSTAT_PATH " -i -f inet -f inet6" #endif #if NETSTAT_NETBSD NETSTAT_PATH " -ib" #endif ,"r"))) deinit(1, "no input stream found: %s\n",strerror(errno)); #if NETSTAT_NETBSD if (!(f2=popen( NETSTAT_PATH " -i","r"))) deinit(1, "no input stream found: %s\n",strerror(errno)); buffer2=(char *)malloc(MAX_LINE_BUFFER); if ((fgets(buffer2,MAX_LINE_BUFFER,f2) == NULL )) deinit(1, "read of netstat failed: %s\n",strerror(errno)); str_buf=(char *)malloc(MAX_LINE_BUFFER); #endif buffer=(char *)malloc(MAX_LINE_BUFFER); #ifdef NETSTAT_LINUX /* we skip first 2 lines if not bsd at any mode */ if ((fgets(buffer,MAX_LINE_BUFFER,f) == NULL ) || (fgets(buffer,MAX_LINE_BUFFER,f) == NULL )) deinit(1, "read of netstat failed: %s\n",strerror(errno)); #endif #if NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD last_name=(char *)malloc(MAX_LINE_BUFFER); last_name[0]='\0'; /* init */ if ((fgets(buffer,MAX_LINE_BUFFER,f) == NULL )) deinit(1, "read of netstat failed: %s\n",strerror(errno)); #endif name=(char *)malloc(MAX_LINE_BUFFER); /* loop and read each line */ while ( (fgets(buffer,MAX_LINE_BUFFER,f) != NULL && buffer[0]!='\n') ) { memset(&tmp_if_stats,0,(size_t)sizeof(t_iface_speed_stats)); /* reinit it to zero */ #ifdef NETSTAT_LINUX sscanf(buffer,"%s%*i%*i%llu%llu%*i%*i%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out); #endif #if NETSTAT_BSD_BYTES if (count_tokens(buffer)>10) /* including address */ sscanf(buffer,"%s%*i%*s%*s%llu%llu%llu%llu%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.bytes.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out,&tmp_if_stats.bytes.out); else /* w/o address */ sscanf(buffer,"%s%*i%*s%llu%llu%llu%llu%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.bytes.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out,&tmp_if_stats.bytes.out); #endif #if NETSTAT_BSD || NETSTAT_SOLARIS if (count_tokens(buffer)>=8) /* including address */ sscanf(buffer,"%s%*i%*s%*s%llu%llu%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out); else /* w/o address */ sscanf(buffer,"%s%*i%*s%llu%llu%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out); #endif #if NETSTAT_NETBSD test_buf=fgets(buffer2,MAX_LINE_BUFFER,f2); if (count_tokens(buffer)>=6) { /* including address */ if (test_buf) sscanf(buffer2,"%s%s%s%s%llu%llu%llu%llu",str_buf,str_buf,str_buf,str_buf,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out); sscanf(buffer,"%s%s%s%s%llu%llu",name,str_buf,str_buf,str_buf,&tmp_if_stats.bytes.in,&tmp_if_stats.bytes.out); } else { if (test_buf) sscanf(buffer2,"%s%s%s%llu%llu%llu%llu",str_buf,str_buf,str_buf,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out); sscanf(buffer,"%s%s%s%llu%llu",name,str_buf,str_buf,&tmp_if_stats.bytes.in,&tmp_if_stats.bytes.out); } #endif #if NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD /* check if we have a new iface or if its only a second line of the same one */ if (!strcmp(last_name,name)) continue; /* skip this line */ strlcpy(last_name,name,MAX_LINE_BUFFER); #endif /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose, #if NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_NETBSD (name[strlen(name)-1]!='*') #else 1 #endif ); current_if_num++; } /* fgets done (while) */ /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); /* clean buffers */ free(buffer); #if NETSTAT_NETBSD free(buffer2); free(str_buf); pclose(f2); #endif #if NETSTAT_BSD || NETSTAT_NETBSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS free(last_name); #endif free(name); /* close input stream */ pclose(f); return; } #endif bwm-ng-0.6.2/src/input/netstat.h000066400000000000000000000035551341267030500165000ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __NETSTAT_H #define __NETSTAT_H #include "retrieve.h" #ifdef NETSTAT void get_iface_stats_netstat (char verbose); #endif #endif bwm-ng-0.6.2/src/input/proc_diskstats.c000066400000000000000000000160561341267030500200450ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "proc_diskstats.h" #ifdef PROC_DISKSTATS int get_short_devfs_name(char *devicename); /* convert devfs name to a short abr - some ugly code * return: 1 on success, -1 on nothing to be done, 0 on failure */ int get_short_devfs_name(char *devicename) { char *short_devicename=NULL; char *ptr=NULL; if ((ptr=strchr(devicename,'/'))) { if (!(short_devicename=(char *)malloc(MAX_LINE_BUFFER))) return 0; strncpy(short_devicename,devicename,(int)(ptr-devicename)); short_devicename[(int)(ptr-devicename)]=0; while ((ptr=strchr(ptr,'/'))) { ptr++; strncat(short_devicename,&ptr[0],1); while (tolower(ptr[0])>='a' && tolower(ptr[0])<='z') ptr++; while (ptr[0]>='0' && ptr[0]<='9') { strncat(short_devicename,&ptr[0],1); ptr++; } } strcpy(devicename,short_devicename); free(short_devicename); return 1; } return -1; } /* do the actual work, get and print stats if verbose */ void get_disk_stats_proc (char verbose) { FILE *f=NULL,*f_s=NULL; char *buffer=NULL,*name=NULL,*ptr; ullong tmp_long; int n,major,minor,maj_s,min_s; static char diskstats_works = 1; static char proc_stat[PATH_MAX] = ""; int hidden_if=0,current_if_num=0; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ /* dont open proc_net_dev if netstat_i is requested, else try to open and if it fails fallback */ if (diskstats_works && !(f=fopen(PROC_DISKSTATS_FILE,"r"))) { diskstats_works = 0; } buffer=(char *)malloc(MAX_LINE_BUFFER); name=(char *)malloc(MAX_LINE_BUFFER); if (!name || !buffer) { if (name) free(name); if (buffer) free(buffer); if (f) fclose(f); deinit(1,"mem alloc failed: %s\n",strerror(errno)); } if (!diskstats_works) { if (!(f=fopen(PROC_PARTITIONS_FILE,"r"))) { diskstats_works = 1; } else { /* skip first two lines in /proc/partitions */ if (fgets(buffer,MAX_LINE_BUFFER,f) && fgets(buffer,MAX_LINE_BUFFER,f)) { /* read correctly */ ; } else { /* error or EOF while reading file, either way we can't continue */ deinit(1, "reading %s failed, or file was too short: %s\n", PROC_PARTITIONS_FILE, strerror(errno)); } } } while ( (fgets(buffer,MAX_LINE_BUFFER,f) != NULL) ) { n = sscanf(buffer, (diskstats_works ? "%i %i %s %llu%llu%llu%llu%llu%llu%llu%*i" : "%i %i %*i %s %llu%llu%llu%llu%llu%llu%llu%*i"), &major,&minor,name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.bytes.in,&tmp_long,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out,&tmp_if_stats.bytes.out); /* skip loop devices, we dont see stats anyway */ if (major == 7) continue; if (n == 7) { /* its a partition with shorter stats, move all to correct fields */ tmp_if_stats.packets.out=tmp_if_stats.bytes.in; tmp_if_stats.bytes.in=tmp_if_stats.errors.in; tmp_if_stats.bytes.out=tmp_long; tmp_if_stats.errors.in=0; tmp_if_stats.errors.out=0; } else { /* having 10 fields all is just fine, else check for other formats */ if (n != 10) { if (diskstats_works == 0 && n == 3) { /* we are reading /proc/partitions and have the * old 2.4 partitions format, look in /proc/stat for block devince data */ if (proc_stat[0] == 0) { /* build /proc/stat path */ strcpy(proc_stat,PROC_PARTITIONS_FILE); if ((ptr=strrchr(proc_stat,'/'))) { ptr++; strcpy(ptr,"stat"); } else { free(name); free(buffer); deinit(1, "strange /proc/partitions name, couldnt build /proc/stats name\n"); } } if (!(f_s=fopen(proc_stat,"r"))) { free(name); free(buffer); deinit(1, "couldnt open %s: %s\n",proc_stat,strerror(errno)); } while ( (fgets(buffer,MAX_LINE_BUFFER,f_s) != NULL)) { if (!strncmp("disk_io:",buffer,8)) { ptr=buffer+9; while (ptr[0]!=0) { n = sscanf(ptr,"(%i,%i): (%*i,%llu,%llu,%llu,%llu)",&maj_s,&min_s,&tmp_if_stats.packets.in,&tmp_if_stats.bytes.in,&tmp_if_stats.packets.out,&tmp_if_stats.bytes.out); if (maj_s==major && min_s==minor) { /* we found the correct device */ fclose(f_s); f_s=NULL; break; } if (!(ptr=strchr(ptr,' '))) break; ptr++; } if (!f_s) break; } } if (f_s) { fclose(f_s); /* couldnt find the entry, prolly a partition */ continue; } } else { /* neither new nor old /proc/partitions nor /proc/diskstats */ free(name); free(buffer); deinit(1, "wrong format of procfile. %i: %s\n",n,buffer); } } } /* stats are in 512 byte blocks */ tmp_if_stats.bytes.in*=512; tmp_if_stats.bytes.out*=512; /* convert devfs name to a short abr */ get_short_devfs_name(name); /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose,(n==10 || proc_stat[0] != 0)); current_if_num++; } /* fgets done (while) */ /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); /* clean buffers */ free(buffer); free(name); /* close input stream */ fclose(f); return; } #endif bwm-ng-0.6.2/src/input/proc_diskstats.h000066400000000000000000000036261341267030500200510ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __PROC_DISKSTATS_H #define __PROC_DISKSTATS_H #include "retrieve.h" #ifdef PROC_DISKSTATS #define LOOP_MAJOR 7 void get_disk_stats_proc (char verbose); #endif #endif bwm-ng-0.6.2/src/input/proc_net_dev.c000066400000000000000000000073011341267030500174510ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "proc_net_dev.h" #ifdef PROC_NET_DEV /* do the actual work, get and print stats if verbose */ void get_iface_stats_proc (char verbose) { char *ptr; FILE *f=NULL; char *buffer=NULL,*name=NULL; int hidden_if=0,current_if_num=0; t_iface_speed_stats stats; /* local struct, used to calc total values */ t_iface_speed_stats tmp_if_stats; memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ /* dont open proc_net_dev if netstat_i is requested, else try to open and if it fails fallback */ if (!(f=fopen(PROC_FILE,"r"))) { deinit(1, "open of procfile failed: %s\n",strerror(errno)); } buffer=(char *)malloc(MAX_LINE_BUFFER); /* we skip first 2 lines if not bsd at any mode */ if ((fgets(buffer,MAX_LINE_BUFFER,f) == NULL ) || (fgets(buffer,MAX_LINE_BUFFER,f) == NULL )) deinit(1, "read of proc failed: %s\n",strerror(errno)); name=(char *)malloc(MAX_LINE_BUFFER); while ( (fgets(buffer,MAX_LINE_BUFFER,f) != NULL) ) { /* get the name */ ptr=strchr(buffer,':'); /* wrong format */ if (ptr==NULL) { deinit(1, "wrong format of input stream\n"); } /* set : to end_of_string and move to first char of "next" string (to first data) */ *ptr++ = 0; sscanf(ptr,"%llu%llu%llu%*i%*i%*i%*i%*i%llu%llu%llu",&tmp_if_stats.bytes.in,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.bytes.out,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out); sscanf(buffer,"%s",name); /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose #ifdef IOCTL ,check_if_up(name) #else ,1 #endif ); current_if_num++; } /* fgets done (while) */ /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); /* clean buffers */ free(buffer); free(name); /* close input stream */ fclose(f); return; } #endif bwm-ng-0.6.2/src/input/proc_net_dev.h000066400000000000000000000035711341267030500174630ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __PROC_NET_DEV_H #define __PROC_NET_DEV_H #include "retrieve.h" #ifdef PROC_NET_DEV void get_iface_stats_proc (char verbose); #endif #endif bwm-ng-0.6.2/src/input/retrieve.c000066400000000000000000000074151341267030500166350ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "retrieve.h" #ifdef IOCTL /* test whether the iface is up or not */ char check_if_up(char *ifname) { struct ifreq ifr; /* check if we already opened the file descriptor * if not open it now */ if (skfd < 0) { if ((skfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { deinit(1, "socket error: %s\n",strerror(errno)); } } /* setup the struct */ strncpy(ifr.ifr_name, ifname,sizeof(ifr.ifr_name)); ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0'; /* lookup the status */ if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) { return 0; /* return if as down if there was an error */ } /* check against IFF_UP and return */ return (ifr.ifr_flags & IFF_UP); } #endif /* chooses the correct get_iface_stats() to use */ void get_iface_stats(char _n) { switch (input_method) { #ifdef NETSTAT case NETSTAT_IN: get_iface_stats_netstat(_n); break; #endif #ifdef LIBSTATGRAB case LIBSTAT_IN: get_iface_stats_libstat(_n); break; case LIBSTATDISK_IN: get_iface_stats_libstatdisk(_n); break; #endif #ifdef PROC_NET_DEV case PROC_IN: get_iface_stats_proc(_n); break; #endif #ifdef GETIFADDRS case GETIFADDRS_IN: get_iface_stats_getifaddrs(_n); break; #endif #if DEVSTAT_IN case DEVSTAT_IN: get_iface_stats_devstat(_n); break; #endif #ifdef SYSCTL case SYSCTL_IN: get_iface_stats_sysctl(_n); break; #endif #if SYSCTLDISK_IN case SYSCTLDISK_IN: get_iface_stats_sysctldisk(_n); break; #endif #if HAVE_LIBKSTAT case KSTATDISK_IN: case KSTAT_IN: get_iface_stats_kstat(_n); break; #endif #ifdef WIN32 case WIN32_IN: get_iface_stats_win32(_n); break; #endif #ifdef PROC_DISKSTATS case DISKLINUX_IN: get_disk_stats_proc(_n); break; #endif #if IOSERVICE_IN case IOSERVICE_IN: get_disk_stats_ioservice(_n); break; #endif } } bwm-ng-0.6.2/src/input/retrieve.h000066400000000000000000000046571341267030500166470ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __RETRIEVE_H #define __RETRIEVE_H #include "../global_vars.h" #include "../defines.h" #include "../types.h" #include "../process.h" #include "../bwm-ng.h" #ifdef IOCTL /* following only for check_if_up and ioctl */ #include #include #include #ifdef HAVE_LINUX_IF_H #include #else #include #endif char check_if_up(char *ifname); #endif #define MAX_LINE_BUFFER 1024 #include "devstat.h" #include "ioservice.h" #include "getifaddrs.h" #include "libkstat.h" #include "libstatgrab.h" #include "netstat.h" #include "proc_diskstats.h" #include "proc_net_dev.h" #include "sysctl.h" #include "win32.h" void get_iface_stats(char _n); #endif bwm-ng-0.6.2/src/input/sysctl.c000066400000000000000000000217711341267030500163320ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "sysctl.h" #ifdef SYSCTL /* do the actual work, get and print stats if verbose */ void get_iface_stats_sysctl (char verbose) { size_t size; int mib[] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; char *bsd_if_buf=NULL, *next=NULL, *lim=NULL; char iface_is_up=0; struct if_msghdr *ifmhdr, *nextifmhdr; struct sockaddr_dl *saddr; char *name=NULL; int hidden_if=0,current_if_num=0,my_errno=0; t_iface_speed_stats tmp_if_stats; t_iface_speed_stats stats; /* local struct, used to calc total values */ memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) deinit(1, "sysctl failed: %s\n",strerror(errno)); if (!(bsd_if_buf = malloc(size))) deinit(1, "no memory: %s\n",strerror(errno)); memset(bsd_if_buf,0,size); if (sysctl(mib, 6, bsd_if_buf, &size, NULL, 0) < 0) { my_errno=errno; free(bsd_if_buf); deinit(1, "sysctl failed: %s\n",strerror(my_errno)); } lim = (bsd_if_buf + size); next = bsd_if_buf; /* loop either while netstat enabled and still lines to read * or still buffer (buf) left */ while (next < (bsd_if_buf + size)) { /* BSD sysctl code */ ifmhdr = (struct if_msghdr *) next; if (ifmhdr->ifm_type != RTM_IFINFO) break; next += ifmhdr->ifm_msglen; while (next < lim) { nextifmhdr = (struct if_msghdr *) next; if (nextifmhdr->ifm_type != RTM_NEWADDR) break; next += nextifmhdr->ifm_msglen; } saddr = (struct sockaddr_dl *) (ifmhdr + 1); if(saddr->sdl_family != AF_LINK) continue; iface_is_up= (show_all_if || (ifmhdr->ifm_flags & IFF_UP)); /* we have to copy here to use saddr->sdl_nlen */ name=(char *)malloc(saddr->sdl_nlen+1); if (!name) { deinit(1,"mem alloc failed: %s\n",strerror(errno)); } strncpy(name,saddr->sdl_data,saddr->sdl_nlen); name[saddr->sdl_nlen]='\0'; tmp_if_stats.bytes.in=ifmhdr->ifm_data.ifi_ibytes; tmp_if_stats.bytes.out=ifmhdr->ifm_data.ifi_obytes; tmp_if_stats.packets.in=ifmhdr->ifm_data.ifi_ipackets; tmp_if_stats.packets.out=ifmhdr->ifm_data.ifi_opackets; tmp_if_stats.errors.in=ifmhdr->ifm_data.ifi_ierrors; tmp_if_stats.errors.out=ifmhdr->ifm_data.ifi_oerrors; /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose, iface_is_up); free(name); current_if_num++; } /* fgets done (while) */ /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); /* close input stream */ free(bsd_if_buf); return; } #endif #if SYSCTLDISK_IN #ifdef HAVE_STRUCT_SYSCTL #define MIBCOUNT 3 #else #define MIBCOUNT 2 #endif void get_iface_stats_sysctldisk (char verbose) { size_t size; int mib[MIBCOUNT]; #if defined(HW_DISKCOUNT) && !defined(HAVE_STRUCT_DISKSTATS_DS_NAME) && defined(HAVE_STRUCT_DISKSTATS) int diskcount = 0; char *name_str = NULL; char **name_arr = NULL; char *ptr = NULL; #endif #if defined(HAVE_STRUCT_DISKSTATS) #define DISK_STRUCT struct diskstats #elif defined(HAVE_STRUCT_DISK_SYSCTL) #define DISK_STRUCT struct disk_sysctl #endif DISK_STRUCT *dstats = NULL; int num,i; char *name=NULL; char free_name=0; int hidden_if=0,current_if_num=0; t_iface_speed_stats tmp_if_stats; t_iface_speed_stats stats; /* local struct, used to calc total values */ memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ mib[0]=CTL_HW; /* get name list on systems without dk_name */ #if defined(HW_DISKCOUNT) && !defined(HAVE_STRUCT_DISKSTATS_DS_NAME) && defined(HAVE_STRUCT_DISKSTATS) mib[1]=HW_DISKCOUNT; if (sysctl(mib, 2, &diskcount, &size, NULL, 0) < 0) deinit(1, "sysctl failed: %s\n",strerror(errno)); mib[1]=HW_DISKNAMES; if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) deinit(1, "sysctl failed: %s\n",strerror(errno)); if (!(name_str=(char *)malloc(size))) deinit(1, "malloc failed for name_str: %s\n",strerror(errno)); if (sysctl(mib, 2, name_str, &size, NULL, 0) < 0) { free(name_str); deinit(1, "malloc failed for name_str: %s\n",strerror(errno)); } /* assume comma seperated list as on OpenBSD */ if (!(name_arr = (char **)malloc(diskcount * sizeof(char *)))) { free(name_str); deinit(1, "malloc failed for name_arr: %s\n",strerror(errno)); } ptr = name_str; i = 0; while (i #include #include #endif #include /* netbsd fix */ #include #ifdef SYSCTL #include #include void get_iface_stats_sysctl (char verbose); #endif #ifdef HAVE_SYS_DISK_H #include #endif #if SYSCTLDISK_IN void get_iface_stats_sysctldisk (char verbose); #endif #endif #endif bwm-ng-0.6.2/src/input/win32.c000066400000000000000000000067501341267030500157530ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrieve stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "win32.h" #ifdef WIN32 void get_iface_stats_win32 (char verbose) { PMIB_IFTABLE if_table,tmp; unsigned long tableSize; int i,current_if_num,hidden_if=0,err; char name[MAX_INTERFACE_NAME_LEN]; t_iface_speed_stats tmp_if_stats; t_iface_speed_stats stats; /* local struct, used to calc total values */ memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */ tableSize=sizeof(MIB_IFTABLE); if_table = malloc(sizeof(MIB_IFTABLE)); if (if_table==NULL) return; /* get table size or data if table is big enough */ if ((err=GetIfTable(if_table, &tableSize, 0)==ERROR_INSUFFICIENT_BUFFER)) { tmp = realloc(if_table, tableSize); if (tmp==NULL) { free(if_table); return; } if_table=tmp; /* get data */ err=GetIfTable(if_table, &tableSize, 0); } if (err != NO_ERROR) { free(if_table); return; } current_if_num=0; for (i=0; idwNumEntries; i++) { strncpy(name,(char*)(if_table->table[i].bDescr),MAX_INTERFACE_NAME_LEN); name[MAX_INTERFACE_NAME_LEN-1]='\0'; tmp_if_stats.bytes.in=if_table->table[i].dwInOctets; tmp_if_stats.bytes.out=if_table->table[i].dwOutOctets; tmp_if_stats.packets.in=if_table->table[i].dwInUcastPkts + if_table->table[i].dwInNUcastPkts; tmp_if_stats.packets.out=if_table->table[i].dwOutUcastPkts + if_table->table[i].dwOutNUcastPkts; tmp_if_stats.errors.in=if_table->table[i].dwInErrors; tmp_if_stats.errors.out=if_table->table[i].dwOutErrors; /* init new interfaces and add fetched data to old or new one */ hidden_if = process_if_data (hidden_if, tmp_if_stats, &stats, name, current_if_num, verbose, 1); current_if_num++; } /* add to total stats and output current stats if verbose */ finish_iface_stats (verbose, stats, hidden_if,current_if_num); free(if_table); return; } #endif bwm-ng-0.6.2/src/input/win32.h000066400000000000000000000036221341267030500157530ustar00rootroot00000000000000/****************************************************************************** * bwm-ng parsing and retrive stuff * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __WIN32_H #define __WIN32_H #include "retrieve.h" #ifdef WIN32 #include #include void get_iface_stats_win32 (char verbose); #endif #endif bwm-ng-0.6.2/src/options.c000066400000000000000000000374321341267030500153460ustar00rootroot00000000000000/****************************************************************************** * bwm-ng handle cmdline and config file options * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #define EXTERN #include "global_vars.h" #include "options.h" #ifdef CONFIG_FILE static char* getToken(char** str, const char* delims); char *trim_whitespace(char *str); int read_config(const char *config_file); #endif static inline int str2output_unit(char *optarg); #if EXTENDED_STATS static inline int str2output_type(char *optarg); #endif static inline int str2out_method(char *optarg); static inline int str2in_method(char *optarg); #ifdef CONFIG_FILE /****************************************************************************** * This is a replacement for strsep which is not portable (missing on Solaris). */ static char* getToken(char** str, const char* delims) { char* token; if (*str==NULL) { /* No more tokens */ return NULL; } token=*str; while (**str!='\0') { if (strchr(delims,**str)!=NULL) { **str='\0'; (*str)++; return token; } (*str)++; } /* There is no other token */ *str=NULL; return token; } /******************************************************************************/ #endif static inline int str2output_unit(char *optarg) { if (optarg) { if (!strcasecmp(optarg,"bytes")) return BYTES_OUT; if (!strcasecmp(optarg,"bits")) return BITS_OUT; if (!strcasecmp(optarg,"packets")) return PACKETS_OUT; if (!strcasecmp(optarg,"errors")) return ERRORS_OUT; } return BYTES_OUT; } #if EXTENDED_STATS static inline int str2output_type(char *optarg) { if (optarg) { if (!strcasecmp(optarg,"rate")) return RATE_OUT; if (!strcasecmp(optarg,"max")) return MAX_OUT; if (!strcasecmp(optarg,"sum")) return SUM_OUT; if (!strcasecmp(optarg,"avg")) return AVG_OUT; } return RATE_OUT; } #endif static inline int str2out_method(char *optarg) { if (optarg) { if (!strcasecmp(optarg,"plain")) return PLAIN_OUT; #ifdef HAVE_CURSES else if (!strcasecmp(optarg,"curses")) return CURSES_OUT; else if (!strcasecmp(optarg,"curses2")) return CURSES2_OUT; #endif #ifdef CSV else if (!strcasecmp(optarg,"csv")) return CSV_OUT; #endif #ifdef HTML else if (!strcasecmp(optarg,"html")) return HTML_OUT; #endif } return -1; } static inline int str2in_method(char *optarg) { if (optarg) { #ifdef PROC_NET_DEV if (!strcasecmp(optarg,"proc")) return PROC_IN; #endif #ifdef NETSTAT if (!strcasecmp(optarg,"netstat")) return NETSTAT_IN; #endif #ifdef LIBSTATGRAB if (!strcasecmp(optarg,"libstat") || !strcasecmp(optarg,"statgrab") || !strcasecmp(optarg,"libstatgrab")) return LIBSTAT_IN; if (!strcasecmp(optarg,"libstatdisk")) return LIBSTATDISK_IN; #endif #ifdef GETIFADDRS if (!strcasecmp(optarg,"getifaddrs")) return GETIFADDRS_IN; #endif #if DEVSTAT_IN if (!strcasecmp(optarg,"devstat")) return DEVSTAT_IN; #endif #ifdef SYSCTL if (!strcasecmp(optarg,"sysctl")) return SYSCTL_IN; #endif #if SYSCTLDISK_IN if (!strcasecmp(optarg,"sysctldisk")) return SYSCTLDISK_IN; #endif #ifdef PROC_DISKSTATS if (!strcasecmp(optarg,"disk")) return DISKLINUX_IN; #endif #ifdef WIN32 if (!strcasecmp(optarg,"win32")) return WIN32_IN; #endif #ifdef HAVE_LIBKSTAT if (!strcasecmp(optarg,"kstat")) return KSTAT_IN; if (!strcasecmp(optarg,"kstatdisk")) return KSTATDISK_IN; #endif #if IOSERVICE_IN if (!strcasecmp(optarg,"ioservice")) return IOSERVICE_IN; #endif } return -1; } #ifdef CONFIG_FILE char *trim_whitespace(char *str) { char *dud = str; int i; /* beginning whitespace first */ while( (int)*dud && isspace((int)*dud) ) ++dud; /* now trailing whitespace */ i = strlen(dud) - 1; while( i>=0 && isspace((int)dud[i]) ) --i; dud[i+1] = 0; return dud; } int read_config(const char *config_file) { FILE *fp; char *buffer; char *token, *value; if (config_file==NULL) return -1; if( (fp = fopen( config_file, "r" ) ) == NULL ) { return -1; } buffer = (char*)malloc( sizeof(char) * 4096 ); while( fgets( buffer, 4096, fp ) ) { value = trim_whitespace( buffer ); token = getToken( &value, "=" ); if( token == NULL ) /* ignore this line if there isn't a token/value pair */ continue; token = trim_whitespace( token ); if( strcasecmp( token, "TIMEOUT" ) == 0 ) { if (value && atol(value)>0) { delay=atol(value); } #ifdef PROC_NET_DEV } else if( strcasecmp( token, "PROCFILE" ) == 0 ) { if (value && (strlen(value)0) { html_refresh=atol(value); } } else if( strcasecmp( token, "HTMLHEADER" ) == 0 ) { if (value) html_header=value[0]=='0' ? 0 : 1; #endif } } free(buffer); fclose(fp); return 0; } #endif void get_cmdln_options(int argc, char *argv[]) { int o; #if CONFIG_FILE && HAVE_GETPWUID static struct passwd *pwd_entry; char *str; #endif #ifdef LONG_OPTIONS int option_index = 0; static struct option long_options[] = { {"timeout", 1, 0, 't'}, #ifdef PROC_NET_DEV {"procfile",1,0,'f'}, #endif #ifdef PROC_DISKSTATS {"diskstatsfile",1,0,1000}, {"partitionsfile",1,0,1001}, #endif #if NETSTAT && ALLOW_NETSTATPATH {"netstat",1,0,'n'}, #endif #if IOSERVICE_IN {"longdisknames",0,0,1002}, #endif {"input",1,0,'i'}, {"dynamic",1,0,'d'}, {"help", 0, 0, 'h'}, {"version",0,0,'V'}, {"allif",1,0,'a'}, {"unit",1,0,'u'}, {"ansiout",0,0,'N'}, #if EXTENDED_STATS {"type",1,0,'T'}, {"avglength",1,0,'A'}, #endif {"interfaces",1,0,'I'}, {"sumhidden",1,0,'S'}, {"output",1,0,'o'}, #ifdef CSV {"csvchar",1,0,'C'}, {"csvfile",1,0,'F'}, #endif {"count",1,0,'c'}, {"daemon",1,0,'D'}, #ifdef HTML {"htmlrefresh",1,0,'R'}, {"htmlheader",1,0,'H'}, #endif {0,0,0,0} }; #endif #ifdef CONFIG_FILE /* loop till first non option argument */ opterr=0; while (1) { #ifdef LONG_OPTIONS o=getopt_long (argc,argv,SHORT_OPTIONS,long_options, &option_index); #else o=getopt (argc,argv,SHORT_OPTIONS); #endif if (o==-1) break; } opterr=1; if (optind < argc) { read_config(argv[optind]); } else { read_config("/etc/bwm-ng.conf"); #ifdef HAVE_GETPWUID pwd_entry=getpwuid(getuid()); if (pwd_entry!=NULL) { str=(char*)malloc(strlen(pwd_entry->pw_dir)+14); snprintf(str,strlen(pwd_entry->pw_dir)+14,"%s/.bwm-ng.conf",pwd_entry->pw_dir); read_config(str); free(str); } #endif } /* reset getopt again */ optind=1; #endif /* get command line arguments, kinda ugly, wanna rewrite it? */ while (1) { #ifdef LONG_OPTIONS o=getopt_long (argc,argv,SHORT_OPTIONS,long_options, &option_index); #else o=getopt (argc,argv,SHORT_OPTIONS); #endif if (o==-1) break; switch (o) { case '?': printf("unknown option: %s\n",argv[optind-1]); exit(EXIT_FAILURE); break; /* ugly workaround to handle optional arguments for all platforms */ case ':': if (!strcmp(argv[optind-1],"-a") || !strcasecmp(argv[optind-1],"--allif")) show_all_if=1; else if (!strcmp(argv[optind-1],"-d") || !strcasecmp(argv[optind-1],"--dynamic")) dynamic=1; else if (!strcmp(argv[optind-1],"-D") || !strcasecmp(argv[optind-1],"--daemon")) daemonize=1; #ifdef HTML else if (!strcmp(argv[optind-1],"-H") || !strcasecmp(argv[optind-1],"--htmlheader")) html_header=1; #endif else if (!strcmp(argv[optind-1],"-S") || !strcasecmp(argv[optind-1],"--sumhidden")) sumhidden=1; else { printf("%s requires an argument!\n",argv[optind-1]); exit(EXIT_FAILURE); } break; #ifdef PROC_DISKSTATS case 1000: if (strlen(optarg)0) { html_refresh=atol(optarg); } break; case 'H': if (optarg) html_header=atoi(optarg); break; #endif case 'c': if (optarg) output_count=atol(optarg); break; #if CSV || HTML case 'F': if (optarg) { if (out_file) fclose(out_file); out_file=fopen(optarg,"a"); if (!out_file) deinit(1, "failed to open outfile\n"); if (out_file_path) free(out_file_path); out_file_path=(char *)strdup(optarg); } break; #endif #ifdef CSV case 'C': if (optarg) csv_char=optarg[0]; break; #endif case 'h': cmdln_printhelp(); break; #ifdef PROC_NET_DEV case 'f': if (optarg && (strlen(optarg)0) { delay=atol(optarg); } break; #if EXTENDED_STATS case 'T': output_type=str2output_type(optarg); break; case 'A': if (optarg) avg_length=atoi(optarg)*1000; break; #endif case 'd': if (optarg) dynamic=atoi(optarg); break; case 'u': output_unit=str2output_unit(optarg); break; #if NETSTAT && ALLOW_NETSTATPATH case 'n': if (optarg && (strlen(optarg)=avg_length) deinit(1, "avglength needs to be a least twice the value of timeout\n"); #endif if ((output_unit==ERRORS_OUT && !net_input_method(input_method)) || (output_unit==PACKETS_OUT && input_method==LIBSTATDISK_IN)) output_unit=BYTES_OUT; return; } bwm-ng-0.6.2/src/options.h000066400000000000000000000040551341267030500153460ustar00rootroot00000000000000/****************************************************************************** * bwm-ng options header * * * * Copyright (C) 2004-2007 Volker Gropp (bwmng@gropp.org) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __OPTIONS_H #define __OPTIONS_H #include "defines.h" #include "types.h" #ifdef CONFIG_FILE #include #include #ifdef HAVE_GETPWUID #include #include #include #endif #endif #include "help.h" #include "bwm-ng.h" void get_cmdln_options(int argc, char *argv[]); #endif bwm-ng-0.6.2/src/output.c000066400000000000000000000572231341267030500152130ustar00rootroot00000000000000/****************************************************************************** * bwm-ng output * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "global_vars.h" #include "output.h" inline static const char *output_type2str(void); static inline const char *input2str(void); static inline const char *show_all_if2str(void); static inline ullong direction2value(char mode,struct inout_long stats); #if EXTENDED_STATS static inline double direction_max2value(char mode,struct inouttotal_double stats,int items); #endif static inline char *dyn_byte_value2str(double value,char *str,int buf_size); char *values2str(char mode,t_iface_speed_stats stats,t_iface_stats full_stats,float multiplier,char *str,int buf_size); inline static const char *output_type2str(void) { #if EXTENDED_STATS static char str[25]; #endif switch (output_type) { case RATE_OUT: return "rate"; break; #if EXTENDED_STATS case MAX_OUT: return "max"; break; case SUM_OUT: return "sum"; break; case AVG_OUT: snprintf(str,24,"avg (%is)",(int)avg_length/1000); return str; break; #endif } return ""; } static inline const char *input2str(void) { switch (input_method) { #ifdef SYSCTL case SYSCTL_IN: return "sysctl"; break; #endif #if SYSCTLDISK_IN case SYSCTLDISK_IN: return "sysctldisk"; break; #endif #ifdef NETSTAT case NETSTAT_IN: return "netstat -i"; break; #endif #ifdef LIBSTATGRAB case LIBSTAT_IN: return "libstatnet"; break; case LIBSTATDISK_IN: return "libstatdisk"; break; #endif #ifdef GETIFADDRS case GETIFADDRS_IN: return "getifaddrs"; break; #endif #if DEVSTAT_IN case DEVSTAT_IN: return "devstat"; break; #endif #ifdef PROC_NET_DEV case PROC_IN: return "/proc/net/dev"; break; #endif #if HAVE_LIBKSTAT case KSTAT_IN: return "kstat"; break; case KSTATDISK_IN: return "kstatdisk"; break; #endif #if IOSERVICE_IN case IOSERVICE_IN: return "ioservice disk IO"; break; #endif #ifdef PROC_DISKSTATS case DISKLINUX_IN: return "disk IO"; break; #endif } return ""; } static inline const char *show_all_if2str(void) { switch (show_all_if) { case 1: return " (all)"; break; case 2: if (net_input_method(input_method)) return " (all and down)"; else return " (all)"; break; } return ""; } int print_header(int option) { #if HTML FILE *tmp_out_file; #endif #ifdef HAVE_CURSES unsigned int row=0; unsigned int col=0; unsigned int width=0; #endif switch (output_method) { #ifdef HAVE_CURSES case CURSES_OUT: erase(); mvwprintw(stdscr,1,2,"bwm-ng v" VERSION" (probing every %2.3fs), press 'h' for help",(float)delay/1000); mvwprintw(stdscr,2,2,"input: %s type: %s",input2str(),output_type2str()); wprintw(stdscr,show_all_if2str()); mvwprintw(stdscr,3,2,"%c iface Rx Tx Total",(char)IDLE_CHARS[option]); /* go to next char for next run */ option++; if (option>3) option=0; mvwprintw(stdscr,4,2,"=============================================================================="); break; case CURSES2_OUT: erase(); if (cols<48 || rows<45) mvwprintw(stdscr,1,2,"window size too small.\n it has to be at least 48x45."); else { width=(cols-3-16-4)/3; mvwprintw(stdscr,1,2,"+---{ bwm-ng v" VERSION" }"); for (col=17+sizeof(VERSION);cols >= 0 && col<(unsigned int)(32+cols-48);col++) mvwprintw(stdscr,1,col,"-"); mvwprintw(stdscr,1,32+cols-48,"+- -- - -- -->"); mvwprintw(stdscr,2,2,"|"), mvwprintw(stdscr,2,32+cols-48,"|------."); for (col=0;col= 0 && col<(unsigned int)(32+cols-48);col++) mvwprintw(stdscr,37,col,"-"); mvwprintw(stdscr,38,2,"`+--> %c probing every: %2.3fs",(char)IDLE_CHARS[option],(float)delay/1000); mvwprintw(stdscr,39,2," +-----> interface: wait... "); mvwprintw(stdscr,40,2," +--------> type: %s",output_type2str()); mvwprintw(stdscr,41,2," `-----------> input: %s",input2str()); scale=max_rt/32; /* print scale */ if (max_rt>=1024) { for (row=0;row<=31;row++) mvwprintw(stdscr,row+3,34+cols-48,"%2.2fM|",(float)(max_rt-row*scale)/1024); } else { for (row=0;row<=31;row++) mvwprintw(stdscr,row+3,34+cols-48,"%4uk|",max_rt-row*scale); } }; /* go to next char for next run */ option++; if (option>3) option=0; break; #endif #ifdef HTML case HTML_OUT: tmp_out_file=out_file==NULL ? stdout : out_file; if (html_header) { fprintf(tmp_out_file,"\n\n\n"); fprintf(tmp_out_file,"\n"); fprintf(tmp_out_file,"\n",html_refresh); fprintf(tmp_out_file,"\n"); fprintf(tmp_out_file,"bwm-ng stats\n\n\n"); } fprintf(tmp_out_file,"
bwm-ng bwm-ng v" VERSION " (refresh %is); input: ",html_refresh); fprintf(tmp_out_file,"%s", input2str()); fprintf(tmp_out_file,"%s", show_all_if2str()); if (output_type==SUM_OUT) fprintf(tmp_out_file,"
Started: %s", start_time); fprintf(tmp_out_file,"
"); fprintf(tmp_out_file,""); break; #endif case PLAIN_OUT_ONCE: case PLAIN_OUT: if (output_method==PLAIN_OUT && ansi_output) printf("\033[1;2H"); printf("bwm-ng v" VERSION " (delay %2.3fs); ", (float)delay/1000); if (output_method==PLAIN_OUT && output_type==SUM_OUT) printf("started: %s; ", start_time); if (output_method==PLAIN_OUT) printf(ansi_output ? "\033[2;2H" : "\n"); printf("input: %s%s", input2str(), show_all_if2str()); if (output_method==PLAIN_OUT) printf("; press 'ctrl-c' to end this\n"); if (output_method==PLAIN_OUT) { if (ansi_output) printf("\033[3;2H"); printf("%c",(char)IDLE_CHARS[option]); } else printf(" "); printf(" iface Rx Tx Total\n"); if (output_method==PLAIN_OUT && ansi_output) printf("\033[4;2H"); printf("==============================================================================\n"); /* go to next char for next run */ option++; if (option>3) option=0; break; } return option; } static inline ullong direction2value(char mode,struct inout_long stats) { switch (mode) { case 0: return stats.in; case 1: return stats.out; case 2: return stats.in+stats.out; } return 0; } #if EXTENDED_STATS static inline double direction_max2value(char mode,struct inouttotal_double stats,int items) { switch (mode) { case 0: return (double)(stats.in/items); case 1: return (double)(stats.out/items); case 2: return (double)(stats.total/items); } return 0; } #endif static inline char *dyn_byte_value2str(double value,char *str,int buf_size) { if (dynamic) { if (value<1024) snprintf(str,buf_size,"%15.2f ",value); else if (value<1048576) snprintf(str,buf_size,"%15.2f K",value/1024); else if (value<1073741824) snprintf(str,buf_size,"%15.2f M",value/1048576); else snprintf(str,buf_size,"%15.2f G",value/1073741824); } else { snprintf(str,buf_size,"%15.2f K",value/1024); } return str; } static inline char *dyn_bit_value2str(double value,char *str,int buf_size) { if (dynamic) { if (value<1000) snprintf(str,buf_size,"%15.2f ",value); else if (value<1000000) snprintf(str,buf_size,"%15.2f k",value/1000); else if (value<1000000000) snprintf(str,buf_size,"%15.2f M",value/1000000); else snprintf(str,buf_size,"%15.2f G",value/1000000000); } else { snprintf(str,buf_size,"%15.2f k",value/1000); } return str; } char *values2str(char mode,t_iface_speed_stats stats,t_iface_stats full_stats,float multiplier,char *str,int buf_size) { char byte_char=' '; char speed[3]; double value=0; char *str_buf=NULL; if (output_type==RATE_OUT #if EXTENDED_STATS || output_type==MAX_OUT || output_type==AVG_OUT #endif ) { strlcpy(speed,"/s",3); } else { strlcpy(speed," ",3); } if ( #if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT input_method==NETSTAT_IN || #endif output_unit==PACKETS_OUT) { switch (output_type) { case RATE_OUT: value=(double)(direction2value(mode,stats.packets)*multiplier); break; #if EXTENDED_STATS case SUM_OUT: value=direction2value(mode,full_stats.sum.packets); break; case MAX_OUT: value=(double)direction_max2value(mode,full_stats.max.packets,1); break; case AVG_OUT: value=(double)direction_max2value(mode,full_stats.avg.item_sum.packets,full_stats.avg.items); break; #endif } snprintf(str,buf_size,"%16.2f %c%s",(double)value,net_input_method(input_method) ? 'P' : '#',speed); } else { switch (output_unit) { case BITS_OUT: case BYTES_OUT: switch (output_type) { case RATE_OUT: value=(double)(direction2value(mode,stats.bytes)*multiplier); break; #if EXTENDED_STATS case SUM_OUT: value=direction2value(mode,full_stats.sum.bytes); break; case MAX_OUT: value=(double)direction_max2value(mode,full_stats.max.bytes,1); break; case AVG_OUT: value=(double)direction_max2value(mode,full_stats.avg.item_sum.bytes,full_stats.avg.items); #endif } str_buf=(char *)malloc(buf_size); if (output_unit==BITS_OUT) { byte_char='b'; value*=8; snprintf(str,buf_size,"%s%c%s",dyn_bit_value2str(value,str_buf,buf_size),byte_char,speed); } else { byte_char='B'; snprintf(str,buf_size,"%s%c%s",dyn_byte_value2str(value,str_buf,buf_size),byte_char,speed); } break; case ERRORS_OUT: switch (output_type) { case RATE_OUT: value=(double)(direction2value(mode,stats.errors)*multiplier); break; #if EXTENDED_STATS case SUM_OUT: value=direction2value(mode,full_stats.sum.errors); break; case MAX_OUT: value=(double)direction_max2value(mode,full_stats.max.errors,1); break; case AVG_OUT: value=(double)direction_max2value(mode,full_stats.avg.item_sum.errors,full_stats.avg.items); break; #endif } snprintf(str,buf_size,"%16.2f E%s",(double)value,speed); break; } } if (str_buf!=NULL) free(str_buf); return str; } /* do the actual output */ void print_values(unsigned int y,unsigned int x,const char *if_name,t_iface_speed_stats stats,float multiplier,t_iface_stats full_stats) { char buffer[50]; struct timeval now; #if CSV || HTML FILE *tmp_out_file; #endif t_iface_speed_stats *stats_csv = NULL; t_double_types stats_csv_d; #ifdef HAVE_CURSES unsigned int row=0; unsigned int col=0; unsigned int width=0; unsigned int i=0, j=0; char adjust=0; #endif switch (output_method) { #ifdef HAVE_CURSES case CURSES_OUT: mvwprintw(stdscr,y,x,"%15s:",if_name); /* output the name */ #if HAVE_WATTRON if (stats.errors.in && output_unit!=ERRORS_OUT) wattron(stdscr, A_REVERSE); #endif wprintw(stdscr,"%s",values2str(0,stats,full_stats,multiplier,buffer,49)); #if HAVE_WATTRON if (stats.errors.in && output_unit!=ERRORS_OUT) wattroff(stdscr, A_REVERSE); #endif wprintw(stdscr," "); #if HAVE_WATTRON if (stats.errors.out && output_unit!=ERRORS_OUT) wattron(stdscr, A_REVERSE); #endif wprintw(stdscr,"%s",values2str(1,stats,full_stats,multiplier,buffer,49)); #if HAVE_WATTRON if (stats.errors.out && output_unit!=ERRORS_OUT) wattroff(stdscr, A_REVERSE); #endif wprintw(stdscr," "); #if HAVE_WATTRON if ((stats.errors.out || stats.errors.in) && output_unit!=ERRORS_OUT) wattron(stdscr, A_REVERSE); #endif wprintw(stdscr,"%s",values2str(2,stats,full_stats,multiplier,buffer,49)); #if HAVE_WATTRON if ((stats.errors.out || stats.errors.in) && output_unit!=ERRORS_OUT) wattroff(stdscr, A_REVERSE); #endif break; case CURSES2_OUT: if (cols<48 || rows<45) mvwprintw(stdscr,1,2,"window size too small.\n it has to be at least 49x46."); else { if (show_only_if+5==y) { /* show only one interface at a time */ width=(cols-3-16-4)/3; mvwprintw(stdscr,39,2," +-----> interface: %s ",if_name); /* output the name */ switch (output_type) { case RATE_OUT: i=(int)(stats.bytes.in*multiplier/1024); /* incoming */ j=(int)(stats.bytes.out*multiplier/1024); /* outgoing */ break; #ifdef EXTENDED_STATS case MAX_OUT: i=(int)(full_stats.max.bytes.in/1024); j=(int)(full_stats.max.bytes.out/1024); break; case SUM_OUT: i=(int)(full_stats.sum.bytes.in/1024); j=(int)(full_stats.sum.bytes.out/1024); break; case AVG_OUT: i=(int)(full_stats.avg.item_sum.bytes.in/1024); j=(int)(full_stats.avg.item_sum.bytes.out/1024); break; #endif }; /* adjust scale */ if (i>max_rt || j>max_rt) { adjust=1; if (i>j) max_rt=i; else max_rt=j; } else if (i<=max_rt-24*scale && j<=max_rt-24*scale) { adjust=1; max_rt=31*scale; }; if (adjust) { adjust=!adjust; if (max_rt<32) max_rt=32; /* print scale */ scale=max_rt/32; if (max_rt>=1024) for (row=0;row<=31;row++) mvwprintw(stdscr,row+3,34+cols-48,"%2.2fM|",(float)(max_rt-row*scale)/1024); else for (row=0;row<=31;row++) mvwprintw(stdscr,row+3,3+cols-484,"%4uk|",max_rt-row*scale); }; /* print bar (incoming) */ if (i>0) { if (i<(max_rt-31*scale)) i=1; else i=(i-(max_rt-31*scale))/scale+2; }; for (row=34;row>=3;row--) { if (i>0) attron(COLOR_PAIR(1)); for (col=0;col0) { attroff(COLOR_PAIR(1)); i--; } }; /* print bar (outgoing) */ if (j>0) { if (j<(max_rt-31*scale)) j=1; else j=(j-(max_rt-31*scale))/scale+2; }; for (row=34;row>=3;row--) { if (j>0) attron(COLOR_PAIR(2)); for (col=0;col0) { attroff(COLOR_PAIR(2)); j--; } }; } else if (show_only_if+6==y) if (strcmp("total",if_name)==0) show_only_if=0; }; break; #endif case PLAIN_OUT_ONCE: case PLAIN_OUT: if (output_method==PLAIN_OUT && ansi_output) printf("\033[%d;2H",y); printf("%15s:",if_name); /* output the name */ printf("%s ", values2str(0,stats,full_stats,multiplier,buffer,49)); printf("%s ",values2str(1,stats,full_stats,multiplier,buffer,49)); printf("%s\n",values2str(2,stats,full_stats,multiplier,buffer,49)); break; #ifdef HTML case HTML_OUT: tmp_out_file=out_file==NULL ? stdout : out_file; fprintf(tmp_out_file,"\n",values2str(2,stats,full_stats,multiplier,buffer,49)); break; #endif #ifdef CSV case CSV_OUT: tmp_out_file=out_file==NULL ? stdout : out_file; gettimeofday(&now, NULL); fprintf(tmp_out_file,"%1.6f%c%s%c",(((double)now.tv_sec * 1000000.0) + (double)now.tv_usec) / 1000000.0,csv_char,if_name,csv_char); if (output_type == RATE_OUT || output_type == SUM_OUT) { if (output_type == RATE_OUT) { stats_csv = &stats; #if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT if (input_method!=NETSTAT_IN) #endif /* output Bytes/s */ fprintf(tmp_out_file,"%.2f%c%.2f%c%.2f%c%llu%c%llu%c",(double)(stats_csv->bytes.out*multiplier),csv_char,(double)(stats_csv->bytes.in*multiplier),csv_char,(double)((stats_csv->bytes.out+stats_csv->bytes.in)*multiplier),csv_char,stats_csv->bytes.in,csv_char,stats_csv->bytes.out,csv_char); /* show packets/s and errors/s */ fprintf(tmp_out_file,"%.2f%c%.2f%c%.2f%c%llu%c%llu",(double)stats_csv->packets.out*multiplier,csv_char,(double)stats_csv->packets.in*multiplier,csv_char,(double)(stats_csv->packets.out+stats_csv->packets.in)*multiplier,csv_char,stats_csv->packets.in,csv_char,stats_csv->packets.out); fprintf(tmp_out_file,"%c%.2f%c%.2f%c%llu%c%llu\n",csv_char,stats_csv->errors.out*multiplier,csv_char,stats_csv->errors.in*multiplier,csv_char,stats_csv->errors.in,csv_char,stats_csv->errors.out); fflush(tmp_out_file); } else { stats_csv = &full_stats.sum; #if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT if (input_method!=NETSTAT_IN) #endif /* output Bytes */ fprintf(tmp_out_file,"%llu%c%llu%c%llu%c",stats_csv->bytes.out,csv_char,stats_csv->bytes.in,csv_char,(stats_csv->bytes.out+stats_csv->bytes.in),csv_char); /* show packets and errors */ fprintf(tmp_out_file,"%llu%c%llu%c%llu",stats_csv->packets.out,csv_char,stats_csv->packets.in,csv_char,(stats_csv->packets.out+stats_csv->packets.in)); fprintf(tmp_out_file,"%c%llu%c%llu\n",csv_char,stats_csv->errors.out,csv_char,stats_csv->errors.in); fflush(tmp_out_file); } } else { /* MAX_OUT or AVG_OUT */ if (output_type == MAX_OUT) stats_csv_d = full_stats.max; else { stats_csv_d.bytes.out = full_stats.avg.item_sum.bytes.out/full_stats.avg.items; stats_csv_d.bytes.in = full_stats.avg.item_sum.bytes.in/full_stats.avg.items; stats_csv_d.bytes.total = full_stats.avg.item_sum.bytes.total/full_stats.avg.items; stats_csv_d.packets.out = full_stats.avg.item_sum.packets.out/full_stats.avg.items; stats_csv_d.packets.in = full_stats.avg.item_sum.packets.in/full_stats.avg.items; stats_csv_d.packets.total = full_stats.avg.item_sum.packets.total/full_stats.avg.items; stats_csv_d.errors.out = full_stats.avg.item_sum.errors.out/full_stats.avg.items; stats_csv_d.errors.in = full_stats.avg.item_sum.errors.in/full_stats.avg.items; stats_csv_d.errors.total = full_stats.avg.item_sum.errors.total/full_stats.avg.items; } #if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT if (input_method!=NETSTAT_IN) #endif /* output Bytes/s */ fprintf(tmp_out_file,"%.2Lf%c%.2Lf%c%.2Lf%c",stats_csv_d.bytes.out,csv_char,stats_csv_d.bytes.in,csv_char,stats_csv_d.bytes.total,csv_char); /* show packets/s and errors/s */ fprintf(tmp_out_file,"%.2Lf%c%.2Lf%c%.2Lf",stats_csv_d.packets.out,csv_char,stats_csv_d.packets.in,csv_char,stats_csv_d.packets.total); fprintf(tmp_out_file,"%c%.2Lf%c%.2Lf\n",csv_char,stats_csv_d.errors.out,csv_char,stats_csv_d.errors.in); fflush(tmp_out_file); } break; #endif } } bwm-ng-0.6.2/src/output.h000066400000000000000000000040531341267030500152110ustar00rootroot00000000000000/****************************************************************************** * bwm-ng output * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #ifndef __OUTPUT_H #define __OUTPUT_H #include "defines.h" #include "types.h" /* for csv output and time() */ #include #include "options.h" int print_header(int option); void print_values(unsigned int y,unsigned int x,const char *if_name,t_iface_speed_stats stats,float multiplier,t_iface_stats full_stats); #endif bwm-ng-0.6.2/src/process.c000066400000000000000000000403401341267030500153210ustar00rootroot00000000000000/****************************************************************************** * bwm-ng process data * * * * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * * * * for more info read README. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * *****************************************************************************/ #include "global_vars.h" #include "process.h" short show_iface(char *instr, char *searchstr,char iface_is_up); #if HAVE_GETTIMEOFDAY static inline long tvdiff(struct timeval newer, struct timeval older); float get_time_delay(int iface_num); #endif static inline ullong calc_new_values(ullong new, ullong old); t_iface_speed_stats convert2calced_values(t_iface_speed_stats new, t_iface_speed_stats old); t_iface_speed_stats convert2calced_disk_values(t_iface_speed_stats new, t_iface_speed_stats old); #if EXTENDED_STATS static inline void sub_avg_values(struct inouttotal_double *values,struct inouttotal_double data); static inline void add_avg_values(struct inouttotal_double *values,struct inouttotal_double data); static inline void save_avg_values(struct inouttotal_double *values,struct inouttotal_double *data,struct inout_long calced_stats,float multiplier); void save_avg(struct t_avg *avg,struct iface_speed_stats calced_stats,float multiplier); static inline void save_sum(struct inout_long *stats,struct inout_long new_stats_values); static inline void save_max(struct inouttotal_double *stats,struct inout_long calced_stats,float multiplier); #endif /* returns the whether to show the iface or not * if is in list return 1, if list is prefaced with ! or * name not found return 0 */ short show_iface(char *instr, char *searchstr,char iface_is_up) { int pos = 0,k,success_ret = 1; unsigned int i = 0; if (instr==NULL) return iface_is_up || (show_all_if==2); if (instr[0]=='%') { success_ret=!success_ret; i++; } k = strlen( searchstr ); for (;i<=strlen(instr);i++) { switch ( instr[i] ) { case 0: case ',': if ( k == pos && ! strncasecmp( &instr[i] - pos, searchstr, pos ) ) { return success_ret || (iface_is_up && show_all_if); } pos = 0; break; default: pos++; break; } } return !success_ret || (iface_is_up && show_all_if) || (show_all_if==2); } #if HAVE_GETTIMEOFDAY /* Returns: the time difference in milliseconds. */ static inline long tvdiff(struct timeval newer, struct timeval older) { return labs((newer.tv_sec-older.tv_sec)*1000+ (newer.tv_usec-older.tv_usec)/1000); } /* returns the milliseconds since old stat */ float get_time_delay(int iface_num) { struct timeval now; float ret = 0.0f; gettimeofday(&now,NULL); long diff = tvdiff(now,if_stats[iface_num].time); if (diff > 0) { ret=(float)1000/diff; } if_stats[iface_num].time.tv_sec=now.tv_sec; if_stats[iface_num].time.tv_usec=now.tv_usec; return ret; } #endif /* basically new-old, but handles "overflow" of source aswell */ static inline ullong calc_new_values(ullong new, ullong old) { /* FIXME: WRAP_AROUND _might_ be wrong for libstatgrab, where the type is always long long */ return (new>=old) ? (ullong)(new-old) : (ullong)(( #ifdef HAVE_LIBKSTAT (input_method==KSTAT_IN) ? WRAP_32BIT : #endif WRAP_AROUND) -old)+new; } /* calc actual new-old values */ t_iface_speed_stats convert2calced_values(t_iface_speed_stats new, t_iface_speed_stats old) { t_iface_speed_stats calced_stats; calced_stats.errors.in=calc_new_values(new.errors.in,old.errors.in); calced_stats.errors.out=calc_new_values(new.errors.out,old.errors.out); calced_stats.packets.out=calc_new_values(new.packets.out,old.packets.out); calced_stats.packets.in=calc_new_values(new.packets.in,old.packets.in); calced_stats.bytes.out=calc_new_values(new.bytes.out,old.bytes.out); calced_stats.bytes.in=calc_new_values(new.bytes.in,old.bytes.in); return calced_stats; } /* calc actual new-old values */ t_iface_speed_stats convert2calced_disk_values(t_iface_speed_stats new, t_iface_speed_stats old) { t_iface_speed_stats calced_stats; calced_stats.bytes.out=calc_new_values(new.bytes.out,old.bytes.out); calced_stats.bytes.in=calc_new_values(new.bytes.in,old.bytes.in); /* needed for linux stats, read and write count */ calced_stats.packets.out=calc_new_values(new.packets.out,old.packets.out)*(calc_new_values(new.errors.out,old.errors.out)+1); calced_stats.packets.in=calc_new_values(new.packets.in,old.packets.in)*(calc_new_values(new.errors.in,old.errors.in)+1); calced_stats.errors.in=0; calced_stats.errors.out=0; return calced_stats; } #if EXTENDED_STATS /* sub old values from cached for avg stats */ static inline void sub_avg_values(struct inouttotal_double *values,struct inouttotal_double data) { values->in-=data.in; values->out-=data.out; values->total-=data.total; } static inline void add_avg_values(struct inouttotal_double *values,struct inouttotal_double data) { values->in+=data.in; values->out+=data.out; values->total+=data.total; } /* put new-old bytes in inout_long struct into a inouttotal_double struct * and add values to cached .value struct */ static inline void save_avg_values(struct inouttotal_double *values,struct inouttotal_double *data,struct inout_long calced_stats,float multiplier) { data->in=calced_stats.in*multiplier; data->out=calced_stats.out*multiplier; data->total=(calced_stats.in+calced_stats.out)*multiplier; add_avg_values(values,*data); } /* manages the list of values for avg * saves data in list * removes old entries * calculates the current value */ void save_avg(struct t_avg *avg,struct iface_speed_stats calced_stats,float multiplier) { struct double_list *list_p; if (avg->first==NULL) { /* first element */ avg->first=avg->last=(struct double_list *)malloc(sizeof(struct double_list)); /* init it to zero and NULL */ memset(avg->first,0,sizeof(struct double_list)); /* save data and add to cache */ save_avg_values(&avg->item_sum.bytes,&avg->first->data.bytes,calced_stats.bytes,multiplier); save_avg_values(&avg->item_sum.errors,&avg->first->data.errors,calced_stats.errors,multiplier); save_avg_values(&avg->item_sum.packets,&avg->first->data.packets,calced_stats.packets,multiplier); avg->items=1; } else { /* we already have a list */ avg->last->next=(struct double_list *)malloc(sizeof(struct double_list)); memset(avg->last->next,0,sizeof(struct double_list)); avg->last=avg->last->next; /* save data and add to cache */ save_avg_values(&avg->item_sum.bytes,&avg->last->data.bytes,calced_stats.bytes,multiplier); save_avg_values(&avg->item_sum.errors,&avg->last->data.errors,calced_stats.errors,multiplier); save_avg_values(&avg->item_sum.packets,&avg->last->data.packets,calced_stats.packets,multiplier); avg->items++; /* remove only entries if at least two items added, * else we might leave an empty list * avg->first has to be != NULL at this point (if in 2nd line of this function) */ while (avg->first->next!=NULL && avg->items > avg_length/delay) { /* list is full, remove first entry */ list_p=avg->first; avg->first=avg->first->next; /* sub values from cache */ sub_avg_values(&avg->item_sum.bytes,list_p->data.bytes); sub_avg_values(&avg->item_sum.errors,list_p->data.errors); sub_avg_values(&avg->item_sum.packets,list_p->data.packets); free(list_p); avg->items--; } } } /* add current in and out bytes to totals struct */ static inline void save_sum(struct inout_long *stats,struct inout_long new_stats_values) { stats->in+=new_stats_values.in; stats->out+=new_stats_values.out; } /* lookup old max values and save new if higher */ static inline void save_max(struct inouttotal_double *stats,struct inout_long calced_stats,float multiplier) { if (multiplier*calced_stats.in > stats->in) stats->in=multiplier*calced_stats.in; if (multiplier*calced_stats.out>stats->out) stats->out=multiplier*calced_stats.out; if (multiplier*(calced_stats.out+calced_stats.in)>stats->total) stats->total=multiplier*(calced_stats.in+calced_stats.out); } #endif void clean_down_ifaces(void) { #ifdef IOCTL int local_if_count; t_iface_stats *new_if_stats = NULL; int new_if_count = 0; for (local_if_count=0;local_if_count
InterfaceRxTxTotal
%15s:",if_name, (stats.errors.in && output_unit!=ERRORS_OUT) ? "error" : "dummy"); fprintf(tmp_out_file,"%s ", values2str(0,stats,full_stats,multiplier,buffer,49), (stats.errors.out && output_unit!=ERRORS_OUT) ? "error" : "dummy"); fprintf(tmp_out_file,"%s ", values2str(1,stats,full_stats,multiplier,buffer,49), ((stats.errors.out || stats.errors.in) && output_unit!=ERRORS_OUT) ? "error" : "dummy" ); fprintf(tmp_out_file,"%s