Browse Source

Add ./tarball_archive/symon-2.77.tar.gz

Wictor Lund 3 years ago
parent
commit
193e778b62

+ 22 - 1
symon/CHANGELOG

@@ -1,3 +1,24 @@
+29/11/2007 - 2.77
+
+   - symon/symux -t can now be used to check configuration files before running
+     in anger.
+
+   - symon now also calculates maximum message size; with symux using twice the
+     calculated value to ensure that configuration errors between
+     sy[mon|mux].conf are detected in the logs. Both enforce maximum message =
+     sizeof(udp payload).
+
+   - Martin van der Werff donated the Linux/sm_df probe.
+
+   - symux/c_smrrds.sh/syweb now all think sensor probes are called
+     sensor_*. (Daniel Spizak, Evgeniy Sudyr)
+
+   - pfq probes must be specified as pfq(interface/queue) in symon and are
+     treated as pfq_interface_symon.rrd by symux.
+
+   - platform/Linux/sm_mem modified to better reflect OpenBSD's idea of the
+     vm_meter stats.
+
 05/07/2007 - 2.76
 
    - symux/readconf.c resolve from host, but discard result. (Henning Brauer)
@@ -511,4 +532,4 @@
 29/09/2001 - Lexer had trouble dealing with ip-addresses. Cleaned up the number
              parsing code and removed a second comment reader.
 
-$Id: CHANGELOG,v 1.66 2007/07/09 11:46:00 dijkstra Exp $
+$Id: CHANGELOG,v 1.72 2007/11/29 13:55:30 dijkstra Exp $

+ 3 - 3
symon/Makefile.inc

@@ -1,12 +1,12 @@
-# $Id: Makefile.inc,v 1.36 2007/07/05 12:16:07 dijkstra Exp $
+# $Id: Makefile.inc,v 1.38 2007/10/29 14:59:43 dijkstra Exp $
 
-V=2.76
+V=2.77
 OS!=uname -s
 
 AR?=	ar
 CC?=	cc
 .ifdef DEBUG
-CFLAGS+=-g -Wall
+CFLAGS=-g -Wall
 .else
 CFLAGS+=-Wall
 .endif

+ 4 - 2
symon/TODO

@@ -5,13 +5,15 @@ TODO:
      Pailloncy for the suggestion.
 
 - rewrite sm_proc.c, don't count shared pages twice
-- remove mon packet limit
 - check shared memory for hackable bugs. (master should only write, clients
   should only read. clients should check incoming data for sanity.)
 
+- check for availability of rrd before compilation
+- make user/group part of makefile.inc
+
 == longer term
 - change rrd to accommodate batch updates
 - write a muxer that supports unix pipes
 - test framework
 
-$Id: TODO,v 1.28 2007/02/11 20:07:31 dijkstra Exp $
+$Id: TODO,v 1.30 2007/11/29 13:59:03 dijkstra Exp $

+ 89 - 5
symon/lib/data.c

@@ -1,4 +1,4 @@
-/* $Id: data.c,v 1.32 2007/04/20 18:53:22 dijkstra Exp $ */
+/* $Id: data.c,v 1.34 2007/11/29 19:36:03 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2007 Willem Dijkstra
@@ -862,9 +862,11 @@ free_muxlist(struct muxlist * mul)
         if (p->port != NULL)
             xfree(p->port);
         if (p->clientsocket)
-		close(p->clientsocket);
+            close(p->clientsocket);
         if (p->symuxsocket)
-		close(p->symuxsocket);
+            close(p->symuxsocket);
+        if (p->packet.data)
+            xfree(p->packet.data);
 
         for (i = 0; i < AF_MAX; i++)
             if (p->symonsocket[i])
@@ -921,9 +923,48 @@ free_sourcelist(struct sourcelist * sol)
         p = np;
     }
 }
-/* Calculate maximum buffer space needed for a single symon hit */
+/* Calculate maximum buffer space needed for a single symon measurement run,
+ * excluding the packet header
+ */
+int
+bytelen_streamlist(struct streamlist * sl)
+{
+    struct stream *stream;
+    int len = 0;
+    int i;
+
+    SLIST_FOREACH(stream, sl, streams) {
+        len += 1; /* type */
+        len += strlen(stream->arg) + 1; /* arg */
+        for (i = 0; streamform[stream->type].form[i] != 0; i++) /* packedstream */
+            len += bytelenvar(streamform[stream->type].form[i]);
+    }
+
+    return len;
+}
+/* Calculate maximum buffer symux space needed for a single symon hit,
+ * excluding the packet header
+ */
 int
-calculate_churnbuffer(struct sourcelist * sol)
+bytelen_sourcelist(struct sourcelist * sol)
+{
+    struct source *source;
+    int maxlen;
+    int len;
+
+    len = maxlen = 0;
+
+    /* determine maximum packet size for a single source */
+    SLIST_FOREACH(source, sol, sources) {
+        len = bytelen_streamlist(&source->sl);
+        if (len > maxlen)
+            maxlen = len;
+    }
+    return maxlen;
+}
+/* Calculate maximum buffer symux space needed for a single symon hit */
+int
+strlen_sourcelist(struct sourcelist * sol)
 {
     char buf[_POSIX2_LINE_MAX];
     struct source *source;
@@ -952,6 +993,49 @@ calculate_churnbuffer(struct sourcelist * sol)
     }
     return maxlen;
 }
+void
+init_symon_packet(struct mux * mux)
+{
+    if (mux->packet.data)
+        xfree(mux->packet.data);
+
+    mux->packet.size = sizeof(struct symonpacketheader) +
+        bytelen_streamlist(&mux->sl);
+    if (mux->packet.size > SYMON_MAXPACKET) {
+        warning("transport max packet size is not enough to transport all streams");
+        mux->packet.size = SYMON_MAXPACKET;
+    }
+    mux->packet.data = xmalloc(mux->packet.size);
+    bzero(mux->packet.data, mux->packet.size);
+
+    debug("symon packet size=%d", mux->packet.size);
+}
+void
+init_symux_packet(struct mux * mux)
+{
+    if (mux->packet.data)
+        xfree(mux->packet.data);
+
+    /* determine optimal packet size */
+    mux->packet.size = sizeof(struct symonpacketheader) +
+        bytelen_sourcelist(&mux->sol);
+    if (mux->packet.size > SYMON_MAXPACKET) {
+        warning("transport max packet size is not enough to transport all streams");
+        mux->packet.size = SYMON_MAXPACKET;
+    }
+
+    /* multiply by 2 to allow users to detect symon.conf/symux.conf stream
+     * configuration differences
+     */
+    mux->packet.size = ((mux->packet.size << 1) > SYMON_MAXPACKET)?
+        SYMON_MAXPACKET:
+        mux->packet.size << 1;
+
+    mux->packet.data = xmalloc(mux->packet.size);
+    bzero(mux->packet.data, mux->packet.size);
+
+    debug("symux packet size=%d", mux->packet.size);
+}
 /* Big endian CRC32 */
 u_int32_t
 crc32(const void *buf, unsigned int len)

+ 10 - 6
symon/lib/data.h

@@ -1,4 +1,4 @@
-/* $Id: data.h,v 1.30 2007/02/11 20:07:31 dijkstra Exp $ */
+/* $Id: data.h,v 1.31 2007/11/29 13:13:17 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2007 Willem Dijkstra
@@ -97,9 +97,10 @@ struct symonpacketheader {
 
 struct symonpacket {
     struct symonpacketheader header;
-    char data[_POSIX2_LINE_MAX];
+    u_int32_t offset;
+    u_int32_t size;
+    char *data;
 };
-
 /* The difference between a stream and a packed stream:
  * - A stream ties stream information to a file.
  * - A packed stream is the measured data itself
@@ -129,7 +130,6 @@ struct mux {
     char *port;
     char *localaddr;
     struct sourcelist sol;
-    int offset;
     int clientsocket;           /* symux; incoming tcp connections */
     int symonsocket[AF_MAX];    /* symux; incoming symon data */
     int symuxsocket;            /* symon; outgoing data to mux */
@@ -305,8 +305,8 @@ struct packedstream {
 /* prototypes */
 __BEGIN_DECLS
 char *type2str(const int);
-int token2type(const int);
-int calculate_churnbuffer(struct sourcelist *);
+int bytelen_sourcelist(struct sourcelist *);
+int bytelen_streamlist(struct streamlist *);
 int getheader(char *, struct symonpacketheader *);
 int ps2strn(struct packedstream *, char *, int, int);
 int setheader(char *, struct symonpacketheader *);
@@ -314,10 +314,12 @@ int snpack(char *, int, char *, int, ...);
 int snpack1(char *, int, char *, int, ...);
 int snpack2(char *, int, char *, int, ...);
 int snpackx(size_t, char *, int, char *, int, va_list);
+int strlen_sourcelist(struct sourcelist *);
 int strlentype(int);
 int sunpack1(char *, struct packedstream *);
 int sunpack2(char *, struct packedstream *);
 int sunpackx(size_t, char *, struct packedstream *);
+int token2type(const int);
 struct mux *add_mux(struct muxlist *, char *);
 struct mux *find_mux(struct muxlist *, char *);
 struct mux *rename_mux(struct muxlist *, struct mux *, char *);
@@ -333,5 +335,7 @@ void free_muxlist(struct muxlist *);
 void free_sourcelist(struct sourcelist *);
 void free_streamlist(struct streamlist *);
 void init_crc32();
+void init_symon_packet(struct mux *);
+void init_symux_packet(struct mux *);
 __END_DECLS
 #endif                          /* _SYMON_LIB_DATA_H */

+ 3 - 3
symon/lib/net.h

@@ -1,7 +1,7 @@
-/* $Id: net.h,v 1.15 2007/02/11 20:07:31 dijkstra Exp $ */
+/* $Id: net.h,v 1.16 2007/11/29 13:13:17 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,7 @@
 #include <sys/types.h>
 
 #define SYMUX_PORT  "2100"      /* default symux port */
-
+#define SYMON_MAXPACKET 65515   /* udp packet max payload 65Kb - 20 byte header */
 extern char res_host[];
 extern char res_service[];
 extern struct sockaddr_storage res_addr;

+ 2 - 1
symon/platform/FreeBSD/Makefile.inc

@@ -1,4 +1,5 @@
-# $Id: Makefile.inc,v 1.4 2006/12/19 22:31:40 dijkstra Exp $
+# $Id: Makefile.inc,v 1.5 2007/11/29 13:59:16 dijkstra Exp $
 SYMON_LIBS=-lkvm -ldevstat
+SYMUX_LIBS=-lm
 SYSCONFDIR=${PREFIX}/etc
 BINDIR=bin

+ 6 - 1
symon/platform/Linux/platform.h

@@ -1,4 +1,4 @@
-/* $Id: platform.h,v 1.7 2007/07/09 13:19:46 dijkstra Exp $ */
+/* $Id: platform.h,v 1.8 2007/07/16 07:37:11 dijkstra Exp $ */
 
 #ifndef _CONF_LINUX_H
 #define _CONF_LINUX_H
@@ -36,6 +36,8 @@ union semun {
 #define CP_SOFTIRQ   6
 #define CP_STEAL     7
 
+#define MAX_PATH_LEN 1024
+
 union stream_parg {
     struct {
         int64_t time[CPUSTATES];
@@ -44,6 +46,9 @@ union stream_parg {
         int64_t states[CPUSTATES];
         char name[6];
     } cp;
+    struct {
+        char mountpath[MAX_PATH_LEN];
+    } df;
 };
 
 #endif

+ 111 - 0
symon/platform/Linux/sm_df.c

@@ -0,0 +1,111 @@
+/* $Id: sm_df.c,v 1.4 2007/11/29 07:47:51 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2007 Martin van der Werff
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *    - Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Get current df statistics and return them in symon_buf as
+ *
+ *   blocks : bfree : bavail : files : ffree : 0 : 0
+ *   syncwrites : asyncwrites are not available on linux
+ */
+
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <mntent.h>
+#include <string.h>
+#include <sys/vfs.h>
+
+#include "conf.h"
+#include "error.h"
+#include "symon.h"
+
+void
+init_df(struct stream *st)
+{
+    FILE * fp = setmntent("/etc/mtab", "r");
+    struct mntent *mount;
+
+    while ((mount = getmntent(fp))) {
+	if (strncmp(mount->mnt_fsname, "/dev/", 5) == 0) {
+            if (strcmp(mount->mnt_fsname + 5, st->arg) == 0) {
+                strlcpy(st->parg.df.mountpath, mount->mnt_dir, sizeof(st->parg.df.mountpath));
+                info("started module df(%.200s) --> %.200s", st->arg, st->parg.df.mountpath);
+                endmntent(fp);
+		return;
+            }
+	}
+    }
+
+    endmntent(fp);
+
+    strlcpy(st->parg.df.mountpath, "/", sizeof(st->parg.df.mountpath));
+
+    info("failed to find (%.200s) - started module df for /", st->arg);
+}
+
+void
+gets_df()
+{
+}
+
+/*
+ * from src/bin/df.c:
+ * Convert statfs returned filesystem size into BLOCKSIZE units.
+ * Attempts to avoid overflow for large filesystems.
+ */
+u_int64_t
+fsbtoblk(u_int64_t num, u_int64_t fsbs, u_int64_t bs)
+{
+    return (((fsbs) != 0 && (fsbs) < (bs)) ? 
+        (num) / ((bs) / (fsbs)) : 
+        (num) * ((fsbs) / (bs)));
+}
+
+int
+get_df(char *symon_buf, int maxlen, struct stream *st)
+{
+    struct statfs buf;
+
+    if (statfs(st->parg.df.mountpath, &buf) == 0 ) {
+        return snpack(symon_buf, maxlen, st->arg, MT_DF,
+                      (u_int64_t)fsbtoblk(buf.f_blocks, buf.f_bsize, SYMON_DFBLOCKSIZE),
+                      (u_int64_t)fsbtoblk(buf.f_bfree, buf.f_bsize, SYMON_DFBLOCKSIZE),
+                      (u_int64_t)fsbtoblk(buf.f_bavail, buf.f_bsize, SYMON_DFBLOCKSIZE),
+                      (u_int64_t)buf.f_files,
+                      (u_int64_t)buf.f_ffree,
+                      (u_int64_t)0,
+                      (u_int64_t)0);
+    }
+
+    warning("df(%.200s) failed", st->arg);
+    return 0;
+}

+ 2 - 1
symon/platform/Linux/sm_mem.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mem.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
+/* $Id: sm_mem.c,v 1.5 2007/10/29 16:14:37 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 Harm Schotanus
@@ -124,6 +124,7 @@ get_mem(char *symon_buf, int maxlen, struct stream *st)
     me_stats[0] = ktob(mem_getitem("Active"));
     me_stats[1] = ktob(mem_getitem("MemTotal"));
     me_stats[2] = ktob(mem_getitem("MemFree"));
+    me_stats[1] -= me_stats[2];
     me_stats[3] = ktob(mem_getitem("SwapFree"));
     me_stats[4] = ktob(mem_getitem("SwapTotal"));
 

+ 8 - 5
symon/symon/symon.8

@@ -35,7 +35,7 @@
 .Nd system monitor
 .Sh SYNOPSIS
 .Nm
-.Op Fl duv
+.Op Fl dtuv
 .Op Fl f Ar filename
 .Pp
 .Sh DESCRIPTION
@@ -77,6 +77,8 @@ Read configuration from
 .Ar filename
 instead of
 .Pa /etc/symon.conf .
+.It Fl t
+Test configuration file and exit.
 .It Fl u
 By default
 .Nm
@@ -171,10 +173,11 @@ does not check whether resources mentioned in
 exist.
 .Pp
 .Sh AUTHOR
-Willem Dijkstra <wpd@xs4all.nl>. Daniel Hartmeier helped to port to big-endian
-architectures. Matthew Gream helped to port symon to other BSD platforms.
+Willem Dijkstra <wpd@xs4all.nl>. \%Daniel \%Hartmeier helped to port to big-endian
+architectures. \%Matthew \%Gream helped to port symon to other BSD platforms.
 .Pp
-Port contributors: Marc Balmer, Matthew Gream, Daniel Hartmeier, J. Martin
-Petersen, Fredrik Soderblom and Harm Schotanus.
+Port contributors: \%Marc \%Balmer, \%Matthew \%Gream, \%Daniel \%Hartmeier,
+\%Constantine A. \%Murenin, J. \%Martin \%Petersen, \%Fredrik \%Soderblom,
+\%Harm \%Schotanus and \%Martin van der \%Werff.
 .Sh SEE ALSO
 .Xr symux 8

+ 15 - 3
symon/symon/symon.c

@@ -1,4 +1,4 @@
-/* $Id: symon.c,v 1.47 2007/04/20 18:53:27 dijkstra Exp $ */
+/* $Id: symon.c,v 1.49 2007/11/29 13:55:30 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2007 Willem Dijkstra
@@ -65,6 +65,7 @@ __END_DECLS
 
 int flag_unsecure = 0;
 int flag_hup = 0;
+int flag_testconf = 0;
 int symon_interval = SYMON_DEFAULT_INTERVAL;
 
 /* map stream types to inits and getters */
@@ -187,7 +188,7 @@ main(int argc, char *argv[])
 
     cfgpath = SYMON_CONFIG_FILE;
 
-    while ((ch = getopt(argc, argv, "dvuf:")) != -1) {
+    while ((ch = getopt(argc, argv, "df:tuv")) != -1) {
         switch (ch) {
         case 'd':
             flag_debug = 1;
@@ -197,6 +198,10 @@ main(int argc, char *argv[])
             cfgpath = xstrdup(optarg);
             break;
 
+        case 't':
+            flag_testconf = 1;
+            break;
+
         case 'u':
             flag_unsecure = 1;
             break;
@@ -204,7 +209,7 @@ main(int argc, char *argv[])
         case 'v':
             info("symon version %s", SYMON_VERSION);
         default:
-            info("usage: %s [-d] [-u] [-v] [-f cfgfile]", __progname);
+            info("usage: %s [-d] [-t] [-u] [-v] [-f cfgfile]", __progname);
             exit(EX_USAGE);
         }
     }
@@ -212,6 +217,11 @@ main(int argc, char *argv[])
     if (!read_config_file(&mul, cfgpath))
         fatal("configuration file contained errors - aborting");
 
+    if (flag_testconf) {
+        info("%s: ok", cfgpath);
+        exit(EX_OK);
+    }
+
     set_stream_use(&mul);
 
     /* open resources that might not be available after privilege drop */
@@ -254,6 +264,7 @@ main(int argc, char *argv[])
 
     /* init modules */
     SLIST_FOREACH(mux, &mul, muxes) {
+        init_symon_packet(mux);
         connect2mux(mux);
         SLIST_FOREACH(stream, &mux->sl, streams) {
             (streamfunc[stream->type].init) (stream);
@@ -291,6 +302,7 @@ main(int argc, char *argv[])
 
                     /* init modules */
                     SLIST_FOREACH(mux, &mul, muxes) {
+                        init_symon_packet(mux);
                         connect2mux(mux);
                         SLIST_FOREACH(stream, &mux->sl, streams) {
                             (streamfunc[stream->type].init) (stream);

+ 17 - 17
symon/symon/symonnet.c

@@ -1,7 +1,7 @@
-/* $Id: symonnet.c,v 1.16 2007/02/11 20:07:32 dijkstra Exp $ */
+/* $Id: symonnet.c,v 1.17 2007/11/29 13:13:18 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -72,10 +72,10 @@ connect2mux(struct mux * mux)
 void
 send_packet(struct mux * mux)
 {
-    if (sendto(mux->symuxsocket, (void *) &mux->packet.data,
-               mux->offset, 0, (struct sockaddr *) & mux->sockaddr,
+    if (sendto(mux->symuxsocket, mux->packet.data,
+               mux->packet.offset, 0, (struct sockaddr *) & mux->sockaddr,
                SS_LEN(&mux->sockaddr))
-        != mux->offset) {
+        != mux->packet.offset) {
         mux->senderr++;
     }
 
@@ -91,36 +91,36 @@ prepare_packet(struct mux * mux)
 {
     time_t t = time(NULL);
 
-    bzero(&mux->packet, sizeof(mux->packet));
+    bzero(mux->packet.data, mux->packet.size);
     mux->packet.header.symon_version = SYMON_PACKET_VER;
     mux->packet.header.timestamp = t;
 
     /* symonpacketheader is always first stream */
-    mux->offset =
-        setheader((char *) &mux->packet.data,
+    mux->packet.offset =
+        setheader(mux->packet.data,
                   &mux->packet.header);
 }
 /* Put a stream into the packet for a mux */
 void
 stream_in_packet(struct stream * stream, struct mux * mux)
 {
-    mux->offset +=
-    (streamfunc[stream->type].get)      /* call getter of stream */
-    (&mux->packet.data[mux->offset],    /* packet buffer */
-     sizeof(mux->packet.data) - mux->offset,    /* maxlen */
-     stream);
+    mux->packet.offset +=
+        (streamfunc[stream->type].get)      /* call getter of stream */
+        (mux->packet.data + mux->packet.offset,    /* packet buffer */
+         mux->packet.size - mux->packet.offset,    /* maxlen */
+         stream);
 }
 /* Ready a packet for transmission, set length and crc */
 void
 finish_packet(struct mux * mux)
 {
-    mux->packet.header.length = mux->offset;
+    mux->packet.header.length = mux->packet.offset;
     mux->packet.header.crc = 0;
 
     /* fill in correct header with crc = 0 */
-    setheader((char *) &mux->packet.data, &mux->packet.header);
+    setheader(mux->packet.data, &mux->packet.header);
 
     /* fill in correct header with crc */
-    mux->packet.header.crc = crc32(&mux->packet.data, mux->offset);
-    setheader((char *) &mux->packet.data, &mux->packet.header);
+    mux->packet.header.crc = crc32(mux->packet.data, mux->packet.offset);
+    setheader(mux->packet.data, &mux->packet.header);
 }

+ 2 - 2
symon/symux/c_smrrds.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
-# $Id: c_smrrds.sh,v 1.36 2007/07/05 12:16:07 dijkstra Exp $
+# $Id: c_smrrds.sh,v 1.37 2007/09/25 14:33:21 dijkstra Exp $
 
 #
 # Copyright (c) 2001-2006 Willem Dijkstra
@@ -163,7 +163,7 @@ df_*.rrd)
 	DS:asyncwrites:COUNTER:$INTERVAL:U:U
     ;;
 
-sensor*.rrd)
+sensor_*.rrd)
     # Build sensor file
     create_rrd $i \
 	DS:value:GAUGE:$INTERVAL:-U:U

+ 19 - 7
symon/symux/readconf.c

@@ -1,7 +1,7 @@
-/* $Id: readconf.c,v 1.31 2007/02/11 20:07:32 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.33 2007/10/29 14:59:43 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2005 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -55,10 +55,12 @@ const char *default_symux_port = SYMUX_PORT;
 int
 insert_filename(char *path, int maxlen, int type, char *args)
 {
+    int i, result;
     char *ts;
     char *ta;
+    char *fta;
 
-    ts = ta = NULL;
+    fta = ts = ta = NULL;
 
     switch (type) {
     case MT_CPU:
@@ -106,7 +108,7 @@ insert_filename(char *path, int maxlen, int type, char *args)
         ta = args;
         break;
     case MT_SENSOR:
-        ts = "sensor";
+        ts = "sensor_";
         ta = args;
         break;
     default:
@@ -115,11 +117,21 @@ insert_filename(char *path, int maxlen, int type, char *args)
         return 0;
     }
 
-    if ((snprintf(path, maxlen, "/%s%s.rrd", ts, ta)) >= maxlen) {
-        return 0;
+    /* ensure that no '/' remain in args */
+    fta = xstrdup(ta);
+
+    for (i = 0; i < strlen(fta); i++) {
+        if (fta[i] == '/') fta[i] = '_';
+    }
+
+    if ((snprintf(path, maxlen, "/%s%s.rrd", ts, fta)) >= maxlen) {
+        result = 0;
     } else {
-        return 1;
+        result = 1;
     }
+
+    xfree(fta);
+    return result;
 }
 /* mux <host> (port|,| ) <number> */
 int

+ 8 - 5
symon/symux/symux.8

@@ -35,7 +35,7 @@
 .Nd symon stream multiplexer
 .Sh SYNOPSIS
 .Nm
-.Op Fl dlv
+.Op Fl dltv
 .Op Fl f Ar filename
 .Pp
 .Sh DESCRIPTION
@@ -84,6 +84,8 @@ instead of
 .Pa /etc/symux.conf .
 .It Fl l
 List rrd files found in active configuration.
+.It Fl t
+Test configuration file and exit.
 .It Fl v
 Show version.
 .El
@@ -331,10 +333,11 @@ to lockup while rrdupdate is updating the rrd file.
 .Nm
 will be unresponsive during this process.
 .Sh AUTHOR
-Willem Dijkstra <wpd@xs4all.nl>. Daniel Hartmeier helped to port to big-endian
-architectures. Matthew Gream helped to port symon to other BSD platforms.
+Willem Dijkstra <wpd@xs4all.nl>. \%Daniel \%Hartmeier helped to port to big-endian
+architectures. \%Matthew \%Gream helped to port symon to other BSD platforms.
 .Pp
-Port contributors: Marc Balmer, Matthew Gream, Daniel Hartmeier, J. Martin
-Petersen, Fredrik Soderblom and Harm Schotanus.
+Port contributors: \%Marc \%Balmer, \%Matthew \%Gream, \%Daniel \%Hartmeier,
+\%Constantine A. \%Murenin, J. \%Martin \%Petersen, \%Fredrik \%Soderblom,
+\%Harm \%Schotanus and \%Martin van der \%Werff.
 .Sh SEE ALSO
 .Xr symon 8

+ 27 - 14
symon/symux/symux.c

@@ -1,7 +1,7 @@
-/* $Id: symux.c,v 1.39 2007/07/09 11:18:01 dijkstra Exp $ */
+/* $Id: symux.c,v 1.41 2007/11/29 13:55:30 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2006 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -63,6 +63,7 @@ void signalhandler(int);
 __END_DECLS
 
 int flag_hup = 0;
+int flag_testconf = 0;
 fd_set fdset;
 int maxfd;
 
@@ -97,10 +98,9 @@ huphandler(int s)
 int
 main(int argc, char *argv[])
 {
-    struct symonpacket packet;
     struct packedstream ps;
     char *cfgfile;
-    char *cfgpath;
+    char *cfgpath = NULL;
     char *stringbuf;
     char *stringptr;
     int maxstringlen;
@@ -129,11 +129,12 @@ main(int argc, char *argv[])
 
     cfgfile = SYMUX_CONFIG_FILE;
 
-    while ((ch = getopt(argc, argv, "df:lv")) != -1) {
+    while ((ch = getopt(argc, argv, "df:ltv")) != -1) {
         switch (ch) {
         case 'd':
             flag_debug = 1;
             break;
+
         case 'f':
             if (optarg && optarg[0] != '/') {
                 /* cfg path needs to be absolute, we will be a daemon soon */
@@ -154,9 +155,15 @@ main(int argc, char *argv[])
             } else
                 cfgfile = xstrdup(optarg);
             break;
+
         case 'l':
             flag_list = 1;
             break;
+
+        case 't':
+            flag_testconf = 1;
+            break;
+
         case 'v':
             info("symux version %s", SYMUX_VERSION);
         default:
@@ -201,6 +208,10 @@ main(int argc, char *argv[])
         }
     }
 
+    if (flag_testconf) {
+        info("%s: ok", cfgfile);
+        exit(EX_OK);
+    }
 
     setegid(getgid());
     setgid(getgid());
@@ -226,9 +237,10 @@ main(int argc, char *argv[])
 
     mux = SLIST_FIRST(&mul);
 
-    churnbuflen = calculate_churnbuffer(&mux->sol);
+    churnbuflen = strlen_sourcelist(&mux->sol);
     debug("size of churnbuffer = %d", churnbuflen);
     initshare(churnbuflen);
+    init_symux_packet(mux);
 
     /* catch signals */
     signal(SIGHUP, huphandler);
@@ -249,7 +261,7 @@ main(int argc, char *argv[])
     rrderrors = 0;
     /* main loop */
     for (;;) {                  /* FOREVER */
-        wait_for_traffic(mux, &source, &packet);
+        wait_for_traffic(mux, &source);
 
         if (flag_hup == 1) {
             flag_hup = 0;
@@ -266,6 +278,7 @@ main(int argc, char *argv[])
                 mux = SLIST_FIRST(&mul);
                 get_symon_sockets(mux);
                 get_client_socket(mux);
+                init_symux_packet(mux);
             }
         } else {
 
@@ -277,11 +290,11 @@ main(int argc, char *argv[])
              * the hasseling with stringptr.
              */
 
-            offset = mux->offset;
+            offset = mux->packet.offset;
             maxstringlen = shared_getmaxlen();
             /* put time:ip: into shared region */
             slot = master_forbidread();
-            timestamp = (time_t) packet.header.timestamp;
+            timestamp = (time_t) mux->packet.header.timestamp;
             stringbuf = shared_getmem(slot);
             debug("stringbuf = 0x%08x", stringbuf);
             snprintf(stringbuf, maxstringlen, "%s;", source->addr);
@@ -290,12 +303,12 @@ main(int argc, char *argv[])
             maxstringlen -= strlen(stringbuf);
             stringptr = stringbuf + strlen(stringbuf);
 
-            while (offset < packet.header.length) {
+            while (offset < mux->packet.header.length) {
                 bzero(&ps, sizeof(struct packedstream));
-                if (packet.header.symon_version == 1) {
-                    offset += sunpack1(packet.data + offset, &ps);
-                } else if (packet.header.symon_version == 2) {
-                    offset += sunpack2(packet.data + offset, &ps);
+                if (mux->packet.header.symon_version == 1) {
+                    offset += sunpack1(mux->packet.data + offset, &ps);
+                } else if (mux->packet.header.symon_version == 2) {
+                    offset += sunpack2(mux->packet.data + offset, &ps);
                 } else {
                     debug("unsupported packet version - ignoring data");
                     ps.type = MT_EOT;

+ 1 - 2
symon/symux/symux.conf

@@ -1,5 +1,5 @@
 #
-# $Id: symux.conf,v 1.22 2004/02/26 22:48:08 dijkstra Exp $
+# $Id: symux.conf,v 1.23 2007/11/29 13:13:18 dijkstra Exp $
 #
 # Demo symux configuration. See symux(8) for BNF.
 
@@ -17,7 +17,6 @@ source 127.0.0.1 {
 	  	 io(wd0)
 	}
 
-	datadir "/var/www/symon/rrds/localhost"
 }
 
 # an example showing the write directive

+ 21 - 19
symon/symux/symuxnet.c

@@ -1,7 +1,7 @@
-/* $Id: symuxnet.c,v 1.23 2007/02/11 20:07:32 dijkstra Exp $ */
+/* $Id: symuxnet.c,v 1.24 2007/11/29 13:13:18 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -172,8 +172,7 @@ get_client_socket(struct mux * mux)
  * Silently forks off clienthandlers
  */
 void
-wait_for_traffic(struct mux * mux, struct source ** source,
-                 struct symonpacket * packet)
+wait_for_traffic(struct mux * mux, struct source ** source)
 {
     fd_set readset;
     int i;
@@ -205,7 +204,7 @@ wait_for_traffic(struct mux * mux, struct source ** source,
 
             for (i = 0; i < AF_MAX; i++)
                 if (FD_ISSET(mux->symonsocket[i], &readset)) {
-                    if (recv_symon_packet(mux, i, source, packet))
+                    if (recv_symon_packet(mux, i, source))
                         return;
                 }
         } else {
@@ -218,8 +217,7 @@ wait_for_traffic(struct mux * mux, struct source ** source,
  * return 0 if no valid packet found
  */
 int
-recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
-                  struct symonpacket * packet)
+recv_symon_packet(struct mux * mux, int socknr, struct source ** source)
 {
     struct sockaddr_storage sind;
     socklen_t sl;
@@ -234,8 +232,8 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
         sl = sizeof(sind);
 
         size = recvfrom(mux->symonsocket[socknr],
-                        (void *) (packet->data + received),
-                        sizeof(struct symonpacket) - received,
+                        (mux->packet.data + received),
+                        (mux->packet.size - received),
                         0, (struct sockaddr *) &sind, &sl);
         if (size > 0)
             received += size;
@@ -244,7 +242,7 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
     } while ((size == -1) &&
              (errno == EAGAIN || errno == EINTR) &&
              (tries < SYMUX_MAXREADTRIES) &&
-             (received < sizeof(packet->data)));
+             (received < mux->packet.size));
 
     if ((size == -1) &&
         errno)
@@ -259,21 +257,25 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
         return 0;
     } else {
         /* get header stream */
-        mux->offset = getheader(packet->data, &packet->header);
+        mux->packet.offset = getheader(mux->packet.data, &mux->packet.header);
         /* check crc */
-        crc = packet->header.crc;
-        packet->header.crc = 0;
-        setheader(packet->data, &packet->header);
-        crc ^= crc32(packet->data, received);
+        crc = mux->packet.header.crc;
+        mux->packet.header.crc = 0;
+        setheader(mux->packet.data, &mux->packet.header);
+        crc ^= crc32(mux->packet.data, received);
         if (crc != 0) {
-            warning("ignored packet with bad crc from %.200s:%.200s",
-                    res_host, res_service);
+            if (mux->packet.header.length > mux->packet.size)
+                warning("ignored oversized packet from %.200s:%.200s; client and server have different stream configurations",
+                        res_host, res_service);
+            else
+                warning("ignored packet with bad crc from %.200s:%.200s",
+                        res_host, res_service);
             return 0;
         }
         /* check packet version */
-        if (packet->header.symon_version > SYMON_PACKET_VER) {
+        if (mux->packet.header.symon_version > SYMON_PACKET_VER) {
             warning("ignored packet with unsupported version %d from %.200s:%.200s",
-                    packet->header.symon_version, res_host, res_service);
+                    mux->packet.header.symon_version, res_host, res_service);
             return 0;
         } else {
             if (flag_debug) {

+ 4 - 4
symon/symux/symuxnet.h

@@ -1,7 +1,7 @@
-/* $Id: symuxnet.h,v 1.12 2007/02/11 20:07:32 dijkstra Exp $ */
+/* $Id: symuxnet.h,v 1.13 2007/11/29 13:13:18 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@ __BEGIN_DECLS
 int get_client_socket(struct mux *);
 int get_symon_sockets(struct mux *);
 int accept_connection(int);
-int recv_symon_packet(struct mux *, int, struct source **, struct symonpacket *);
-void wait_for_traffic(struct mux *, struct source **, struct symonpacket *);
+int recv_symon_packet(struct mux *, int, struct source **);
+void wait_for_traffic(struct mux *, struct source **);
 __END_DECLS
 #endif                          /* _SYMUX_SYMUXNET_H */