This commit is contained in:
Babak Farrokhi 2016-08-10 12:37:43 +04:30
commit 371d73e9e8
7 changed files with 109 additions and 17 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "libpidutil"]
path = libpidutil
url = https://github.com/farrokhi/libpidutil.git

3
.travis.yml Normal file
View File

@ -0,0 +1,3 @@
language: c
compiler: clang
script: make

View File

@ -1,4 +1,4 @@
Copyright (c) 2015, Babak Farrokhi Copyright (c) 2016, Babak Farrokhi
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -1,14 +1,25 @@
PREFIX=/usr/local
INC=-I$(PREFIX)/include
LIB=-L$(PREFIX)/lib -lutil
FLAGS=-Wall -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3
CC?=cc CC?=cc
PREFIX?=/usr/local
CPPFLAGS=-I$(PREFIX)/include -I./libpidutil
LDFLAGS=-L$(PREFIX)/lib -L./libpidutil
LDLIBS=-lpidutil
CFLAGS=-Wall -fno-strict-aliasing
CFLAGS+=$(CPPFLAGS)
all: ifstatd_ .PHONY: libpidutil get-deps
ifstatd_: ifstatd.c Makefile all: get-deps libpidutil ifstatd_
$(CC) $(FLAGS) $(INC) $(LIB) ifstatd.c -o ifstatd_
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
libpidutil:
$(MAKE) -C libpidutil all
clean: clean:
rm -f ifstatd_ rm -f *.BAK *.log *.o *.a core ifstatd_
$(MAKE) -C libpidutil clean

View File

@ -1,11 +1,10 @@
[![Build Status](https://travis-ci.org/farrokhi/ifstatd.svg)](https://travis-ci.org/farrokhi/ifstatd)
# ifstatd_ plugin # 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 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 program depends on [libpidutil](https://github.com/farrokhi/libpidutil)
## Installation ## Installation
1. Clone this repo and build using `make` 1. Clone this repo and build using `make`
@ -37,3 +36,7 @@ NOTE: This plugin created for FreeBSD and might not run on other OSes
service munin-node restart 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.

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2015, Babak Farrokhi * Copyright (c) 2016, Babak Farrokhi
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#define _GNU_SOURCE
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
@ -31,9 +32,15 @@
#include <sys/file.h> #include <sys/file.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h>
#ifdef __linux__
#define AF_LINK AF_PACKET
#define _GNU_SOURCE
#else
#include <net/if_var.h> #include <net/if_var.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <ifaddrs.h> #endif
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
@ -46,7 +53,52 @@
#include <string.h> #include <string.h>
#include <sysexits.h> #include <sysexits.h>
#include <unistd.h> #include <unistd.h>
#include <libutil.h> #include <time.h>
#include <pidutil.h>
#ifdef __MACH__
#include <sys/time.h>
#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 IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
#define RESOLUTION 10 #define RESOLUTION 10
@ -70,6 +122,23 @@ char *pid_filename;
char *cache_filename; char *cache_filename;
struct pidfh *pfh; 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 * Prepare for a clean shutdown
*/ */
@ -172,6 +241,8 @@ wait_for(int seconds)
struct timespec tp; struct timespec tp;
bzero(&tp, sizeof(tp));
clock_gettime(CLOCK_REALTIME, &tp); clock_gettime(CLOCK_REALTIME, &tp);
time_t current_epoch = tp.tv_sec; time_t current_epoch = tp.tv_sec;

1
libpidutil Submodule

@ -0,0 +1 @@
Subproject commit 6c886a4584028724e80d8e5010126916114275aa