From 3be703f67d34b761725a13b6e58ab22591824bbe Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Fri, 5 Jul 2013 15:11:46 +0200 Subject: Initial import --- .gitignore | 21 +- ChangeLog | 0 Makefile.am | 11 + README.md | 5 + autogen.sh | 4 + configure.ac | 191 +++++++ etc/bmon.conf | 81 +++ include/bmon/.gitignore | 2 + include/bmon/attr.h | 138 +++++ include/bmon/bmon.h | 82 +++ include/bmon/compile-fixes.h | 35 ++ include/bmon/conf.h | 91 +++ include/bmon/config.h | 158 ++++++ include/bmon/defs.h.in | 246 ++++++++ include/bmon/element.h | 130 +++++ include/bmon/element_cfg.h | 53 ++ include/bmon/graph.h | 72 +++ include/bmon/group.h | 100 ++++ include/bmon/history.h | 93 +++ include/bmon/info.h | 42 ++ include/bmon/input.h | 52 ++ include/bmon/list.h | 93 +++ include/bmon/module.h | 75 +++ include/bmon/output.h | 39 ++ include/bmon/unit.h | 68 +++ include/bmon/utils.h | 102 ++++ m4/ax_with_curses.m4 | 518 +++++++++++++++++ man/Makefile.am | 3 + man/bmon.8 | 235 ++++++++ src/.gitignore | 2 + src/Makefile.am | 42 ++ src/attr.c | 635 +++++++++++++++++++++ src/bmon.c | 397 +++++++++++++ src/conf.c | 596 ++++++++++++++++++++ src/element.c | 537 ++++++++++++++++++ src/element_cfg.c | 96 ++++ src/graph.c | 235 ++++++++ src/group.c | 278 +++++++++ src/history.c | 318 +++++++++++ src/in_dummy.c | 243 ++++++++ src/in_netlink.c | 868 ++++++++++++++++++++++++++++ src/in_null.c | 62 ++ src/in_proc.c | 234 ++++++++ src/input.c | 83 +++ src/module.c | 195 +++++++ src/out_ascii.c | 299 ++++++++++ src/out_curses.c | 1277 ++++++++++++++++++++++++++++++++++++++++++ src/out_format.c | 373 ++++++++++++ src/out_null.c | 56 ++ src/output.c | 95 ++++ src/unit.c | 216 +++++++ src/utils.c | 421 ++++++++++++++ 52 files changed, 10285 insertions(+), 13 deletions(-) create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 etc/bmon.conf create mode 100644 include/bmon/.gitignore create mode 100644 include/bmon/attr.h create mode 100644 include/bmon/bmon.h create mode 100644 include/bmon/compile-fixes.h create mode 100644 include/bmon/conf.h create mode 100644 include/bmon/config.h create mode 100644 include/bmon/defs.h.in create mode 100644 include/bmon/element.h create mode 100644 include/bmon/element_cfg.h create mode 100644 include/bmon/graph.h create mode 100644 include/bmon/group.h create mode 100644 include/bmon/history.h create mode 100644 include/bmon/info.h create mode 100644 include/bmon/input.h create mode 100644 include/bmon/list.h create mode 100644 include/bmon/module.h create mode 100644 include/bmon/output.h create mode 100644 include/bmon/unit.h create mode 100644 include/bmon/utils.h create mode 100644 m4/ax_with_curses.m4 create mode 100644 man/Makefile.am create mode 100644 man/bmon.8 create mode 100644 src/.gitignore create mode 100644 src/Makefile.am create mode 100644 src/attr.c create mode 100644 src/bmon.c create mode 100644 src/conf.c create mode 100644 src/element.c create mode 100644 src/element_cfg.c create mode 100644 src/graph.c create mode 100644 src/group.c create mode 100644 src/history.c create mode 100644 src/in_dummy.c create mode 100644 src/in_netlink.c create mode 100644 src/in_null.c create mode 100644 src/in_proc.c create mode 100644 src/input.c create mode 100644 src/module.c create mode 100644 src/out_ascii.c create mode 100644 src/out_curses.c create mode 100644 src/out_format.c create mode 100644 src/out_null.c create mode 100644 src/output.c create mode 100644 src/unit.c create mode 100644 src/utils.c diff --git a/.gitignore b/.gitignore index 0331bbb..ef9058c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,12 @@ -# Object files *.o - -# Libraries -*.lib *.a - -# Shared objects (inc. Windows DLLs) -*.dll *.so *.so.* -*.dylib - -# Executables -*.exe -*.out -*.app +*.swp +.deps +Makefile.in +Makefile +/build-aux/ +/aclocal.m4 +/configure +/config.* diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..533f8c5 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,11 @@ +# -*- Makefile -*- + +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = src man + +pkgsysconfdir = $(sysconfdir) +pkgsysconf_DATA = etc/bmon.conf + +EXTRA_DIST = \ + $(pkgsysconf_DATA) diff --git a/README.md b/README.md index f47f8b3..50255a0 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,8 @@ bmon ==== bandwidth monitor and rate estimator + +bmon is a monitoring and debugging tool to capture networking related +statistics and prepare them visually in a human friendly way. It +features various output methods including an interactive curses user +interface and a programmable text output for scripting. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..a569614 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +autoreconf -fi; +rm -Rf autom4te.cache; diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..752784b --- /dev/null +++ b/configure.ac @@ -0,0 +1,191 @@ +# +# configure.in Configure Script +# +# Copyright (c) 2001-2013 Thomas Graf +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +AC_INIT(bmon, 3.0-git, [], [], [http://www.infradead.org/~tgr/bmon/]) +AC_CONFIG_HEADERS(include/bmon/defs.h) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_MACRO_DIR([m4]) + +AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)], []) + +AC_ISC_POSIX +AC_PROG_CC +AC_PROG_CC_STDC +AC_PROG_CPP +AC_PROG_MAKE_SET +AC_PROG_INSTALL + +AC_C_CONST +AC_C_INLINE + +AC_HEADER_TIME +AC_HEADER_DIRENT + +AC_TYPE_SIZE_T +AC_TYPE_SIGNAL +AC_TYPE_PID_T + +AC_FUNC_FORK + +AC_CHECK_HEADERS(getopt.h ncurses/ncurses.h ncurses.h curses.h) +AC_CHECK_HEADERS(dirent.h sys/utsname.h sys/sockio.h netinet6/in6.h) +AC_CHECK_HEADERS(fcntl.h netdb.h netinet/in.h sysctl/ioctl.h) +AC_CHECK_HEADERS(sys/param.h sys/socket.h) + +AC_CHECK_TYPES(suseconds_t) + +AC_CHECK_FUNCS(atexit gettimeofday memset pow socket strcasecmp) +AC_CHECK_FUNCS(strchr strdup strerror strncasecmp strstr strtol) +AC_CHECK_FUNCS(uname getdate) + +AX_WITH_CURSES +if test "x$ax_cv_curses" != xyes || test "x$ax_cv_curses_color" != xyes; then + AC_MSG_ERROR([requires an X/Open-compatible Curses library with color]) +fi + +PKG_CHECK_MODULES([CONFUSE], [libconfuse], [], AC_MSG_ERROR([requires libconfuse])) + +PKG_CHECK_MODULES([LIBNL], [libnl-3.0], [], AC_MSG_ERROR([requires libnl])) +PKG_CHECK_MODULES([LIBNL_ROUTE], [libnl-route-3.0], [], AC_MSG_ERROR([requires libnl3-route])) + +AC_CHECK_LIB(m, pow, [], AC_MSG_ERROR([requires libm])) + +BMON_LIB="" + +##################################################################### +## +## libcurses check +## +##################################################################### +CURSES="No " +AC_CHECK_LIB(ncurses, initscr, [ + AC_DEFINE_UNQUOTED(HAVE_NCURSES, "1", [have ncurses]) + LCURSES="ncurses" + CURSES="Yes" +],[ + AC_CHECK_LIB(curses,initscr, [ + AC_DEFINE_UNQUOTED(HAVE_CURSES, "1", [have curses]) + LCURSES="curses" + CURSES="Yes" + ],[ + echo + echo "*** Warning: Building bmon w/o curses support ***" + echo + ]) +]) + +LIBCURSES="-l$LCURSES" + +AC_CHECK_LIB($LCURSES, redrawwin, [ + AC_DEFINE_UNQUOTED(HAVE_REDRAWWIN, "1", [have redrawwin]) +]) + +AC_CHECK_LIB($LCURSES, use_default_colors, [ + AC_DEFINE_UNQUOTED(HAVE_USE_DEFAULT_COLORS, "1", [have udc]) +]) + +##################################################################### +## +## interface counter overflow workaround +## +##################################################################### +AC_ARG_ENABLE(cnt-workaround, +[ --disable-cnt-workaround Disables interface counter overflow workaround],[ + if test x$enableval = xno; then + AC_DEFINE_UNQUOTED(DISABLE_OVERFLOW_WORKAROUND,"1",[no overflow workaround]) + fi +]) + +##################################################################### +## +## curses +## +##################################################################### +AC_ARG_ENABLE(curses, +[ --disable-curses Disables curses output],[ + if test x$enableval = xno; then + CURSES="No " + fi +]) + +##################################################################### +## +## debug check +## +##################################################################### +DEBUG=0 +AC_ARG_ENABLE(debug, +[ --enable-debug Enable debug mode (default disabled)],[ + if test x$enableval = xyes; then + AC_DEFINE_UNQUOTED(DEBUG, "1", [enable debugging]) + DEBUG=1; + fi +]) + +##################################################################### +## +## target os eval +## +##################################################################### +case ${target_os} in + linux*) + AC_DEFINE_UNQUOTED(SYS_LINUX, "1", [operating system]) + ;; + + *solaris*) + AC_DEFINE_UNQUOTED(SYS_SUNOS, "1", [operating system]) + ;; + + *bsd*) + AC_DEFINE_UNQUOTED(SYS_BSD, "1", [operating system]) + ;; + + *darwin*) + AC_DEFINE_UNQUOTED(SYS_BSD, "1", [operating system]) + ;; + + *) + AC_DEFINE_UNQUOTED(SYS_OTHER, "1", [operating system]) + ;; +esac + +##################################################################### +## +## export variables +## +##################################################################### +AC_SUBST(DEBUG) +AC_SUBST(STATIC) +AC_SUBST(SYS) +AC_SUBST(ARCH) + +AC_SUBST(CURSES) + +AC_CONFIG_FILES([ +Makefile +src/Makefile +man/Makefile +]) + +AC_OUTPUT diff --git a/etc/bmon.conf b/etc/bmon.conf new file mode 100644 index 0000000..567a131 --- /dev/null +++ b/etc/bmon.conf @@ -0,0 +1,81 @@ +/* + * read_interval = 1.0 + * rate_interval = 1.0 + * variance = 0.1 + * history_variance = 0.1 + * sleep_time = 20000 + * lifetime = 30.0 + * show_all = true + * policy = "" + */ + +/* + * element eth0 { + * description = { "My description" } + * rxmax = { 10000 } + * txmax = { 10000 } + * max = { 12500000 } + * } + */ + +/* + * Default configuration + * + * The following definitions is what is compiled into bmon and used + * by default. + * + * unit byte { + * variant default { + * div = { 1, 1024, 1048576, 1073741824, 1099511627776} + * txt = { "B", "KiB", "MiB", "GiB", "TiB" } + * } + * variant si { + * div = { 1, 1000, 1000000, 1000000000, 1000000000000 } + * txt = { "B", "KB", "MB", "GB", "TB" } + * } + * } + * + * unit bit { + * variant default { + * div = { 1, 1024, 1048576, 1073741824, 1099511627776} + * txt = { "b", "Kib", "Mib", "Gib", "TiB" } + * } + * variant si { + * div = { 1, 1000, 1000000, 1000000000, 1000000000000 } + * txt = { "b", "Kb", "Mb", "Gb", "Tb" } + * } + * } + * + * unit number { + * variant default { + * div = { 1, 1000, 1000000, 1000000000, 1000000000000 } + * txt = { "", "K", "M", "G", "T" } + * } + * } + * unit percent { + * variant default { + * div = { 1. } + * txt = { "%" } + * } + * } + * + * history second { + * interval = { 1. } + * size = { 60 } + * } + * + * history minute { + * interval = { 60. } + * size = { 60 } + * } + * + * history hour { + * interval = { 3600. } + * size = { 60 } + * } + * + * history day { + * interval = { 86400. } + * size = { 60 } + * } + */ diff --git a/include/bmon/.gitignore b/include/bmon/.gitignore new file mode 100644 index 0000000..7ffac03 --- /dev/null +++ b/include/bmon/.gitignore @@ -0,0 +1,2 @@ +defs.h* +stamp-h1 diff --git a/include/bmon/attr.h b/include/bmon/attr.h new file mode 100644 index 0000000..224f151 --- /dev/null +++ b/include/bmon/attr.h @@ -0,0 +1,138 @@ +/* + * bmon/attr.h Attributes + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_ATTR_H_ +#define __BMON_ATTR_H_ + +#include +#include + +struct element; + +struct rate +{ + /* Total value of attribute with eventual overflows accumulated. */ + uint64_t r_total; + + /* Current value of counter */ + uint64_t r_current; + + /* Value of r_current at last read */ + uint64_t r_prev; + + /* Rate per second calculated every `rate_interval' */ + float r_rate; + + /* Time of last calculation */ + timestamp_t r_last_calc; +}; + +enum { + ATTR_TYPE_UNSPEC, + ATTR_TYPE_COUNTER, + ATTR_TYPE_RATE, + ATTR_TYPE_PERCENT, +}; + +struct attr_def { + int ad_id; + char * ad_name; + char * ad_description; + int ad_type; + int ad_flags; + struct unit * ad_unit; + + struct list_head ad_list; +}; + +struct attr_map { + const char * name; + const char * description; + const char * unit; + int attrid, + type, + rxid, + txid, + flags; +}; + +extern int attr_def_add(const char *, const char *, + struct unit *, int, int); +extern struct attr_def * attr_def_lookup(const char *); +extern struct attr_def * attr_def_lookup_id(int); + +extern int attr_map_load(struct attr_map *map, size_t size); + +#define ATTR_FORCE_HISTORY 0x01 /* collect history */ +#define ATTR_IGNORE_OVERFLOWS 0x02 +#define ATTR_TRUE_64BIT 0x04 +#define ATTR_RX_ENABLED 0x08 /* has RX counter */ +#define ATTR_TX_ENABLED 0x10 /* has TX counter */ +#define ATTR_DOING_HISTORY 0x20 /* history collected */ + +struct attr +{ + struct rate a_rx_rate, + a_tx_rate; + + uint8_t a_flags; + struct attr_def * a_def; + timestamp_t a_last_update; + + struct list_head a_history_list; + + struct list_head a_list; + struct list_head a_sort_list; +}; + +extern struct attr * attr_lookup(const struct element *, int); +extern void attr_update(struct element *, int, + uint64_t, uint64_t , int ); +extern void attr_notify_update(struct attr *, + timestamp_t *); +extern void attr_free(struct attr *); + +extern void attr_rate2float(struct attr *, + double *, char **, int *, + double *, char **, int *); + +extern void attr_calc_usage(struct attr *, float *, float *, + uint64_t, uint64_t); + +#define ATTR_HASH_SIZE 32 + +#define UPDATE_FLAG_RX 0x01 +#define UPDATE_FLAG_TX 0x02 +#define UPDATE_FLAG_64BIT 0x04 + +extern struct attr * attr_select_first(void); +extern struct attr * attr_select_last(void); +extern struct attr * attr_select_next(void); +extern struct attr * attr_select_prev(void); +extern struct attr * attr_current(void); + +extern void attr_start_collecting_history(struct attr *); + +#endif diff --git a/include/bmon/bmon.h b/include/bmon/bmon.h new file mode 100644 index 0000000..e349110 --- /dev/null +++ b/include/bmon/bmon.h @@ -0,0 +1,82 @@ +/* + * bmon.h All-include Header + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_BMON_H_ +#define __BMON_BMON_H_ + +#include +#include + +extern int start_time; + +typedef struct timestamp_s +{ + int64_t tv_sec; + int64_t tv_usec; +} timestamp_t; + +typedef struct xdate_s +{ + struct tm d_tm; + unsigned int d_usec; +} xdate_t; + +enum { + EMPTY_LIST = 1, + END_OF_LIST = 2 +}; + +#define BUG() \ + do { \ + fprintf(stderr, "BUG: %s:%d\n", __FILE__, __LINE__); \ + assert(0); \ + exit(EINVAL); \ + } while (0); + +#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0])) + +#if defined __GNUC__ +#define __init __attribute__ ((constructor)) +#define __exit __attribute__ ((destructor)) +#else +#define __init +#define __exit +#endif + +#ifdef DEBUG +#define DBG(FMT, ARG...) \ + do { \ + fprintf(stderr, \ + "[DBG] %20s:%-4u %s: " FMT "\n", \ + __FILE__, __LINE__, \ + __PRETTY_FUNCTION__, ##ARG); \ + } while (0) +#else +#define DBG(FMT, ARG...) \ + do { \ + } while (0) +#endif + +#endif diff --git a/include/bmon/compile-fixes.h b/include/bmon/compile-fixes.h new file mode 100644 index 0000000..c3e5b00 --- /dev/null +++ b/include/bmon/compile-fixes.h @@ -0,0 +1,35 @@ +/* + * compile_fixes.h + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_COMPILE_FIXES_H_ +#define __BMON_COMPILE_FIXES_H_ + +#include + +#ifndef HAVE_SUSECONDS_T +typedef long suseconds_t; +#endif + +#endif diff --git a/include/bmon/conf.h b/include/bmon/conf.h new file mode 100644 index 0000000..f95d48f --- /dev/null +++ b/include/bmon/conf.h @@ -0,0 +1,91 @@ +/* + * conf.h Config Crap + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_CONF_H_ +#define __BMON_CONF_H_ + +#include + +extern cfg_t *cfg; + +extern float cfg_read_interval; +extern float cfg_rate_interval; +extern float cfg_rate_variance; +extern float cfg_history_variance; +extern int cfg_show_all; +extern int cfg_unit_exp; + +extern void conf_init_pre(void); +extern void conf_init_post(void); +extern void configfile_read(void); +extern void set_configfile(const char *); + +extern unsigned int get_lifecycles(void); + +extern void conf_set_float(const char *, double); +extern double conf_get_float(const char *); +extern void conf_set_int(const char *, long); +extern long conf_get_int(const char *); +extern void conf_set_string(const char *, const char *); +extern const char * conf_get_string(const char *); + +typedef struct tv_s +{ + char * tv_type; + char * tv_value; + struct list_head tv_list; +} tv_t; + +typedef struct module_conf_s +{ + char * m_name; + struct list_head m_attrs; + struct list_head m_list; +} module_conf_t; + +extern int parse_module_param(const char *, struct list_head *); + +enum { + LAYOUT_UNSPEC, + LAYOUT_DEFAULT, + LAYOUT_STATUSBAR, + LAYOUT_HEADER, + LAYOUT_LIST, + LAYOUT_SELECTED, + __LAYOUT_MAX +}; + +#define LAYOUT_MAX (__LAYOUT_MAX - 1) + +struct layout +{ + int l_fg, + l_bg, + l_attr; +}; + +extern struct layout cfg_layout[]; + +#endif diff --git a/include/bmon/config.h b/include/bmon/config.h new file mode 100644 index 0000000..e717245 --- /dev/null +++ b/include/bmon/config.h @@ -0,0 +1,158 @@ +/* + * config.h Global Config + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_CONFIG_H_ +#define __BMON_CONFIG_H_ + +#include +#include + +#if STDC_HEADERS != 1 +#error "*** ERROR: ANSI C headers required for compilation ***" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#ifdef HAVE_VFORK_H +#include +#endif + +#if !HAVE_WORKING_VFORK +#define vfork fork +#endif + +#if defined HAVE_STRING_H +#include +#elif defined HAVE_STRINGS_H +#include +#else +#error "*** ERROR: No string header file found ***" +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef HAVE_STDINT_H +#include +#endif + +#ifdef HAVE_INITTYPES_H +#include +#endif + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#if defined HAVE_GETOPT_H +#include +#endif + +#include +#include +#include +#include + +#if defined HAVE_SYS_UTSNAME_H +#include +#endif + +#if defined HAVE_NCURSESW_CURSES_H +# include +#elif defined HAVE_NCURSESW_H +# include +#elif defined HAVE_NCURSES_CURSES_H +# include +#elif defined HAVE_NCURSES_H +# include +#elif defined HAVE_CURSES_H +# include +#else +# error "SysV or X/Open-compatible Curses header file required" +#endif + +#include + +#if defined HAVE_NETINET6_IN6_H +#include +#endif + +#include +#include + +#include + +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + +#ifndef SCNu64 +#define SCNu64 "llu" +#endif + +#ifndef PRIu64 +#define PRIu64 "llu" +#endif + +#ifndef PRId64 +#define PRId64 "lld" +#endif + +#ifndef PRIX64 +#define PRIX64 "X" +#endif + +#define DEFAULT_GROUP "intf" + +#endif diff --git a/include/bmon/defs.h.in b/include/bmon/defs.h.in new file mode 100644 index 0000000..d176c30 --- /dev/null +++ b/include/bmon/defs.h.in @@ -0,0 +1,246 @@ +/* include/bmon/defs.h.in. Generated from configure.ac by autoheader. */ + +/* enable debugging */ +#undef DEBUG + +/* no overflow workaround */ +#undef DISABLE_OVERFLOW_WORKAROUND + +/* Define to 1 if you have the `atexit' function. */ +#undef HAVE_ATEXIT + +/* have curses */ +#undef HAVE_CURSES + +/* Define to 1 if library supports color (enhanced functions) */ +#undef HAVE_CURSES_COLOR + +/* Define to 1 if library supports X/Open Enhanced functions */ +#undef HAVE_CURSES_ENHANCED + +/* Define to 1 if is present */ +#undef HAVE_CURSES_H + +/* Define to 1 if library supports certain obsolete features */ +#undef HAVE_CURSES_OBSOLETE + +/* Define to 1 if you have the header file. */ +#undef HAVE_DIRENT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `fork' function. */ +#undef HAVE_FORK + +/* Define to 1 if you have the `getdate' function. */ +#undef HAVE_GETDATE + +/* Define to 1 if you have the header file. */ +#undef HAVE_GETOPT_H + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* have ncurses */ +#undef HAVE_NCURSES + +/* Define to 1 if the NcursesW library is present */ +#undef HAVE_NCURSESW + +/* Define to 1 if is present */ +#undef HAVE_NCURSESW_CURSES_H + +/* Define to 1 if is present */ +#undef HAVE_NCURSESW_H + +/* Define to 1 if is present */ +#undef HAVE_NCURSES_CURSES_H + +/* Define to 1 if is present */ +#undef HAVE_NCURSES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NCURSES_NCURSES_H + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +#undef HAVE_NDIR_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET6_IN6_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if you have the `pow' function. */ +#undef HAVE_POW + +/* have redrawwin */ +#undef HAVE_REDRAWWIN + +/* Define to 1 if you have the `socket' function. */ +#undef HAVE_SOCKET + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strchr' function. */ +#undef HAVE_STRCHR + +/* Define to 1 if you have the `strdup' function. */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strncasecmp' function. */ +#undef HAVE_STRNCASECMP + +/* Define to 1 if you have the `strstr' function. */ +#undef HAVE_STRSTR + +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + +/* Define to 1 if the system has the type `suseconds_t'. */ +#undef HAVE_SUSECONDS_T + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSCTL_IOCTL_H + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#undef HAVE_SYS_DIR_H + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#undef HAVE_SYS_NDIR_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PARAM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKIO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UTSNAME_H + +/* Define to 1 if you have the `uname' function. */ +#undef HAVE_UNAME + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* have udc */ +#undef HAVE_USE_DEFAULT_COLORS + +/* Define to 1 if you have the `vfork' function. */ +#undef HAVE_VFORK + +/* Define to 1 if you have the header file. */ +#undef HAVE_VFORK_H + +/* Define to 1 if `fork' works. */ +#undef HAVE_WORKING_FORK + +/* Define to 1 if `vfork' works. */ +#undef HAVE_WORKING_VFORK + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define as the return type of signal handlers (`int' or `void'). */ +#undef RETSIGTYPE + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* operating system */ +#undef SYS_BSD + +/* operating system */ +#undef SYS_LINUX + +/* operating system */ +#undef SYS_OTHER + +/* operating system */ +#undef SYS_SUNOS + +/* Define to 1 if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to `int' if does not define. */ +#undef pid_t + +/* Define to `unsigned int' if does not define. */ +#undef size_t + +/* Define as `fork' if `vfork' does not work. */ +#undef vfork diff --git a/include/bmon/element.h b/include/bmon/element.h new file mode 100644 index 0000000..6c68250 --- /dev/null +++ b/include/bmon/element.h @@ -0,0 +1,130 @@ +/* + * bmon/element.h Elements + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_ELEMENT_H_ +#define __BMON_ELEMENT_H_ + +#include +#include +#include + +#define MAX_GRAPHS 32 +#define IFNAME_MAX 32 + +struct policy +{ + char * p_rule; + struct list_head p_list; +}; + +struct element_cfg; + +struct info +{ + char * i_name; + char * i_value; + struct list_head i_list; +}; + +struct element +{ + char * e_name; + char * e_description; + uint32_t e_id; + uint32_t e_flags; + unsigned int e_lifecycles; + unsigned int e_level; /* recursion level */ + + struct element * e_parent; + struct element_group * e_group; + + struct list_head e_list; + struct list_head e_childs; + + unsigned int e_nattrs; + struct list_head e_attrhash[ATTR_HASH_SIZE]; + struct list_head e_attr_sorted; + + unsigned int e_ninfo; + struct list_head e_info_list; + + struct attr_def * e_key_attr[__GT_MAX]; + struct attr_def * e_usage_attr; + + float e_rx_usage, + e_tx_usage; + + struct element_cfg * e_cfg; + + struct attr * e_current_attr; +}; + +#define ELEMENT_CREAT (1 << 0) + +extern struct element * element_lookup(struct element_group *, + const char *, uint32_t, + struct element *, int); + +extern void element_free(struct element *); + +extern void element_reset_update_flag(struct element_group *, + struct element *, + void *); +extern void element_notify_update(struct element *, + timestamp_t *); +extern void element_lifesign(struct element *, int); +extern void element_check_if_dead(struct element_group *, + struct element *, void *); + +extern int element_set_key_attr(struct element *, const char *, const char *); +extern int element_set_usage_attr(struct element *, const char *); + +#define ELEMENT_FLAG_FOLDED (1 << 0) +#define ELEMENT_FLAG_UPDATED (1 << 1) +#define ELEMENT_FLAG_EXCLUDE (1 << 2) +#define ELEMENT_FLAG_CREATED (1 << 3) + +extern void element_foreach_attr(struct element *, + void (*cb)(struct element *, + struct attr *, void *), + void *); + +extern struct element * element_current(void); +extern struct element * element_select_first(void); +extern struct element * element_select_last(void); +extern struct element * element_select_next(void); +extern struct element * element_select_prev(void); + +extern int element_allowed(const char *, struct element_cfg *); +extern void element_parse_policy(const char *); + +extern void element_update_info(struct element *, + const char *, + const char *); + +extern void element_set_txmax(struct element *, uint64_t); +extern void element_set_rxmax(struct element *, uint64_t); + +#endif diff --git a/include/bmon/element_cfg.h b/include/bmon/element_cfg.h new file mode 100644 index 0000000..3131841 --- /dev/null +++ b/include/bmon/element_cfg.h @@ -0,0 +1,53 @@ +/* + * element_cfg.h Element Configuration + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_ELEMENT_CFG_H_ +#define __BMON_ELEMENT_CFG_H_ + +#include +#include + +#define ELEMENT_CFG_SHOW (1 << 0) +#define ELEMENT_CFG_HIDE (1 << 1) + +struct element_cfg +{ + char * ec_name; /* Name of element config */ + char * ec_parent; /* Name of parent */ + char * ec_description; /* Human readable description */ + uint64_t ec_rxmax; /* Maximum RX value expected */ + uint64_t ec_txmax; /* Minimum TX value expected */ + unsigned int ec_flags; /* Flags */ + + struct list_head ec_list; /* Internal, do not modify */ + int ec_refcnt; /* Internal, do not modify */ +}; + +extern struct element_cfg * element_cfg_alloc(const char *); +extern struct element_cfg * element_cfg_create(const char *); +extern void element_cfg_free(struct element_cfg *); +extern struct element_cfg * element_cfg_lookup(const char *); + +#endif diff --git a/include/bmon/graph.h b/include/bmon/graph.h new file mode 100644 index 0000000..bdfac72 --- /dev/null +++ b/include/bmon/graph.h @@ -0,0 +1,72 @@ +/* + * bmon/graph.h Graph creation utility + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_GRAPH_H_ +#define __BMON_GRAPH_H_ + +#include +#include + +struct history; + +struct graph_cfg { + int gc_height, + gc_width, + gc_flags; + + char gc_background, + gc_foreground, + gc_noise, + gc_unknown; + + struct unit * gc_unit; +}; + +struct graph_table { + char * gt_table; + char * gt_y_unit; + float * gt_scale; +}; + +struct graph { + struct graph_cfg g_cfg; + struct graph_table g_rx, + g_tx; + + struct list_head g_list; +}; + +extern void graph_free(struct graph *); +extern struct graph * graph_alloc(struct history *, struct graph_cfg *); +extern void graph_refill(struct graph *, struct history *); + +extern size_t graph_row_size(struct graph_cfg *); + +extern void new_graph(void); +extern void del_graph(void); +extern int next_graph(void); +extern int prev_graph(void); + +#endif diff --git a/include/bmon/group.h b/include/bmon/group.h new file mode 100644 index 0000000..b952aac --- /dev/null +++ b/include/bmon/group.h @@ -0,0 +1,100 @@ +/* + * bmon/group.h Group Management + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_GROUP_H_ +#define __BMON_GROUP_H_ + +#include + +struct element; + +enum { + GT_MAJOR, + GT_MINOR, + __GT_MAX, +}; + +#define GT_MAX (__GT_MAX - 1) + +#define GROUP_COL_MAX (__GT_MAX * 2) + +struct group_hdr +{ + char * gh_name; + char * gh_title; + char * gh_column[GROUP_COL_MAX]; + struct list_head gh_list; +}; + +extern struct group_hdr * group_lookup_hdr(const char *); +extern int group_new_hdr(const char *, const char *, + const char *, const char *, + const char *, const char *); +extern int group_new_derived_hdr(const char *, + const char *, + const char *); + +struct element_group +{ + char * g_name; + struct group_hdr * g_hdr; + + struct list_head g_elements; + unsigned int g_nelements; + + /* Currently selected element in this group */ + struct element * g_current; + + struct list_head g_list; +}; + +#define GROUP_CREATE 1 + +extern struct element_group * group_lookup(const char *, int); +extern void reset_update_flags(void); +extern void free_unused_elements(void); +extern void calc_rates(void); + +extern void group_foreach( + void (*cb)(struct element_group *, + void *), + void *); +extern void group_foreach_recursive( + void (*cb)(struct element_group *, + struct element *, void *), + void *); + +extern void group_foreach_element(struct element_group *, + void (*cb)(struct element_group *, + struct element *, void *), + void *); + +extern struct element_group * group_current(void); +extern struct element_group * group_select_first(void); +extern struct element_group * group_select_last(void); +extern struct element_group * group_select_next(void); +extern struct element_group * group_select_prev(void); + +#endif diff --git a/include/bmon/history.h b/include/bmon/history.h new file mode 100644 index 0000000..6b7faa4 --- /dev/null +++ b/include/bmon/history.h @@ -0,0 +1,93 @@ +/* + * bmon/history.h History Management + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_HISTORY_H_ +#define __BMON_HISTORY_H_ + +#include +#include + +#define HISTORY_UNKNOWN ((uint64_t) -1) +#define HBEAT_TRIGGER 60.0f + +enum { + HISTORY_TYPE_8 = 1, + HISTORY_TYPE_16 = 2, + HISTORY_TYPE_32 = 4, + HISTORY_TYPE_64 = 8, +}; + +struct history_def +{ + char * hd_name; + int hd_size, + hd_type; + float hd_interval; + + struct list_head hd_list; +}; + +struct history_store +{ + /* TODO? store error ratio? */ + void * hs_data; + uint64_t hs_prev_total; +}; + +struct history +{ + /* index to current entry in data array */ + int h_index; + struct history_def * h_definition; + /* time of last history update */ + timestamp_t h_last_update; + struct list_head h_list; + + float h_min_interval, + h_max_interval; + + struct history_store h_rx, + h_tx; + +}; + +extern struct history_def * history_def_lookup(const char *); +extern struct history_def * history_def_alloc(const char *); + +extern uint64_t history_data(struct history *, + struct history_store *, int); +extern void history_update(struct attr *, + struct history *, timestamp_t *); +extern struct history * history_alloc(struct history_def *); +extern void history_free(struct history *); +extern void history_attach(struct attr *); + +extern struct history_def * history_select_first(void); +extern struct history_def * history_select_last(void); +extern struct history_def * history_select_next(void); +extern struct history_def * history_select_prev(void); +extern struct history_def * history_current(void); + +#endif diff --git a/include/bmon/info.h b/include/bmon/info.h new file mode 100644 index 0000000..b12b97d --- /dev/null +++ b/include/bmon/info.h @@ -0,0 +1,42 @@ +/* + * bmon/info.h Info Attributes + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_INFO_H_ +#define __BMON_INFO_H_ + +#include +#include + +struct element; + +struct info +{ + char * i_name; + char * i_value; + + struct list_head i_list; +}; + +#endif diff --git a/include/bmon/input.h b/include/bmon/input.h new file mode 100644 index 0000000..dfd24d0 --- /dev/null +++ b/include/bmon/input.h @@ -0,0 +1,52 @@ +/* + * input.h Input API + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_INPUT_H_ +#define __BMON_INPUT_H_ + +#include +#include +#include + +extern int input_set(const char *); +extern void input_register(struct bmon_module *); +extern void input_read(void); + +struct reader_timing +{ + timestamp_t rt_last_read; /* timestamp taken before read */ + timestamp_t rt_next_read; /* estimated next read */ + + struct { + float v_error; + float v_max; + float v_min; + float v_total; + } rt_variance; +}; + +extern struct reader_timing rtiming; + +#endif diff --git a/include/bmon/list.h b/include/bmon/list.h new file mode 100644 index 0000000..c7569d7 --- /dev/null +++ b/include/bmon/list.h @@ -0,0 +1,93 @@ +/* + * bmon/list.h Kernel List Implementation + * + * Copied and adapted from the kernel sources + * + */ + +#ifndef BMON_LIST_H_ +#define BMON_LIST_H_ + +struct list_head +{ + struct list_head * next; + struct list_head * prev; +}; + +static inline void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +} + +static inline void __list_add(struct list_head *obj, struct list_head *prev, + struct list_head *next) +{ + prev->next = obj; + obj->prev = prev; + next->prev = obj; + obj->next = next; +} + +static inline void list_add_tail(struct list_head *obj, struct list_head *head) +{ + __list_add(obj, head->prev, head); +} + +static inline void list_add_head(struct list_head *obj, struct list_head *head) +{ + __list_add(obj, head, head->next); +} + +static inline void list_del(struct list_head *obj) +{ + obj->next->prev = obj->prev; + obj->prev->next = obj->next; +} + +static inline int list_empty(struct list_head *head) +{ + return head->next == head; +} + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - ((size_t) &((type *)0)->member));}) + +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +#define list_at_tail(pos, head, member) \ + ((pos)->member.next == (head)) + +#define list_at_head(pos, head, member) \ + ((pos)->member.prev == (head)) + +#define LIST_SELF(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = { &(name), &(name) } + +#define list_first_entry(head, type, member) \ + list_entry((head)->next, type, member) + +#define list_for_each_entry(pos, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member); \ + &(pos)->member != (head); \ + (pos) = list_entry((pos)->member.next, typeof(*(pos)), member)) + +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &(pos)->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +#define init_list_head(head) \ + do { (head)->next = (head); (head)->prev = (head); } while (0) + +#endif diff --git a/include/bmon/module.h b/include/bmon/module.h new file mode 100644 index 0000000..bd1405a --- /dev/null +++ b/include/bmon/module.h @@ -0,0 +1,75 @@ +/* + * module.h Module API + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_MODULE_H_ +#define __BMON_MODULE_H_ + +#include +#include + +#define BMON_MODULE_ENABLED 1 +#define BMON_MODULE_DEFAULT 2 + +struct bmon_module +{ + char * m_name; + + int (*m_init)(void); + int (*m_probe)(void); + void (*m_shutdown)(void); + + void (*m_parse_opt)(const char *, const char *); + + void (*m_pre)(void); + void (*m_do)(void); + void (*m_post)(void); + + int m_flags; + struct list_head m_list; +}; + +struct bmon_subsys +{ + char * s_name; + int s_nmod; + struct list_head s_mod_list; + + void (*s_activate_default)(void); + + struct list_head s_list; +}; + +extern void module_foreach_run_enabled_pre(struct bmon_subsys *); +extern void module_foreach_run_enabled(struct bmon_subsys *); +extern void module_foreach_run_enabled_post(struct bmon_subsys *); + +extern void module_register(struct bmon_subsys *, struct bmon_module *); +extern int module_set(struct bmon_subsys *, const char *); + +extern void module_init(void); +extern void module_shutdown(void); +extern void module_register_subsys(struct bmon_subsys *); + +#endif diff --git a/include/bmon/output.h b/include/bmon/output.h new file mode 100644 index 0000000..f1fa6c5 --- /dev/null +++ b/include/bmon/output.h @@ -0,0 +1,39 @@ +/* + * output.h Output API + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_OUTPUT_H_ +#define __BMON_OUTPUT_H_ + +#include +#include +#include + +extern void output_register(struct bmon_module *); +extern int output_set(const char *); +extern void output_pre(void); +extern void output_draw(void); +extern void output_post(void); + +#endif diff --git a/include/bmon/unit.h b/include/bmon/unit.h new file mode 100644 index 0000000..e0a83d3 --- /dev/null +++ b/include/bmon/unit.h @@ -0,0 +1,68 @@ +/* + * bmon/unit.h Units + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_UNIT_H_ +#define __BMON_UNIT_H_ + +#include + +#define DYNAMIC_EXP (-1) + +enum { + UNIT_DEFAULT, + UNIT_SI, + __UNIT_MAX, +}; + +#define UNIT_MAX (__UNIT_MAX - 1) + +#define UNIT_BYTE "byte" +#define UNIT_NUMBER "number" + +struct fraction { + uint64_t f_divisor; + char * f_name; + + struct list_head f_list; +}; + +struct unit { + char * u_name; + struct list_head u_div[__UNIT_MAX]; + + struct list_head u_list; +}; + +extern struct unit * unit_lookup(const char *); +extern struct unit * unit_add(const char *name); +extern void unit_add_div(struct unit *, int, const char *, float); +extern uint64_t unit_divisor(uint64_t, struct unit *, char **, int *); +extern double unit_value2str(uint64_t, struct unit *, char **, int *); +extern void fraction_free(struct fraction *); + +extern char * unit_bytes2str(uint64_t, char *, size_t); +extern char * unit_bit2str(uint64_t, char *, size_t); + +#endif diff --git a/include/bmon/utils.h b/include/bmon/utils.h new file mode 100644 index 0000000..725a1cb --- /dev/null +++ b/include/bmon/utils.h @@ -0,0 +1,102 @@ +/* + * utils.h General purpose utilities + * + * Copyright (c) 2001-2013 Thomas Graf + * Copyright (c) 2013 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BMON_UTILS_H_ +#define __BMON_UTILS_H_ + +#include + +extern void * xcalloc(size_t, size_t); +extern void * xrealloc(void *, size_t); +extern void xfree(void *); +extern void quit (const char *, ...); + +extern float timestamp_to_float(timestamp_t *); +extern int64_t timestamp_to_int(timestamp_t *); + +extern void float_to_timestamp(timestamp_t *, float); +extern void int_to_timestamp(timestamp_t *, int); + +extern void timestamp_add(timestamp_t *, timestamp_t *, timestamp_t *); +extern void timestamp_sub(timestamp_t *, timestamp_t *, timestamp_t *); + +extern int timestamp_le(timestamp_t *, timestamp_t *); +extern int timestamp_is_negative(timestamp_t *ts); + +extern void update_timestamp(timestamp_t *); +extern void copy_timestamp(timestamp_t *, timestamp_t *); + +extern float timestamp_diff(timestamp_t *, timestamp_t *); + +#if 0 + + + +#if __BYTE_ORDER == __BIG_ENDIAN +#define xntohll(N) (N) +#define xhtonll(N) (N) +#else +#define xntohll(N) ((((uint64_t) ntohl(N)) << 32) + ntohl((N) >> 32)) +#define xhtonll(N) ((((uint64_t) htonl(N)) << 32) + htonl((N) >> 32)) +#endif + +enum { + U_NUMBER, + U_BYTES, + U_BITS +}; + +extern float read_delta; + + +const char * xinet_ntop(struct sockaddr *, char *, socklen_t); + + +extern float time_diff(timestamp_t *, timestamp_t *); +extern float diff_now(timestamp_t *); + +extern uint64_t parse_size(const char *); + +extern int parse_date(const char *str, xdate_t *dst); + +#ifndef HAVE_STRDUP +extern char *strdup(const char *); +#endif + +extern char * timestamp2str(timestamp_t *ts, char *buf, size_t len); + +static inline char *xstrncat(char *dest, const char *src, size_t n) +{ + return strncat(dest, src, n - strlen(dest) - 1); +} + +static inline void xdate_to_ts(timestamp_t *dst, xdate_t *src) +{ + dst->tv_sec = mktime(&src->d_tm); + d