From b42518974dd57fefc785455e98686aea13002fe3 Mon Sep 17 00:00:00 2001 From: Kirk Webb Date: Wed, 27 Apr 2016 22:06:43 -0600 Subject: [PATCH] Fixes/updates to sdcollectd RRDtool support. Update mothership defs file to enable idle stats collection. --- clientside/sensors/slothd/GNUmakefile.in | 10 +++---- clientside/sensors/slothd/sdcollectd.c | 26 +++++++++--------- clientside/sensors/slothd/sdcollectd.h | 35 +++++++++++++++--------- configure | 9 +++++- configure.ac | 6 ++-- defs-default | 4 +++ 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/clientside/sensors/slothd/GNUmakefile.in b/clientside/sensors/slothd/GNUmakefile.in index 8e544e65c..2e2d0ea20 100644 --- a/clientside/sensors/slothd/GNUmakefile.in +++ b/clientside/sensors/slothd/GNUmakefile.in @@ -29,9 +29,9 @@ SLOTHD_DIR = unknownclient TBLIB = $(TESTBED_LIBOBJDIR)/libtb/libtb.a SD_USER = nobody -SD_GROUP = nobody SD_DATADIR = $(INSTALL_TOPDIR)/data/slothd_rrd -SD_USE_RRDTOOL = @SD_USE_RRDTOOL@ +SD_DOSTATS = @SDCOLLECTD_DOSTATS@ +SD_USE_RRDTOOL = @SDCOLLECTD_USE_RRDTOOL@ SBIN_SCRIPTS = sdisrunning sddeploy SDPROGS = sdcollectd$(EXE) slothd$(EXE) @@ -42,8 +42,8 @@ CC?=gcc ## For debug compilation ##CFLAGS+= -g CFLAGS+= -Wall -I${OBJDIR} -I/usr/local/include -I$(TESTBED_LIBSRCDIR)/libtb \ - -DCLIENT_BINDIR='"$(CLIENT_BINDIR)"' \ - -DLOG_TESTBED=$(LOG_TESTBED) + -DCLIENT_BINDIR='"$(CLIENT_BINDIR)"' -DDOSTATS=$(SD_DOSTATS) \ + -DLOG_TESTBED=$(LOG_TESTBED) -DRUNASUSER='"$(SD_USER)"' LDFLAGS+= $(LDSTATIC) -L${TESTBED_LIBOBJDIR}/libtb -L/usr/local/lib/mysql SDLIBS+= -ltb -lmysqlclient LIBS= $(MLIBS) @@ -94,7 +94,7 @@ boss-install: $(addprefix $(INSTALL_SBINDIR)/, $(SBIN_SCRIPTS) sdcollectd) webfe $(INSTALL_PROGRAM) $(SRCDIR)/digest-slothd $(INSTALL_DIR)/opsdir/sbin/digest-slothd $(INSTALL_PROGRAM) webfeedback $(INSTALL_LIBEXECDIR) ifeq ($(SD_USE_RRDTOOL),1) - $(SUDO) $(INSTALL) -d -m 0755 -o $(SD_USER) -g $(SD_GROUP) $(SD_DATADIR) + $(SUDO) $(INSTALL) -d -m 0755 -o $(SD_USER) $(SD_DATADIR) endif client-install: client diff --git a/clientside/sensors/slothd/sdcollectd.c b/clientside/sensors/slothd/sdcollectd.c index bae9df392..3cb71de8b 100644 --- a/clientside/sensors/slothd/sdcollectd.c +++ b/clientside/sensors/slothd/sdcollectd.c @@ -51,7 +51,7 @@ int parse_args(int argc, char **argv) { char ch; /* setup defaults. */ - opts->dostats = 0; + opts->dostats = DOSTATS; opts->debug = 0; opts->port = SDCOLLECTD_PORT; @@ -59,7 +59,6 @@ int parse_args(int argc, char **argv) { switch (ch) { case 's': - info("Populating statistics tables/files"); opts->dostats = 1; break; @@ -111,6 +110,10 @@ int main(int argc, char **argv) { error("Error processing arguments, exiting.\n"); exit(1); } + + if (opts->dostats) { + info("Populating statistics tables/files"); + } /* clear, and initialize inet sockaddr */ bzero(&servaddr, sizeof(struct sockaddr_in)); @@ -491,11 +494,7 @@ void UpdateDBRecord(IDLE_DATA *iddata) { void PutDBStats(IDLE_DATA *iddata) { int i; time_t now = time(NULL); - char curstamp[100]; - char tmpstr[(NUMACTTYPES+1)*sizeof(curstamp)]; - char *actstr[] = ACTSTRARRAY; - sprintf(curstamp, "FROM_UNIXTIME(%lu)", (long unsigned int)now); if (!mydb_update("INSERT INTO node_idlestats VALUES ('%s', FROM_UNIXTIME(%lu), FROM_UNIXTIME(%lu), %f, %f, %f)", iddata->id, now, @@ -528,6 +527,7 @@ void PutRRDStats(IDLE_DATA *iddata) { time_t now = time(NULL); char rrdfile[sizeof(SD_RRD_STORAGEDIR) + TBDB_FLEN_NODEID + MACADDRLEN + 7]; char updstr[100]; + const char *updarr[] = {updstr}; rrd_clear_error(); /* Precautionary */ @@ -538,7 +538,7 @@ void PutRRDStats(IDLE_DATA *iddata) { if (rrd_create_r(rrdfile, SD_RRD_STEPSIZE, now - 10, - sizeof(SD_RRD_NODE_LAYOUT), + sizeof(SD_RRD_NODE_LAYOUT)/sizeof(char*), SD_RRD_NODE_LAYOUT) != 0) { error("Failed to create RRD file for node %s: %s", iddata->id, @@ -554,8 +554,8 @@ void PutRRDStats(IDLE_DATA *iddata) { /* Update RRD with new data. */ sprintf(updstr, "N:%lu:%f:%f:%f", iddata->mis, iddata->l1m, iddata->l5m, iddata->l15m); - if (rrd_update_r(rrdfile, NULL, 1, &updstr) != 0) { - error("Failed to update RRD file for node: %s: %s", + if (rrd_update_r(rrdfile, NULL, 1, updarr) != 0) { + error("Failed to update RRD file for node %s: %s", iddata->id, rrd_get_error()); return; @@ -570,7 +570,7 @@ void PutRRDStats(IDLE_DATA *iddata) { if (rrd_create_r(rrdfile, SD_RRD_STEPSIZE, now - 10, - sizeof(SD_RRD_IFACE_LAYOUT), + sizeof(SD_RRD_IFACE_LAYOUT)/sizeof(char*), SD_RRD_IFACE_LAYOUT) != 0) { error("Failed to create RRD file for node/iface %s/%s: %s", iddata->id, iddata->ifaces[i], @@ -586,9 +586,9 @@ void PutRRDStats(IDLE_DATA *iddata) { sprintf(updstr, "N:%lu:%lu", iddata->ifaces[i].ipkts, iddata->ifaces[i].opkts); - if (rrd_update_r(rrdfile, NULL, 1, &updstr) != 0) { - error("Failed to update RRD file for node: %s: %s", - iddata->id, + if (rrd_update_r(rrdfile, NULL, 1, updarr) != 0) { + error("Failed to update RRD file for node/iface %s/%s: %s", + iddata->id, iddata->ifaces[i].mac, rrd_get_error()); return; } diff --git a/clientside/sensors/slothd/sdcollectd.h b/clientside/sensors/slothd/sdcollectd.h index 77e0655f8..e5fab5773 100644 --- a/clientside/sensors/slothd/sdcollectd.h +++ b/clientside/sensors/slothd/sdcollectd.h @@ -42,16 +42,15 @@ #include #include #include +#include "config.h" #include "tbdb.h" #include "log.h" #define SDPROTOVERS 2 -#define SDCOLLECTD_PORT 8509 #define NODENAMESIZE 100 #define BUFSIZE 1500 #define MAXNUMIFACES 10 #define MACADDRLEN 12 -#define RUNASUSER "nobody" #define MAXKEYSIZE 10 #define MAXVALUESIZE 40 @@ -67,30 +66,40 @@ #define NUMACTTYPES 4 #define ACTSTRARRAY {"last_tty_act", "last_cpu_act", "last_net_act", "last_ext_act"} +#ifndef SDCOLLECTD_PORT +#define SDCOLLECTD_PORT 8509 +#endif + +#ifndef RUNASUSER +#define RUNASUSER "nobody" +#endif + +#ifndef DOSTATS +#define DOSTATS 0 +#endif + #ifdef USE_RRDTOOL #include -#define SD_RRD_STORAGEDIR TBROOT "/slothd_rrd" +#define SD_RRD_STORAGEDIR TBROOT "/data/slothd_rrd" #define SD_RRD_STEPSIZE 300 /* five minutes. */ -char *SD_RRD_NODE_LAYOUT[] = { +const char *SD_RRD_NODE_LAYOUT[] = { "DS:last_tty:DERIVE:600:0:U", "DS:load_1min:GAUGE:600:0:U", "DS:load_5min:GAUGE:600:0:U", "DS:load_15min:GAUGE:600:0:U", - "RRA:MAX:0.5:5m:1d", - "RRA:AVERAGE:0.5:5m:1d", - "RRA:MAX:0.5:1h:1w", - "RRA:AVERAGE:0.5:1h:1w" + "RRA:AVERAGE:0.5:1:288", /* 5m samples for a day. */ + "RRA:MAX:0.5:12:168", /* Max of 12 x 5m samples (1 hr), keep 1w. */ + "RRA:AVERAGE:0.5:12:168" /* Avg of 12 x 5m samples (1 hr), keep 1w. */ }; -char *SD_RRD_IFACE_LAYOUT[] = { +const char *SD_RRD_IFACE_LAYOUT[] = { "DS:ipkts:DERIVE:600:0:U", "DS:opkts:DERIVE:600:0:U", - "RRA:MAX:0.5:5m:1d", - "RRA:AVERAGE:0.5:5m:1d", - "RRA:MAX:0.5:1h:1w", - "RRA:AVERAGE:0.5:1h:1w" + "RRA:AVERAGE:0.5:1:288", /* 5m samples for a day. */ + "RRA:MAX:0.5:12:168", /* Max of 12 x 5m samples (1 hr), keep 1w. */ + "RRA:AVERAGE:0.5:12:168" /* Avg of 12 x 5m samples (1 hr), keep 1w. */ }; #endif diff --git a/configure b/configure index 1898c13ee..2d33aa532 100755 --- a/configure +++ b/configure @@ -676,8 +676,10 @@ TBROBOCOPSEMAIL_NOSLASH TBROBOCOPSEMAIL TBOPSEMAIL_NOSLASH TBOPSEMAIL -CLUSTER_PUBSUBD_PORT +SDCOLLECTD_USE_RRDTOOL +SDCOLLECTD_DOSTATS EXPIRE_PASSWORDS +CLUSTER_PUBSUBD_PORT CLUSTER_PORTAL ATTENUATOR BS_IQN_PREFIX @@ -5014,6 +5016,9 @@ done + + + @@ -5184,6 +5189,8 @@ ATTENUATOR="" CLUSTER_PORTAL="" CLUSTER_PUBSUBD_PORT="" EXPIRE_PASSWORDS=1 +SDCOLLECTD_DOSTATS=0 +SDCOLLECTD_USE_RRDTOOL=0 # # XXX You really don't want to change these! diff --git a/configure.ac b/configure.ac index 7b35c3657..0c44dd321 100644 --- a/configure.ac +++ b/configure.ac @@ -317,7 +317,8 @@ AC_SUBST(ATTENUATOR) AC_SUBST(CLUSTER_PORTAL) AC_SUBST(CLUSTER_PUBSUBD_PORT) AC_SUBST(EXPIRE_PASSWORDS) -AC_SUBST(SD_USE_RRDTOOL) +AC_SUBST(SDCOLLECTD_DOSTATS) +AC_SUBST(SDCOLLECTD_USE_RRDTOOL) # # Offer both versions of the email addresses that have the @ escaped @@ -485,7 +486,8 @@ ATTENUATOR="" CLUSTER_PORTAL="" CLUSTER_PUBSUBD_PORT="" EXPIRE_PASSWORDS=1 -SD_USE_RRDTOOL=0 +SDCOLLECTD_DOSTATS=0 +SDCOLLECTD_USE_RRDTOOL=0 # # XXX You really don't want to change these! diff --git a/defs-default b/defs-default index 41ef04156..058cc6c59 100644 --- a/defs-default +++ b/defs-default @@ -116,6 +116,10 @@ CLUSTER_PORTAL="boss.emulab.net" CLUSTER_PUBSUBD_PORT=16506 # Mobile networking support (PhantomNet) MOBILESUPPORT=1 +# Do not set these without talking to Utah! +# Collect idle statistics by default, and store in RRD files. +SDCOLLECTD_DOSTATS=1 +SDCOLLECTD_USE_RRDTOOL=1 # # SSL Certificate stuff. Used to customize config files in ssl directory. -- GitLab