Compare commits
2 Commits
coverity_s
...
test
Author | SHA1 | Date | |
---|---|---|---|
|
eed0cadf35 | ||
|
13cf9440c4 |
43
.travis.yml
43
.travis.yml
@ -1,33 +1,10 @@
|
||||
script: ./autogen.sh && ./configure && make
|
||||
|
||||
env:
|
||||
global:
|
||||
# COVERITY_SCAN_TOKEN
|
||||
# ** specific to your project **
|
||||
secure: "UwSy57y9-USTD6w65Ubvyg"
|
||||
|
||||
addons:
|
||||
coverity_scan:
|
||||
|
||||
# GitHub project metadata
|
||||
# ** specific to your project **
|
||||
project:
|
||||
name: tgraf/bmon
|
||||
version: 3.7
|
||||
description: bandwidth monitor
|
||||
|
||||
# Where email notification of build analysis results will be sent
|
||||
notification_email: tgraf@suug.ch
|
||||
|
||||
# Commands to prepare for build_command
|
||||
# ** likely specific to your build **
|
||||
build_command_prepend: ./autogen.sh && ./configure
|
||||
|
||||
# The command that will be added as an argument to "cov-build" to compile your project for analysis,
|
||||
# ** likely specific to your build **
|
||||
build_command: make
|
||||
|
||||
# Pattern to match selecting branches that will run analysis. We recommend leaving this set to 'coverity_scan'.
|
||||
# Take care in resource usage, and consider the build frequency allowances per
|
||||
# https://scan.coverity.com/faq#frequency
|
||||
branch_pattern: coverity_scan
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
before_install:
|
||||
- sudo apt-get install libconfuse-dev
|
||||
- sudo apt-get install libnl-3-dev libnl-route-3-dev
|
||||
- sudo apt-get install libncurses-dev
|
||||
# Change this to your needs
|
||||
script: ./.travis/run.sh
|
||||
|
@ -6,4 +6,4 @@ if [ $CC = "clang" ]; then
|
||||
FLAGS="$FLAGS -Wno-error=unused-command-line-argument"
|
||||
fi
|
||||
|
||||
./autogen.sh && ./configure && make CFLAGS="$FLAGS" && make distcheck
|
||||
./autogen.sh && ./configure && make CFLAGS="$FLAGS"
|
||||
|
@ -4,4 +4,4 @@ ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = src man include examples
|
||||
|
||||
EXTRA_DIST = ChangeLog LICENSE.BSD LICENSE.MIT NEWS README.md
|
||||
EXTRA_DIST = ChangeLog LICENSE.BSD LICENSE.MIT NEWS README.adoc
|
||||
|
22
NEWS
22
NEWS
@ -1,25 +1,3 @@
|
||||
v3.8 - July 25, 2015
|
||||
----------------------
|
||||
* Don't disable Netlink if TC stats are unavailable
|
||||
|
||||
v3.7 - November 22, 2014
|
||||
----------------------
|
||||
* Bugfixes
|
||||
* Documentation updates
|
||||
* Provide minimal interface information on BSD
|
||||
|
||||
v3.6 - November 22, 2014
|
||||
----------------------
|
||||
* Build fix for uclinux
|
||||
* Fix LICENSE links
|
||||
|
||||
v3.5 - August 30, 2014
|
||||
----------------------
|
||||
* Fixes for all defects identified by coverity
|
||||
* Fix accuracy issue on total rate calculation
|
||||
* Travis-CI support
|
||||
* Various other small bugfixes
|
||||
|
||||
v3.4 - August 24, 2014
|
||||
----------------------
|
||||
* Bugfixes
|
||||
|
40
README.md
40
README.md
@ -8,29 +8,20 @@ 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.
|
||||
|
||||
## Download
|
||||
## Changes
|
||||
|
||||
* [Latest Release](https://github.com/tgraf/bmon/releases/latest)
|
||||
* [Older Releases](https://github.com/tgraf/bmon/releases)
|
||||
### New in 3.4
|
||||
* Bugfixes
|
||||
* blank screen with config file
|
||||
* quick-help toggle with '?' in curses
|
||||
* Better bmon.conf example
|
||||
|
||||
## Debian/Ubuntu Installation
|
||||
## New in 3.3
|
||||
* MacOS X port
|
||||
* Only initialize curses module if actually used
|
||||
* Assorted bug and spelling fixes
|
||||
* Various build fixes
|
||||
|
||||
```
|
||||
git clone https://github.com/tgraf/bmon.git
|
||||
cd bmon
|
||||
apt-get install build-essential make libconfuse-dev libnl-3-dev libnl-route-3-dev libncurses-dev
|
||||
./autogen.sh
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
bmon
|
||||
```
|
||||
|
||||
-------------
|
||||
## New in 3.8
|
||||
* Don't disable Netlink if TC stats are unavailable
|
||||
|
||||
-------------
|
||||
### Usage
|
||||
|
||||
To run bmon in the default curses mode:
|
||||
@ -49,10 +40,9 @@ provided via:
|
||||
|
||||
## Copyright
|
||||
|
||||
> *Copyright (c) 2001-2014 Thomas Graf <tgraf@suug.ch>*
|
||||
> *Copyright (c) 2013 Red Hat, Inc.*
|
||||
> *Copyright (c) 2001-2014 Thomas Graf <tgraf@suug.ch>
|
||||
> Copyright (c) 2013 Red Hat, Inc.*
|
||||
|
||||
Please see the [LICENSE.BSD](https://github.com/tgraf/bmon/blob/master/LICENSE.BSD)
|
||||
and [LICENSE.MIT](https://github.com/tgraf/bmon/blob/master/LICENSE.MIT) files for
|
||||
additional details.
|
||||
Please see the [LICENSE](https://github.com/tgraf/bmon/blob/master/LICENSE)
|
||||
file for additional details.
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
# DEALINGS IN THE SOFTWARE.
|
||||
|
||||
AC_INIT(bmon, 3.8, [], [], [http://www.infradead.org/~tgr/bmon/])
|
||||
AC_INIT(bmon, 3.4, [], [], [http://www.infradead.org/~tgr/bmon/])
|
||||
AC_CONFIG_HEADERS(include/bmon/defs.h)
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
@ -70,7 +70,7 @@ fi
|
||||
PKG_CHECK_MODULES([CONFUSE], [libconfuse], [], AC_MSG_ERROR([requires libconfuse]))
|
||||
|
||||
case ${target_os} in
|
||||
linux*|uclinux*)
|
||||
linux*)
|
||||
PKG_CHECK_MODULES([LIBNL], [libnl-3.0], [], AC_MSG_ERROR([requires libnl3-dev]))
|
||||
PKG_CHECK_MODULES([LIBNL_ROUTE], [libnl-route-3.0], [], AC_MSG_ERROR([requires libnl3-route]))
|
||||
;;
|
||||
|
@ -60,11 +60,9 @@ enum {
|
||||
#if defined __GNUC__
|
||||
#define __init __attribute__ ((constructor))
|
||||
#define __exit __attribute__ ((destructor))
|
||||
#define __unused__ __attribute__ ((unused))
|
||||
#else
|
||||
#define __init
|
||||
#define __exit
|
||||
#define __unused__
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -34,7 +34,7 @@ in parallel. bmon automatically loads a useful and working input module
|
||||
by default. See INPUT MODULES for more details.
|
||||
.RE
|
||||
.PP
|
||||
\fB \-o\fR, \fB\-\-output\fRMODULE[:OPTIONS][,MODULE...]
|
||||
\fB \-o\fR, \fB\-\-ouptut\fRMODULE[:OPTIONS][,MODULE...]
|
||||
.RS 4
|
||||
Set list of output modules to load and use. Multiple modules can be used
|
||||
in parallel. By default, bmon will use the curses output mode, if that is
|
||||
@ -44,7 +44,7 @@ text mode. See OUTPUT MODULES for more details.
|
||||
.PP
|
||||
\fB \-U\fR, \fB\-\-use\-si\fR
|
||||
.RS 4
|
||||
Use SI unit system (1KB = 1'000 bytes) instead of 1KB = 1'024 bytes.
|
||||
Use SI unit system instead of 1KB = 1'024 bytes.
|
||||
.RE
|
||||
.PP
|
||||
\fB \-f\fR, \fB\-\-configfile=\fRFILE
|
||||
@ -75,11 +75,6 @@ Set interval in seconds in which the rate per counter is calculated.
|
||||
The default is 1.0 seconds.
|
||||
.RE
|
||||
.PP
|
||||
\fB \-b\fR, \fB\-\-use\-bit\fR
|
||||
.RS 4
|
||||
Show rates in bits per second instead of bytes per second.
|
||||
.RE
|
||||
.PP
|
||||
\fB \-L\fR, \fB\-\-lifetime=\fRFLOAT
|
||||
.RS 4
|
||||
Set lifetime of an element in seconds before it is no longer displayed
|
||||
|
@ -7,7 +7,6 @@ bmon_CFLAGS = \
|
||||
-I${top_builddir}/include \
|
||||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-D_GNU_SOURCE \
|
||||
-Wall \
|
||||
$(CURSES_CFLAGS) \
|
||||
$(CONFUSE_CFLAGS) \
|
||||
$(LIBNL_CFLAGS) \
|
||||
|
@ -111,7 +111,7 @@ int attr_def_add(const char *name, const char *desc, struct unit *unit,
|
||||
return def->ad_id;
|
||||
}
|
||||
|
||||
static void attr_def_free(struct attr_def *def)
|
||||
void attr_def_free(struct attr_def *def)
|
||||
{
|
||||
if (!def)
|
||||
return;
|
||||
|
52
src/bmon.c
52
src/bmon.c
@ -33,6 +33,8 @@
|
||||
#include <bmon/group.h>
|
||||
|
||||
int start_time;
|
||||
int do_quit = 0;
|
||||
int is_daemon = 0;
|
||||
|
||||
struct reader_timing rtiming;
|
||||
|
||||
@ -86,7 +88,14 @@ static void do_shutdown(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void sig_exit(void)
|
||||
RETSIGTYPE sig_int(int unused)
|
||||
{
|
||||
if (do_quit)
|
||||
exit(-1);
|
||||
do_quit = 1;
|
||||
}
|
||||
|
||||
void sig_exit(void)
|
||||
{
|
||||
do_shutdown();
|
||||
}
|
||||
@ -111,7 +120,7 @@ void quit(const char *fmt, ...)
|
||||
static inline void print_version(void)
|
||||
{
|
||||
printf("bmon %s\n", PACKAGE_VERSION);
|
||||
printf("Copyright (C) 2001-2015 by Thomas Graf <tgraf@suug.ch>\n");
|
||||
printf("Copyright (C) 2001-2013 by Thomas Graf <tgraf@suug.ch>\n");
|
||||
printf("Copyright (C) 2013 Red Hat, Inc.\n");
|
||||
printf("bmon comes with ABSOLUTELY NO WARRANTY. This is free " \
|
||||
"software, and you\nare welcome to redistribute it under " \
|
||||
@ -127,10 +136,10 @@ static void parse_args_pre(int argc, char *argv[])
|
||||
char *gostr = "+:hvVf:";
|
||||
|
||||
struct option long_opts[] = {
|
||||
{"help", 0, NULL, 'h'},
|
||||
{"version", 0, NULL, 'v'},
|
||||
{"configfile", 1, NULL, 'f'},
|
||||
{NULL, 0, NULL, 0},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'v'},
|
||||
{"configfile", 1, 0, 'f'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
int c = getopt_long(argc, argv, gostr, long_opts, NULL);
|
||||
if (c == -1)
|
||||
@ -166,17 +175,17 @@ static int parse_args_post(int argc, char *argv[])
|
||||
"L:hvVf:";
|
||||
|
||||
struct option long_opts[] = {
|
||||
{"input", 1, NULL, 'i'},
|
||||
{"output", 1, NULL, 'o'},
|
||||
{"policy", 1, NULL, 'p'},
|
||||
{"read-interval", 1, NULL, 'r'},
|
||||
{"rate-interval", 1, NULL, 'R'},
|
||||
{"sleep-interval", 1, NULL, 's'},
|
||||
{"show-all", 0, NULL, 'a'},
|
||||
{"use-si", 0, NULL, 'U'},
|
||||
{"use-bit", 0, NULL, 'b'},
|
||||
{"lifetime", 1, NULL, 'L'},
|
||||
{NULL, 0, NULL, 0},
|
||||
{"input", 1, 0, 'i'},
|
||||
{"output", 1, 0, 'o'},
|
||||
{"policy", 1, 0, 'p'},
|
||||
{"read-interval", 1, 0, 'r'},
|
||||
{"rate-interval", 1, 0, 'R'},
|
||||
{"sleep-interval", 1, 0, 's'},
|
||||
{"show-all", 0, 0, 'a'},
|
||||
{"use-si", 0, 0, 'U'},
|
||||
{"use-bit", 0, 0, 'b'},
|
||||
{"lifetime", 1, 0, 'L'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
int c = getopt_long(argc, argv, gostr, long_opts, NULL);
|
||||
if (c == -1)
|
||||
@ -211,7 +220,7 @@ static int parse_args_post(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
cfg_setbool(cfg, "show_all", cfg_true);
|
||||
cfg_setint(cfg, "show_all", 1);
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
@ -260,8 +269,9 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned long sleep_time;
|
||||
double read_interval;
|
||||
int unused;
|
||||
|
||||
start_time = time(NULL);
|
||||
start_time = time(0);
|
||||
memset(&rtiming, 0, sizeof(rtiming));
|
||||
rtiming.rt_variance.v_min = FLT_MAX;
|
||||
|
||||
@ -352,6 +362,9 @@ int main(int argc, char *argv[])
|
||||
output_post();
|
||||
}
|
||||
|
||||
if (do_quit)
|
||||
exit(0);
|
||||
|
||||
/*
|
||||
* ST := Configured ST
|
||||
*/
|
||||
@ -387,4 +400,5 @@ int main(int argc, char *argv[])
|
||||
static void __init bmon_init(void)
|
||||
{
|
||||
atexit(&sig_exit);
|
||||
//signal(SIGINT, &sig_int);
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ static void configfile_read_units(void)
|
||||
|
||||
static void configfile_read_attrs(void)
|
||||
{
|
||||
int i, nattrs, t = 0;
|
||||
int i, nattrs, t;
|
||||
|
||||
nattrs = cfg_size(cfg, "attr");
|
||||
|
||||
|
@ -113,9 +113,8 @@ void element_parse_policy(const char *policy)
|
||||
xfree(copy);
|
||||
}
|
||||
|
||||
static struct element *__lookup_element(struct element_group *group,
|
||||
const char *name, uint32_t id,
|
||||
struct element *parent)
|
||||
struct element *__lookup_element(struct element_group *group, const char *name,
|
||||
uint32_t id, struct element *parent)
|
||||
{
|
||||
struct list_head *list;
|
||||
struct element *e;
|
||||
|
20
src/graph.c
20
src/graph.c
@ -58,6 +58,26 @@ static inline char *tbl_pos(struct graph_cfg *cfg, char *tbl, int nrow, int ncol
|
||||
return at_col(at_row(cfg, tbl, nrow), ncol);
|
||||
}
|
||||
|
||||
static void write_column(struct graph_cfg *cfg, struct graph_table *tbl, int ncol,
|
||||
uint64_t value, double *scale, double half_step)
|
||||
{
|
||||
char *col = at_col(tbl->gt_table, ncol);
|
||||
int i;
|
||||
|
||||
#if 0
|
||||
if (value == UNK_DATA) {
|
||||
for (i = 0; i < height; i++)
|
||||
*(at_row(g, col, i)) = unk_char;
|
||||
#endif
|
||||
if (value) {
|
||||
*(at_row(cfg, col, 0)) = ':';
|
||||
|
||||
for (i = 0; i < cfg->gc_height; i++)
|
||||
if (value >= (scale[i] - half_step))
|
||||
*(at_row(cfg, col, i)) = cfg->gc_foreground;
|
||||
}
|
||||
}
|
||||
|
||||
static void fill_table(struct graph *g, struct graph_table *tbl,
|
||||
struct history *h, struct history_store *data)
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ static void dummy_parse_opt(const char *type, const char *value)
|
||||
c_numdev = strtol(value, NULL, 0);
|
||||
else if (!strcasecmp(type, "randomize")) {
|
||||
c_randomize = 1;
|
||||
srand(time(NULL));
|
||||
srand(time(0));
|
||||
} else if (!strcasecmp(type, "seed") && value)
|
||||
srand(strtol(value, NULL, 0));
|
||||
else if (!strcasecmp(type, "mtu") && value)
|
||||
|
122
src/in_netlink.c
122
src/in_netlink.c
@ -37,8 +37,6 @@ static int c_notc = 0;
|
||||
static struct element_group *grp;
|
||||
static struct bmon_module netlink_ops;
|
||||
|
||||
#include <linux/if.h>
|
||||
|
||||
#include <netlink/netlink.h>
|
||||
#include <netlink/cache.h>
|
||||
#include <netlink/utils.h>
|
||||
@ -49,17 +47,6 @@ static struct bmon_module netlink_ops;
|
||||
#include <netlink/route/classifier.h>
|
||||
#include <netlink/route/qdisc/htb.h>
|
||||
|
||||
/* These counters are not available prior to libnl 3.2.25. Set them to -1 so
|
||||
* rtnl_link_get_stat() won't be called for them. */
|
||||
#if LIBNL_CURRENT < 220
|
||||
# define RTNL_LINK_ICMP6_CSUMERRORS -1
|
||||
# define RTNL_LINK_IP6_CSUMERRORS -1
|
||||
# define RTNL_LINK_IP6_NOECTPKTS -1
|
||||
# define RTNL_LINK_IP6_ECT1PKTS -1
|
||||
# define RTNL_LINK_IP6_ECT0PKTS -1
|
||||
# define RTNL_LINK_IP6_CEPKTS -1
|
||||
#endif
|
||||
|
||||
static struct attr_map link_attrs[] = {
|
||||
{
|
||||
.name = "bytes",
|
||||
@ -293,14 +280,6 @@ static struct attr_map link_attrs[] = {
|
||||
.rxid = RTNL_LINK_ICMP6_INERRORS,
|
||||
.txid = RTNL_LINK_ICMP6_OUTERRORS,
|
||||
},
|
||||
{
|
||||
.name = "icmp6csumerr",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
.unit = UNIT_NUMBER,
|
||||
.description = "ICMPv6 Checksum Errors",
|
||||
.rxid = RTNL_LINK_ICMP6_CSUMERRORS,
|
||||
.txid = -1,
|
||||
},
|
||||
{
|
||||
.name = "ip6inhdrerr",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
@ -341,14 +320,6 @@ static struct attr_map link_attrs[] = {
|
||||
.rxid = RTNL_LINK_IP6_INADDRERRORS,
|
||||
.txid = -1,
|
||||
},
|
||||
{
|
||||
.name = "ip6csumerr",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
.unit = UNIT_NUMBER,
|
||||
.description = "Ip6 Checksum Error",
|
||||
.rxid = RTNL_LINK_IP6_CSUMERRORS,
|
||||
.txid = -1,
|
||||
},
|
||||
{
|
||||
.name = "ip6reasmtimeo",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
@ -380,38 +351,6 @@ static struct attr_map link_attrs[] = {
|
||||
.description = "Ip6 Reasm/Frag Requests",
|
||||
.rxid = RTNL_LINK_IP6_REASMREQDS,
|
||||
.txid = RTNL_LINK_IP6_FRAGCREATES,
|
||||
},
|
||||
{
|
||||
.name = "ip6noectpkts",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
.unit = UNIT_NUMBER,
|
||||
.description = "Ip6 Non-ECT Packets",
|
||||
.rxid = RTNL_LINK_IP6_NOECTPKTS,
|
||||
.txid = -1,
|
||||
},
|
||||
{
|
||||
.name = "ip6ect1pkts",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
.unit = UNIT_NUMBER,
|
||||
.description = "Ip6 ECT(1) Packets",
|
||||
.rxid = RTNL_LINK_IP6_ECT1PKTS,
|
||||
.txid = -1,
|
||||
},
|
||||
{
|
||||
.name = "ip6ect0pkts",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
.unit = UNIT_NUMBER,
|
||||
.description = "Ip6 ECT(0) Packets",
|
||||
.rxid = RTNL_LINK_IP6_ECT0PKTS,
|
||||
.txid = -1,
|
||||
},
|
||||
{
|
||||
.name = "ip6cepkts",
|
||||
.type = ATTR_TYPE_COUNTER,
|
||||
.unit = UNIT_NUMBER,
|
||||
.description = "Ip6 CE Packets",
|
||||
.rxid = RTNL_LINK_IP6_CEPKTS,
|
||||
.txid = -1,
|
||||
}
|
||||
};
|
||||
|
||||
@ -491,13 +430,12 @@ static struct attr_map tc_attrs[] = {
|
||||
};
|
||||
|
||||
struct rdata {
|
||||
struct nl_cache * class_cache;
|
||||
struct element * parent;
|
||||
int level;
|
||||
};
|
||||
|
||||
static struct nl_sock *sock;
|
||||
static struct nl_cache *link_cache, *qdisc_cache;
|
||||
static struct nl_cache *link_cache, *qdisc_cache, *class_cache;
|
||||
|
||||
static void update_tc_attrs(struct element *e, struct rtnl_tc *tc)
|
||||
{
|
||||
@ -532,10 +470,10 @@ static void update_tc_infos(struct element *e, struct rtnl_tc *tc)
|
||||
|
||||
static void handle_qdisc(struct nl_object *obj, void *);
|
||||
static void find_classes(uint32_t, struct rdata *);
|
||||
static void find_qdiscs(int, uint32_t, struct rdata *);
|
||||
static void find_qdiscs(uint32_t, struct rdata *);
|
||||
|
||||
static struct element *handle_tc_obj(struct rtnl_tc *tc, const char *prefix,
|
||||
const struct rdata *rdata)
|
||||
struct rdata *rdata)
|
||||
{
|
||||
char buf[IFNAME_MAX], name[IFNAME_MAX];
|
||||
uint32_t id = rtnl_tc_get_handle(tc);
|
||||
@ -545,14 +483,11 @@ static struct element *handle_tc_obj(struct rtnl_tc *tc, const char *prefix,
|
||||
snprintf(name, sizeof(name), "%s %s (%s)",
|
||||
prefix, buf, rtnl_tc_get_kind(tc));
|
||||
|
||||
if (!rdata || !rdata->parent)
|
||||
BUG();
|
||||
|
||||
if (!(e = element_lookup(grp, name, id, rdata->parent, ELEMENT_CREAT)))
|
||||
if (!(e = element_lookup(grp, name, id, rdata ? rdata->parent : NULL, ELEMENT_CREAT)))
|
||||
return NULL;
|
||||
|
||||
if (e->e_flags & ELEMENT_FLAG_CREATED) {
|
||||
e->e_level = rdata->level;
|
||||
e->e_level = rdata ? rdata->level : 0;
|
||||
|
||||
if (element_set_key_attr(e, "tc_bytes", "tc_packets") ||
|
||||
element_set_usage_attr(e, "tc_bytes"))
|
||||
@ -583,9 +518,8 @@ static void handle_class(struct nl_object *obj, void *arg)
|
||||
{
|
||||
struct rtnl_tc *tc = (struct rtnl_tc *) obj;
|
||||
struct element *e;
|
||||
const struct rdata *rdata = arg;
|
||||
struct rdata *rdata = arg;
|
||||
struct rdata ndata = {
|
||||
.class_cache = rdata->class_cache,
|
||||
.level = rdata->level + 1,
|
||||
};
|
||||
|
||||
@ -598,10 +532,10 @@ static void handle_class(struct nl_object *obj, void *arg)
|
||||
element_set_txmax(e, rtnl_htb_get_rate((struct rtnl_class *) tc));
|
||||
|
||||
find_classes(rtnl_tc_get_handle(tc), &ndata);
|
||||
find_qdiscs(rtnl_tc_get_ifindex(tc), rtnl_tc_get_handle(tc), &ndata);
|
||||
find_qdiscs(rtnl_tc_get_handle(tc), &ndata);
|
||||
}
|
||||
|
||||
static void find_qdiscs(int ifindex, uint32_t parent, struct rdata *rdata)
|
||||
static void find_qdiscs(uint32_t parent, struct rdata *rdata)
|
||||
{
|
||||
struct rtnl_qdisc *filter;
|
||||
|
||||
@ -609,7 +543,6 @@ static void find_qdiscs(int ifindex, uint32_t parent, struct rdata *rdata)
|
||||
return;
|
||||
|
||||
rtnl_tc_set_parent((struct rtnl_tc *) filter, parent);
|
||||
rtnl_tc_set_ifindex((struct rtnl_tc *) filter, ifindex);
|
||||
|
||||
nl_cache_foreach_filter(qdisc_cache, OBJ_CAST(filter),
|
||||
handle_qdisc, rdata);
|
||||
@ -638,7 +571,7 @@ static void find_classes(uint32_t parent, struct rdata *rdata)
|
||||
|
||||
rtnl_tc_set_parent((struct rtnl_tc *) filter, parent);
|
||||
|
||||
nl_cache_foreach_filter(rdata->class_cache, OBJ_CAST(filter),
|
||||
nl_cache_foreach_filter(class_cache, OBJ_CAST(filter),
|
||||
handle_class, rdata);
|
||||
|
||||
rtnl_class_put(filter);
|
||||
@ -648,9 +581,8 @@ static void handle_qdisc(struct nl_object *obj, void *arg)
|
||||
{
|
||||
struct rtnl_tc *tc = (struct rtnl_tc *) obj;
|
||||
struct element *e;
|
||||
const struct rdata *rdata = arg;
|
||||
struct rdata *rdata = arg;
|
||||
struct rdata ndata = {
|
||||
.class_cache = rdata->class_cache,
|
||||
.level = rdata->level + 1,
|
||||
};
|
||||
|
||||
@ -672,7 +604,6 @@ static void handle_qdisc(struct nl_object *obj, void *arg)
|
||||
static void handle_tc(struct element *e, struct rtnl_link *link)
|
||||
{
|
||||
struct rtnl_qdisc *qdisc;
|
||||
struct nl_cache *class_cache;
|
||||
int ifindex = rtnl_link_get_ifindex(link);
|
||||
struct rdata rdata = {
|
||||
.level = 1,
|
||||
@ -682,8 +613,6 @@ static void handle_tc(struct element *e, struct rtnl_link *link)
|
||||
if (rtnl_class_alloc_cache(sock, ifindex, &class_cache) < 0)
|
||||
return;
|
||||
|
||||
rdata.class_cache = class_cache;
|
||||
|
||||
qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, TC_H_ROOT);
|
||||
if (qdisc) {
|
||||
handle_qdisc(OBJ_CAST(qdisc), &rdata);
|
||||
@ -807,7 +736,7 @@ static void do_link(struct nl_object *obj, void *arg)
|
||||
attr_update(e, m->attrid, c_rx, c_tx, flags);
|
||||
}
|
||||
|
||||
if (!c_notc && qdisc_cache)
|
||||
if (!c_notc)
|
||||
handle_tc(e, link);
|
||||
|
||||
element_notify_update(e, NULL);
|
||||
@ -823,8 +752,7 @@ static void netlink_read(void)
|
||||
goto disable;
|
||||
}
|
||||
|
||||
if (qdisc_cache &&
|
||||
(err = nl_cache_resync(sock, qdisc_cache, NULL, NULL)) < 0) {
|
||||
if ((err = nl_cache_resync(sock, qdisc_cache, NULL, NULL)) < 0) {
|
||||
fprintf(stderr, "Unable to resync qdisc cache: %s\n", nl_geterror(err));
|
||||
goto disable;
|
||||
}
|
||||
@ -844,20 +772,9 @@ static void netlink_shutdown(void)
|
||||
nl_socket_free(sock);
|
||||
}
|
||||
|
||||
static void netlink_use_bit(struct attr_map *map, const int size)
|
||||
{
|
||||
if(cfg_getbool(cfg, "use_bit")) {
|
||||
for(int i = 0; i < size; ++i) {
|
||||
if(!strcmp(map[i].description, "Bytes")) {
|
||||
map[i].description = "Bits";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int netlink_do_init(void)
|
||||
{
|
||||
int err;
|
||||
int err, i;
|
||||
|
||||
if (!(sock = nl_socket_alloc())) {
|
||||
fprintf(stderr, "Unable to allocate netlink socket\n");
|
||||
@ -875,13 +792,10 @@ static int netlink_do_init(void)
|
||||
}
|
||||
|
||||
if ((err = rtnl_qdisc_alloc_cache(sock, &qdisc_cache)) < 0) {
|
||||
fprintf(stderr, "Warning: Unable to allocate qdisc cache: %s\n", nl_geterror(err));
|
||||
fprintf(stderr, "Disabling QoS statistics.\n");
|
||||
qdisc_cache = NULL;
|
||||
fprintf(stderr, "Unable to allocate qdisc cache: %s\n", nl_geterror(err));
|
||||
goto disable;
|
||||
}
|
||||
|
||||
netlink_use_bit(link_attrs, ARRAY_SIZE(link_attrs));
|
||||
netlink_use_bit(tc_attrs, ARRAY_SIZE(tc_attrs));
|
||||
if (attr_map_load(link_attrs, ARRAY_SIZE(link_attrs)) ||
|
||||
attr_map_load(tc_attrs, ARRAY_SIZE(tc_attrs)))
|
||||
BUG();
|
||||
@ -903,17 +817,17 @@ static int netlink_probe(void)
|
||||
|
||||
if (!(sock = nl_socket_alloc()))
|
||||
return 0;
|
||||
|
||||
|
||||
if (nl_connect(sock, NETLINK_ROUTE) < 0)
|
||||
return 0;
|
||||
|
||||
|
||||
if (rtnl_link_alloc_cache(sock, AF_UNSPEC, &lc) == 0) {
|
||||
nl_cache_free(lc);
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
nl_socket_free(sock);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ static void proc_read(void)
|
||||
{
|
||||
struct element *e;
|
||||
FILE *fd;
|
||||
char buf[512], *p, *s, *unused __unused__;
|
||||
char buf[512], *p, *s, *unused;
|
||||
int w;
|
||||
|
||||
if (!(fd = fopen(c_path, "r")))
|
||||
|
@ -163,7 +163,6 @@ sysctl_read(void)
|
||||
struct element *e, *e_parent = NULL;
|
||||
struct if_msghdr *ifm, *nextifm;
|
||||
struct sockaddr_dl *sdl;
|
||||
char info_buf[64];
|
||||
|
||||
ifm = (struct if_msghdr *) next;
|
||||
if (ifm->ifm_type != RTM_IFINFO)
|
||||
@ -226,18 +225,6 @@ sysctl_read(void)
|
||||
attr_update(e, m->attrid, rx, tx, flags);
|
||||
}
|
||||
|
||||
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_mtu);
|
||||
element_update_info(e, "MTU", info_buf);
|
||||
|
||||
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_metric);
|
||||
element_update_info(e, "Metric", info_buf);
|
||||
|
||||
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_recvquota);
|
||||
element_update_info(e, "RX-Quota", info_buf);
|
||||
|
||||
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_xmitquota);
|
||||
element_update_info(e, "TX-Quota", info_buf);
|
||||
|
||||
element_notify_update(e, NULL);
|
||||
element_lifesign(e, 1);
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ static void __auto_load(struct bmon_module *m)
|
||||
int module_set(struct bmon_subsys *ss, const char *name)
|
||||
{
|
||||
struct bmon_module *mod;
|
||||
struct list_head *list;
|
||||
LIST_HEAD(tmp_list);
|
||||
module_conf_t *m;
|
||||
|
||||
|
@ -137,7 +137,7 @@ static void apply_layout(int layout)
|
||||
attrset(cfg_layout[layout].l_attr);
|
||||
}
|
||||
|
||||
static char *float2str(double value, int width, int prec, char *buf, size_t len)
|
||||
char *float2str(double value, int width, int prec, char *buf, size_t len)
|
||||
{
|
||||
snprintf(buf, len, "%'*.*f", width, value == 0.0f ? 0 : prec, value);
|
||||
|
||||
@ -148,7 +148,7 @@ static void put_line(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[2048];
|
||||
int x, y __unused__;
|
||||
int x, y;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
getyx(stdscr, y, x);
|
||||
@ -430,7 +430,7 @@ static void draw_statusbar(void)
|
||||
{
|
||||
static const char *help_text = "Press ? for help";
|
||||
char s[27];
|
||||
time_t t = time(NULL);
|
||||
time_t t = time(0);
|
||||
|
||||
apply_layout(LAYOUT_STATUSBAR);
|
||||
|
||||
|
@ -119,8 +119,11 @@ static char *get_token(struct element_group *g, struct element *e,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(a = attr_lookup(e, def->ad_id)))
|
||||
if (!(a = attr_lookup(e, def->ad_id))) {
|
||||
fprintf(stderr, "Unable to find attribute %u (%s)\n",
|
||||
def->ad_id, name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!strncasecmp(type, "rx:", 3)) {
|
||||
snprintf(buf, len, "%" PRIu64, a->a_rx_rate.r_total);
|
||||
@ -186,8 +189,8 @@ static inline void add_token(int type, char *data)
|
||||
if (out_tokens == NULL)
|
||||
quit("Cannot reallocate out token array\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
out_tokens[token_index].ot_type = type;
|
||||
out_tokens[token_index].ot_str = data;
|
||||
token_index++;
|
||||
@ -247,7 +250,7 @@ static int format_probe(void)
|
||||
}
|
||||
|
||||
goto out;
|
||||
|
||||
|
||||
finish_escape:
|
||||
*p = '\0';
|
||||
add_token(OT_STRING, s);
|
||||
@ -256,7 +259,7 @@ finish_escape:
|
||||
continue;
|
||||
}
|
||||
|
||||
out:
|
||||
out:
|
||||
if (new_one) {
|
||||
add_token(OT_STRING, p);
|
||||
new_one = 0;
|
||||
@ -325,9 +328,9 @@ static void print_help(void)
|
||||
" \"$(element:name) $(attr:rxrate:packets) $(attr:txrate:packets)\\n\"\n" \
|
||||
" eth0 33 5\n" \
|
||||
"\n" \
|
||||
" \"Item: $(element:name)\\n\" \\\n" \
|
||||
" \"Bytes Rate: $(attr:rxrate:bytes)/$(attr:txrate:bytes)\\n\" \\\n" \
|
||||
" \"Packets Rate: $(attr:rxrate:packets)/$(attr:txrate:packets)\\n\"\n" \
|
||||
" \"Element: $(element:name)\\nBytes Rate: \" \\\n" \
|
||||
" \"$(attr:rxrate:bytes)/$(attr:txrate:bytes)\\nPackets Rate: \" \\\n" \
|
||||
" \"$(attr:rxrate:packets)/$(attr:txrate:packets)\\n\"\n" \
|
||||
" Item: eth0\n" \
|
||||
" Bytes Rate: 49130/2119\n" \
|
||||
" Packets Rate: 40/11\n" \
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <bmon/utils.h>
|
||||
#include <bmon/unit.h>
|
||||
|
||||
static struct unit *byte_unit, *bit_unit;
|
||||
static struct unit *byte_unit, *bit_unit, *number_unit;
|
||||
|
||||
static LIST_HEAD(units);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user