From 1fb260d101c1352ac880a0db945bfad984b1ef19 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 21 Oct 2015 11:29:05 +0330 Subject: [PATCH 01/13] - now depend on libpidutil [1] instead of FreeBSD specific libutil - cleanup Makefile and respect PREFIX - now builds on OS X on which clock_gettime() is not implemented --- Makefile | 6 +++--- ifstatd.c | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 862f713..6e5b675 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -PREFIX=/usr/local +PREFIX?=/usr/local INC=-I$(PREFIX)/include -LIB=-L$(PREFIX)/lib -lutil -FLAGS=-Wall -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 +LIB=-L$(PREFIX)/lib -lpidutil +FLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 CC?=cc all: ifstatd_ diff --git a/ifstatd.c b/ifstatd.c index 1ccaef9..24d6bd0 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -46,7 +46,13 @@ #include #include #include -#include +#include +#include + +#ifdef __MACH__ +#include +#define CLOCK_REALTIME 0 +#endif #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) #define RESOLUTION 10 @@ -70,6 +76,23 @@ char *pid_filename; char *cache_filename; struct pidfh *pfh; +#ifdef __MACH__ +/* clock_gettime is not implemented on OSX */ +int +clock_gettime(int clk_id, struct timespec *t) +{ + struct timeval now; + int rv = gettimeofday(&now, NULL); + + if (rv) + return rv; + t->tv_sec = now.tv_sec; + t->tv_nsec = now.tv_usec * 1000; + return 0; +} + +#endif + /* * Prepare for a clean shutdown */ From dd28f6e0075082430ee72251606114950537a51f Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 21 Oct 2015 11:31:58 +0330 Subject: [PATCH 02/13] - update README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f08e29..97b9572 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Interface statistics plugin for munin with [supersampling](http://guide.munin-monitoring.org/en/latest/plugin/supersampling.html) capability -NOTE: This plugin created for FreeBSD and might not run on other OSes +NOTE: This plugin builds on FreeBSD and Darwin, but not tested on other paltforms. +NOTE: This program depends on [libpidutil](https://github.com/farrokhi/libpidutil) ## Installation 1. Clone this repo and build using `make` From 1b4cfba717d5882b2b3f6e22268c9ed7d25f134c Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 21 Oct 2015 11:40:40 +0330 Subject: [PATCH 03/13] cleanup README --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 97b9572..f2377e3 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ # ifstatd_ plugin -[![Issues](https://img.shields.io/github/issues/farrokhi/ifstatd.svg)](https://github.com/farrokhi/ifstatd/issues) -[![Coverity Scan](https://img.shields.io/coverity/scan/6341.svg)](https://scan.coverity.com/projects/farrokhi-ifstatd) -[![GitHub License](https://img.shields.io/github/license/farrokhi/ifstatd.svg)](https://github.com/farrokhi/ifstatd/blob/master/LICENSE) Interface statistics plugin for munin with [supersampling](http://guide.munin-monitoring.org/en/latest/plugin/supersampling.html) capability NOTE: This plugin builds on FreeBSD and Darwin, but not tested on other paltforms. + NOTE: This program depends on [libpidutil](https://github.com/farrokhi/libpidutil) ## Installation From d2cace06a98962e918be819b4b49bb430ddec0e0 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Sun, 25 Oct 2015 16:17:24 +0330 Subject: [PATCH 04/13] - fix potential uninitialized variable --- ifstatd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ifstatd.c b/ifstatd.c index 24d6bd0..e0012e3 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -195,6 +195,8 @@ wait_for(int seconds) struct timespec tp; + bzero(&tp, sizeof(tp)); + clock_gettime(CLOCK_REALTIME, &tp); time_t current_epoch = tp.tv_sec; From 837abdafe63f90956051f9319b33969cc783ba9c Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Tue, 27 Oct 2015 11:22:23 +0330 Subject: [PATCH 05/13] - add Travis CI hint file and icon --- .travis.yml | 3 +++ README.md | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..15224aa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: c +compiler: clang +script: make \ No newline at end of file diff --git a/README.md b/README.md index f2377e3..35bf4f6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/farrokhi/ifstatd.svg)](https://travis-ci.org/farrokhi/ifstatd) + # ifstatd_ plugin Interface statistics plugin for munin with [supersampling](http://guide.munin-monitoring.org/en/latest/plugin/supersampling.html) capability From 91f68407db698542bebe26b9e2b07117fadff700 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Tue, 27 Oct 2015 11:35:27 +0330 Subject: [PATCH 06/13] - add `libpidutil` dependency as submodule - Cleanup Makefile --- .gitmodules | 3 +++ Makefile | 26 +++++++++++++++++--------- libpidutil | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 .gitmodules create mode 160000 libpidutil diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7b62c60 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libpidutil"] + path = libpidutil + url = https://github.com/farrokhi/libpidutil.git diff --git a/Makefile b/Makefile index 6e5b675..e16a84e 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,22 @@ -PREFIX?=/usr/local -INC=-I$(PREFIX)/include -LIB=-L$(PREFIX)/lib -lpidutil -FLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 CC?=cc +PREFIX?=/usr/local +CPPFLAGS=-I$(PREFIX)/include +LDFLAGS=-L$(PREFIX)/lib +LDLIBS=-lpidutil +FLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 -all: ifstatd_ +.PHONY: libpidutil get-deps -ifstatd_: ifstatd.c Makefile - $(CC) $(FLAGS) $(INC) $(LIB) ifstatd.c -o ifstatd_ +all: get-deps libpidutil ifstatd_ + +ifstatd_: ifstatd.o + +get-deps: + git submodule update --init + +libpidutil: + $(MAKE) -C libpidutil all clean: - rm -f ifstatd_ - + rm -f *.BAK *.log *.o *.a core ifstatd_ + $(MAKE) -C libpidutil clean diff --git a/libpidutil b/libpidutil new file mode 160000 index 0000000..6c886a4 --- /dev/null +++ b/libpidutil @@ -0,0 +1 @@ +Subproject commit 6c886a4584028724e80d8e5010126916114275aa From 6be3e3f94923df64a0b902212514071dc487853e Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Tue, 27 Oct 2015 11:55:56 +0330 Subject: [PATCH 07/13] - Fix build on linux --- Makefile | 4 ++-- ifstatd.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e16a84e..960240a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC?=cc PREFIX?=/usr/local -CPPFLAGS=-I$(PREFIX)/include -LDFLAGS=-L$(PREFIX)/lib +CPPFLAGS=-I$(PREFIX)/include -I./libpidutil +LDFLAGS=-L$(PREFIX)/lib -L./libpidutil LDLIBS=-lpidutil FLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 diff --git a/ifstatd.c b/ifstatd.c index e0012e3..96c2a6c 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -31,9 +31,14 @@ #include #include #include +#include + +#ifdef __linux__ +# define AF_LINK AF_PACKET +#else #include #include -#include +#endif #include #include @@ -54,6 +59,45 @@ #define CLOCK_REALTIME 0 #endif +#ifdef __linux__ +/* + * * Structure describing information about an interface + * * which may be of interest to management entities. + * */ +struct if_data { + /* generic interface information */ + u_char ifi_type; /* ethernet, tokenring, etc */ + u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ + u_char ifi_addrlen; /* media address length */ + u_char ifi_hdrlen; /* media header length */ + u_char ifi_link_state; /* current link state */ + u_char ifi_vhid; /* carp vhid */ + u_char ifi_baudrate_pf; /* baudrate power factor */ + u_char ifi_datalen; /* length of this data struct */ + u_long ifi_mtu; /* maximum transmission unit */ + u_long ifi_metric; /* routing metric (external only) */ + u_long ifi_baudrate; /* linespeed */ + /* volatile statistics */ + u_long ifi_ipackets; /* packets received on interface */ + u_long ifi_ierrors; /* input errors on interface */ + u_long ifi_opackets; /* packets sent on interface */ + u_long ifi_oerrors; /* output errors on interface */ + u_long ifi_collisions; /* collisions on csma interfaces */ + u_long ifi_ibytes; /* total number of octets received */ + u_long ifi_obytes; /* total number of octets sent */ + u_long ifi_imcasts; /* packets received via multicast */ + u_long ifi_omcasts; /* packets sent via multicast */ + u_long ifi_iqdrops; /* dropped on input, this interface */ + u_long ifi_noproto; /* destined for unsupported protocol */ + uint64_t ifi_hwassist; /* HW offload capabilities, see IFCAP */ + time_t ifi_epoch; /* uptime at attach or stat reset */ + struct timeval ifi_lastchange; /* time of last administrative change */ +#ifdef _IFI_OQDROPS + u_long ifi_oqdrops; /* dropped on output */ +#endif /* _IFI_OQFROPS */ +}; +#endif /* __linux __ */ + #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) #define RESOLUTION 10 From 46a5f87af71976bc0807523f3b64b92d043f99d7 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Tue, 27 Oct 2015 11:58:27 +0330 Subject: [PATCH 08/13] - more linux shims --- ifstatd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ifstatd.c b/ifstatd.c index 96c2a6c..d7a83b0 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -34,7 +34,8 @@ #include #ifdef __linux__ -# define AF_LINK AF_PACKET +#define AF_LINK AF_PACKET +#define _GNU_SOURCE #else #include #include From 811cb8e9a536a596ff0c4139ef3049b3ac3d0434 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 27 Oct 2015 12:00:26 +0330 Subject: [PATCH 09/13] - Fix Makefile on FreeBSD (does not honour CPPFLAGS) --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 960240a..b3a67c0 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ PREFIX?=/usr/local CPPFLAGS=-I$(PREFIX)/include -I./libpidutil LDFLAGS=-L$(PREFIX)/lib -L./libpidutil LDLIBS=-lpidutil -FLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 +CFLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 +CFLAGS+=$(CPPFLAGS) .PHONY: libpidutil get-deps From a0013d54bbf99db3f96a40ff5690493bb22cdad7 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Tue, 27 Oct 2015 12:02:53 +0330 Subject: [PATCH 10/13] - update compatibility info in README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35bf4f6..e729f3d 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ Interface statistics plugin for munin with [supersampling](http://guide.munin-monitoring.org/en/latest/plugin/supersampling.html) capability -NOTE: This plugin builds on FreeBSD and Darwin, but not tested on other paltforms. - NOTE: This program depends on [libpidutil](https://github.com/farrokhi/libpidutil) ## Installation @@ -38,3 +36,7 @@ NOTE: This program depends on [libpidutil](https://github.com/farrokhi/libpiduti service munin-node restart ``` +## Compatibility + +This plugin builds on FreeBSD, Darwin and Linux, and is tested on FreeBSD. Your milage may vary. Pleare report if build on other operating systems are broken or does not work as expected. + From 78a6040728520077d93243adfa54473ad3bf1ba9 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 6 Apr 2016 13:08:07 +0430 Subject: [PATCH 11/13] update copyright message --- LICENSE | 2 +- ifstatd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 2d1052b..53024e6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015, Babak Farrokhi +Copyright (c) 2016, Babak Farrokhi All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/ifstatd.c b/ifstatd.c index d7a83b0..bd78b74 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2015, Babak Farrokhi + * Copyright (c) 2016, Babak Farrokhi * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 8300ccce6de10fded4ddf0ca4c6aa0b9f8da7429 Mon Sep 17 00:00:00 2001 From: Mark Saad Date: Fri, 20 May 2016 22:34:11 -0400 Subject: [PATCH 12/13] Updated Makefile New version uses a building and linking phase to compile ifstatd_ --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b3a67c0..24e4708 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,16 @@ PREFIX?=/usr/local CPPFLAGS=-I$(PREFIX)/include -I./libpidutil LDFLAGS=-L$(PREFIX)/lib -L./libpidutil LDLIBS=-lpidutil -CFLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 +CFLAGS=-Wall -fno-strict-aliasing CFLAGS+=$(CPPFLAGS) .PHONY: libpidutil get-deps all: get-deps libpidutil ifstatd_ -ifstatd_: ifstatd.o +ifstatd_: + $(CC) $(CFLAGS) $(CPPFLAGS) -c ifstatd.c -o ifstatd.o + $(CC) $(CPPFLAGS) $(LDFLAGS) -g -o ifstatd_ ifstatd.o libpidutil/libpidutil.a get-deps: git submodule update --init From d400ffe8416c32bedf1755de7716ce7a616439e1 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Tue, 24 May 2016 18:58:32 +0430 Subject: [PATCH 13/13] make linux happy --- ifstatd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ifstatd.c b/ifstatd.c index bd78b74..b529c86 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE #include #include #include