Pārlūkot izejas kodu

Add ./tarball_archive/mon-2.4.tar.gz

Wictor Lund 3 gadi atpakaļ
vecāks
revīzija
07bf73f8af

+ 25 - 1
mon/CHANGELOG

@@ -1,3 +1,27 @@
+06/09/2002 -
+   monmux/c_monrrds.sh:
+     - Added RRD_ARGS support. All created rrds have start=epoch. Incoming data
+       from hosts may be from an earlier time than rrd creation now.
+
+   mon2web/class_[io|if|mem|cpu].inc, index.php:
+     - Rewrote argument representation of the graphs to be the same as how it
+       is configured in the configuration files.
+
+   mon2web/class_pf.inc, graph_pf.php:
+     - Initial pf support.
+
+01/09/2002 - Internal cosmetics - not released
+
+   mon/mon.c: 
+     - mon packetsize is still limited by size of struct monpacket in
+       data.h:79. All other limits have been removed.
+
+   lib/data.c mon/monnet.c monmux/muxnet.c:
+     - header structure is now safely transported across the network.
+
+   lib/data.c
+     - added streamtypes b(yte) and s(hort) in preparation for new streams.
+
 31/08/2002 - 2.3
 
     Makefiles, mon/mon.c: 
@@ -101,4 +125,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.1 2002/08/31 15:54:57 dijkstra Exp $
+$Id: CHANGELOG,v 1.2 2002/09/02 06:15:19 dijkstra Exp $

+ 2 - 2
mon/Makefile

@@ -1,7 +1,7 @@
 # $Id: Makefile,v 1.6 2002/08/31 15:54:57 dijkstra Exp $
 
-SUBDIR=	lib mon monmux 
-V=2.3
+SUBDIR=	lib mon monmux mon2web
+V=2.4
 
 .if make(clean)
 SUBDIR+= ports/mon

+ 1 - 0
mon/Makefile.inc

@@ -19,6 +19,7 @@ STRIP=  strip
 BINDIR= libexec
 MANDIR=	man
 SHRDIR= share/mon
+WEBDIR= share/mon/web
 
 .ifndef PREFIX
 PREFIX=/usr/local

+ 3 - 2
mon/TODO

@@ -1,7 +1,8 @@
 TODO:
 
 == current problems / short term
-- rework sending struct
+- add mon2web manual page / readme, explain weird format
+- remove mon packet limit
 - rework port makefile, current version contains both (mon|monmux) on a host
   and that does not make sense for a probe only host. flavors should be
   default, kvm, no-pf (3.1 and up dep)
@@ -14,4 +15,4 @@ TODO:
 - write a muxer that supports unix pipes
 - write a client that drives a crystal fontz lcd
 
-$Id: TODO,v 1.15 2002/08/31 16:18:09 dijkstra Exp $
+$Id: TODO,v 1.16 2002/09/02 06:15:19 dijkstra Exp $

+ 94 - 8
mon/lib/data.c

@@ -1,4 +1,4 @@
-/* $Id: data.c,v 1.14 2002/08/29 19:38:52 dijkstra Exp $ */
+/* $Id: data.c,v 1.15 2002/09/02 06:15:52 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -68,7 +68,9 @@ __END_DECLS
  *
  * L = u_int64 
  * l = u_int32
+ * s = u_int16
  * c = 3.2f <= u_int14 <= u_int16  (used in percentages)
+ * b = u_int8
  */
 struct {
     char type;
@@ -78,9 +80,11 @@ struct {
     int  bytelen;
     u_int64_t max;
 } streamvar[] = {
-    {'L', ":%qu",    " %20qu",   22, sizeof(u_int64_t), (u_int64_t) 0xffffffffffffffff},
+    {'L', ":%llu",  " %20llu",   22, sizeof(u_int64_t), (u_int64_t) 0xffffffffffffffff},
     {'l', ":%lu",    " %10lu",   12, sizeof(u_int32_t), (u_int64_t) 0xffffffff},
-    {'c', ":%3.2f", "  %3.2f",    7, sizeof(u_int16_t), (u_int64_t) 100},
+    {'s', ":%u",       " %5u",    7, sizeof(u_int16_t), (u_int64_t) 0xffff},
+    {'c', ":%3.2f",  " %3.2f",    8, sizeof(u_int16_t), (u_int64_t) 100},
+    {'b', ":%3u",      " %3u",    5, sizeof(u_int8_t),  (u_int64_t) 255},
     {'\0', NULL,         NULL,    0,                 0,             0}
 };
 /* streams of <type> have the packedstream <form> */
@@ -231,6 +235,44 @@ checklen(int maxlen, int current, int extra)
 	return 1;
     }
 }
+int 
+setheader(char *buf, struct monpacketheader *hph) 
+{
+    struct monpacketheader nph;
+    char *p;
+
+    nph.timestamp = htonq(hph->timestamp);
+    nph.crc = htonl(hph->crc);
+    nph.length = htons(hph->length);
+    nph.mon_version = hph->mon_version;
+
+    p = buf;
+
+    bcopy(&nph.crc, p, sizeof(u_int32_t)); p += sizeof(u_int32_t);
+    bcopy(&nph.timestamp, p, sizeof(u_int64_t)); p += sizeof(u_int64_t);
+    bcopy(&nph.length, p, sizeof(u_int16_t)); p += sizeof(u_int16_t);
+    bcopy(&nph.mon_version, p, sizeof(u_int8_t)); p += sizeof(u_int8_t);
+
+    return (p - buf);
+}
+int
+getheader(char *buf, struct monpacketheader *hph)
+{
+    char *p;
+
+    p = buf;
+
+    bcopy(p, &hph->crc, sizeof(u_int32_t)); p += sizeof(u_int32_t);
+    bcopy(p, &hph->timestamp, sizeof(u_int64_t)); p += sizeof(u_int64_t);
+    bcopy(p, &hph->length, sizeof(u_int16_t)); p += sizeof(u_int16_t);
+    bcopy(p, &hph->mon_version, sizeof(u_int8_t)); p += sizeof(u_int8_t);
+
+    hph->timestamp = ntohq(hph->timestamp);
+    hph->crc = ntohl(hph->crc);
+    hph->length = ntohs(hph->length);
+    
+    return (p - buf);
+}
 /* 
  * Pack multiple arguments of a MT_TYPE into a network order bytestream.
  * snpack returns the number of bytes actually stored.  
@@ -239,6 +281,8 @@ int
 snpack(char *buf, int maxlen, char *id, int type, ...)
 {
     va_list ap;
+    u_int16_t b;
+    u_int16_t s;
     u_int16_t c;
     u_int32_t l;
     u_int64_t q;
@@ -271,18 +315,31 @@ snpack(char *buf, int maxlen, char *id, int type, ...)
 	/* check for buffer overflow */
 	if (checklen(maxlen, offset, bytelenvar(streamform[type].form[i])))
 	    return offset;
-		     
+	
+	/* all values smaller than 32 bytes are transferred using ints on the
+           stack. This is to ensure that we get the correct value, if the
+           compiler decided to upgrade our short to a 32bit int. -- cheers
+           dhartmei@ */
 	switch (streamform[type].form[i]) {
+	case 'b':
+	    b = va_arg(ap, int);
+	    buf[offset++] = b;
+	    break;
+
 	case 'c':
-	    c = va_arg(ap, int); /* int instead of u_int16_t to avoid just
-                                    getting the first 2 bytes if the compiler
-                                    generated an int on the stack -- cheers
-                                    dhartmei@ */
+	    c = va_arg(ap, int);
 	    c = htons(c);
 	    bcopy(&c, buf + offset, sizeof(u_int16_t));
 	    offset += sizeof(u_int16_t);
 	    break;
 
+	case 's':
+	    s = va_arg(ap, int);
+	    s = htons(c);
+	    bcopy(&s, buf + offset, sizeof(u_int16_t));
+	    offset += sizeof(u_int16_t);
+	    break;
+
 	case 'l': 
 	    l = va_arg(ap, u_int32_t);
 	    l = htonl(l);
@@ -321,6 +378,7 @@ sunpack(char *buf, struct packedstream *ps)
     char *in, *out;
     int i=0;
     int type;
+    u_int16_t s;
     u_int16_t c;
     u_int32_t l;
     u_int64_t q;
@@ -350,6 +408,12 @@ sunpack(char *buf, struct packedstream *ps)
 
     while (streamform[type].form[i] != '\0') {
 	switch (streamform[type].form[i]) {
+	case 'b':
+	    bcopy((void *)in, (void *)out, sizeof(u_int8_t));
+	    in++;
+	    out++;
+	    break;
+
 	case 'c':
 	    bcopy((void *)in, &c, sizeof(u_int16_t));
 	    c = ntohs(c);
@@ -358,6 +422,14 @@ sunpack(char *buf, struct packedstream *ps)
 	    out += sizeof(u_int16_t);
 	    break;
 
+	case 's':
+	    bcopy((void *)in, &s, sizeof(u_int16_t));
+	    s = ntohs(s);
+	    bcopy(&s, (void *)out, sizeof(u_int16_t));
+	    in  += sizeof(u_int16_t);
+	    out += sizeof(u_int16_t);
+	    break;
+
 	case 'l': 
 	    bcopy((void *)in, &l, sizeof(u_int32_t));
 	    l = ntohl(l);
@@ -387,6 +459,8 @@ int
 ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
 {
     float f;
+    u_int16_t b;
+    u_int16_t s;
     u_int16_t c;
     u_int64_t q;
     u_int32_t l;
@@ -416,6 +490,12 @@ ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
 	}
 
 	switch (vartype) {
+	case 'b':
+	    bcopy(in, &b, sizeof(u_int8_t));
+	    snprintf(out, strlenvar(vartype), formatstr, b); 
+	    in++;
+	    break; 
+
 	case 'c':
 	    bcopy(in, &c, sizeof(u_int16_t));
 	    f = (float)c / 10.0;
@@ -423,6 +503,12 @@ ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
 	    in  += sizeof(u_int16_t);
 	    break;
 
+	case 's':
+	    bcopy(in, &s, sizeof(u_int16_t));
+	    snprintf(out, strlenvar(vartype), formatstr, s); 
+	    in  += sizeof(u_int16_t);
+	    break;
+
 	case 'l': 
 	    bcopy(in, &l, sizeof(u_int32_t));
 	    snprintf(out, strlenvar(vartype), formatstr, l); 

+ 15 - 4
mon/lib/data.h

@@ -1,4 +1,4 @@
-/* $Id: data.h,v 1.14 2002/08/31 16:09:55 dijkstra Exp $ */
+/* $Id: data.h,v 1.15 2002/09/02 06:15:52 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -76,14 +76,22 @@ ntohq (u_int64_t v)
  * so that works out to about 38 packedstreams in a single mon packet.  
  */
 #define MON_PACKET_VER  1
-struct monpacket {
-    struct {
+
+/* Sending structures over the network is dangerous as the compiler might have
+ * added extra padding between items. monpacketheader below is therefore also
+ * marshalled and demarshalled via snpack and sunpack. The actual values are
+ * copied out of memory into this structure one by one. 
+ */
+struct monpacketheader {
 	u_int64_t timestamp;
 	u_int32_t crc;
 	u_int16_t length;
 	u_int8_t mon_version;
 	u_int8_t reserved;
-    } header;
+};
+
+struct monpacket {
+    struct monpacketheader header;
     char data[_POSIX2_LINE_MAX];
 };  
   
@@ -151,6 +159,7 @@ struct packedstream {
     int padding;
     char args[MON_PS_ARGLEN];
     union {
+	struct monpacketheader header;
 	struct { 
 	    u_int64_t mtotal_transfers;
 	    u_int64_t mtotal_seeks;
@@ -214,7 +223,9 @@ __BEGIN_DECLS
 const char    *type2str(const int);
 const int      token2type(const int);
 int            calculate_churnbuffer(struct sourcelist *);
+int            getheader(char *, struct monpacketheader *);
 int            ps2strn(struct packedstream *, char *, int, int);
+int            setheader(char *, struct monpacketheader *);
 int            snpack(char *, int, char*, int, ...);
 int            strlentype(int);
 int            sunpack(char *, struct packedstream *);

+ 5 - 1
mon/lib/net.h

@@ -1,4 +1,4 @@
-/* $Id: net.h,v 1.5 2002/04/04 20:49:58 dijkstra Exp $ */
+/* $Id: net.h,v 1.6 2002/09/02 06:15:52 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -37,6 +37,10 @@
 
 #define MONMUX_PORT  2100                     /* default monmux port */
 
+/* Rewrite an ipadress uint32_t as 4 comma seperated bytes */
+#define IPAS4BYTES(x) \
+        ((x) >> 24), ((x) >> 16) & 0xff, ((x) >> 8) & 0xff, (x) & 0xff
+
 extern char lookup_hostname[];
 extern char lookup_address[];
 extern u_int32_t lookup_ip;

+ 5 - 2
mon/mon/io.c

@@ -1,4 +1,4 @@
-/* $Id: io.c,v 1.5 2002/08/31 15:00:25 dijkstra Exp $ */
+/* $Id: io.c,v 1.6 2002/09/02 06:16:26 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -62,10 +62,14 @@ char io_name[_POSIX2_LINE_MAX];
 void 
 init_io(char *s) 
 {
+#ifdef MON_KVM
     io_size_disk = sizeof io_disk;
     io_size_dihead = sizeof io_dihead;
 
     info("started module io(%s)", s);
+#else
+    warning("io(%s) requires kvm support which was disabled at compile time", s);
+#endif
 }
 /* Get new io statistics */
 int 
@@ -100,7 +104,6 @@ get_io(char *mon_buf, int maxlen, char *disk)
 
     return 0;
 #else
-    warning("io(%s) requires kvm support which was disabled at compile time", disk);
     return 0;
 #endif
 }

+ 1 - 1
mon/mon/mon.8

@@ -68,7 +68,7 @@ priviledges. All other probes use ioctls and sysctls to obtain their data.
 .Lp
 The options:
 .Bl -tag -width Ds
-.It Fl a
+.It Fl v
 Show version information.
 .It Fl d
 Stop 

+ 23 - 17
mon/mon/monnet.c

@@ -1,4 +1,4 @@
-/* $Id: monnet.c,v 1.8 2002/08/11 20:00:57 dijkstra Exp $ */
+/* $Id: monnet.c,v 1.9 2002/09/02 06:16:55 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -42,6 +42,7 @@
 #include "error.h"
 #include "data.h"
 #include "mon.h"
+#include "net.h"
 
 /* Fill a mux structure with inet details */
 void 
@@ -73,18 +74,17 @@ connect2mux(struct mux *mux)
 void 
 send_packet(struct mux *mux)
 {   
-    if (sendto(mux->monsocket, (void *)&mux->packet, 
-	       mux->offset + sizeof(mux->packet.header), 0,
-	       (struct sockaddr *)&mux->sockaddr, sizeof(mux->sockaddr)) 
-	!= (mux->offset + sizeof(mux->packet.header))) {
+    if (sendto(mux->monsocket, (void *)&mux->packet.data, 
+	       mux->offset, 0, (struct sockaddr *)&mux->sockaddr, 
+	       sizeof(mux->sockaddr))
+	!= mux->offset) {
 	mux->senderr++;
     }
 
     if (mux->senderr >= MON_WARN_SENDERR)
 	warning("%d updates to mux(%u.%u.%u.%u) lost due to send errors",
 		mux->senderr, 
-		(mux->ip >> 24), (mux->ip >> 16) & 0xff, 
-		(mux->ip >> 8) & 0xff, mux->ip & 0xff), mux->senderr = 0;
+		IPAS4BYTES(mux->ip)), mux->senderr = 0;
 }
 /* Prepare a packet for data */
 void 
@@ -93,10 +93,13 @@ prepare_packet(struct mux *mux)
     time_t t = time(NULL);
 
     bzero(&mux->packet, sizeof(mux->packet));
-    mux->offset = 0;
-
     mux->packet.header.mon_version = MON_PACKET_VER;
-    mux->packet.header.timestamp = htonq((u_int64_t) t);
+    mux->packet.header.timestamp = t;
+
+    /* monpacketheader is always first stream */
+    mux->offset = 
+	setheader((char *)&mux->packet.data, 
+		  &mux->packet.header);
 }
 /* Put a stream into the packet for a mux */
 void 
@@ -105,17 +108,20 @@ 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 */
-	 _POSIX2_LINE_MAX - mux->offset,    /* maxlen */
+	 sizeof(mux->packet.data) - mux->offset,    /* maxlen */
 	 stream->args);
 }
 /* Ready a packet for transmission, set length and crc */
 void finish_packet(struct mux *mux) 
 {
-    u_int32_t crc;
-
-    mux->packet.header.length = htons(mux->offset);
-    
+    mux->packet.header.length = mux->offset;
     mux->packet.header.crc = 0;
-    crc = crc32(&mux->packet, mux->offset + sizeof(mux->packet.header));
-    mux->packet.header.crc = htonl(crc);
+
+    /* fill in correct header with crc = 0 */
+    setheader((char *)&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);
 }
+

+ 26 - 0
mon/mon2web/Makefile

@@ -0,0 +1,26 @@
+# $Id: $
+.include "../Makefile.inc"
+
+all:
+
+clean:
+
+install: 
+	${INSTALL} -d -m 555 -g www -o www ${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www class_cpu.inc	${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www class_graph.inc	${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www class_if.inc		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www class_io.inc		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www class_mem.inc	${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www class_pf.inc		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www datasources.inc	${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www graph_cpu.php	${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www graph_if.php		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www graph_io.php		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www graph_mem.php	${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www graph_pf.php		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www index.php		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www mon.css		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www mon.png		${PREFIX}/${WEBDIR}
+	${INSTALL} -c -m 444 -g www -o www spacer.png		${PREFIX}/${WEBDIR}
+

+ 1 - 1
mon/mon2web/class_cpu.inc

@@ -9,7 +9,7 @@ class CPU_Graph extends Graph {
     function execute($url) {
 	$this->url2options($url);
 	// and add a few private things
-	$this->graphsettings["rawcmdline"] .=" -v '% ".$this->get("name")."' -u 100 --rigid ";
+	$this->graphsettings["rawcmdline"] .=" -v '% cpu(".$this->get("name").")' -u 100 --rigid ";
 
 	$this->shortcut = array_merge($this->shortcut, array(
 	    "cpu" => array(

+ 1 - 1
mon/mon2web/class_if.inc

@@ -204,7 +204,7 @@ class IF_Graph extends Graph {
 
 	$this->graphdefaults = array_merge($this->graphdefaults,
 					   $this->shortcut["if"]["brief"]);
-	$this->graphsettings["rawcmdline"] .=" -v '".$this->get("name")."'";
+	$this->graphsettings["rawcmdline"] .=" -v 'if(".$this->get("name").")'";
 	$this->url2options($url);
     }
 }

+ 1 - 1
mon/mon2web/class_io.inc

@@ -10,7 +10,7 @@ class IO_Graph extends Graph {
 	$this->url2options($url);
 
 	// and add a few private things
-	$this->graphsettings["rawcmdline"] .=" -v '".$this->get("name")."'";
+	$this->graphsettings["rawcmdline"] .=" -v 'io(".$this->get("name").")'";
 	$this->shortcut = array_merge($this->shortcut, array(
 	    "io" => array(
 		"brief" => array(

+ 1 - 1
mon/mon2web/class_mem.inc

@@ -10,7 +10,7 @@ class MEM_Graph extends Graph {
     function execute($url) {
 	$this->url2options($url);
 	// and add a few private things
-	$this->graphsettings["rawcmdline"] .=" -v '% ".$this->get("name")."' -b 1024 ";
+	$this->graphsettings["rawcmdline"] .=" -v 'mem' -b 1024 ";
 	
 	$this->shortcut = array_merge($this->shortcut, array(
 	    "mem" => array(

+ 169 - 0
mon/mon2web/class_pf.inc

@@ -0,0 +1,169 @@
+<?php
+require_once("class_graph.inc");
+
+class PF_Graph extends Graph {
+    function PF_Graph() {
+	// get all the sensible defaults from our parent class
+	$this->init(); 
+    }
+    function execute($url) {
+	$this->url2options($url);
+
+	// and add a few private things
+	$this->shortcut = array_merge($this->shortcut, array(
+	    "pf" => array(
+		"brief" => array(
+		    "dsdefinition" => array(
+			"DEF:A=".$this->get("rrdfile").":bytes:AVERAGE "),
+		    "graphdefinition" => array(
+			'COMMENT:"            min          avg          max          last\n"',
+			"AREA:A#00FF00:'bytes'",
+			"GPRINT:A:MIN:'%6.2lf %sBps'",
+			"GPRINT:A:AVERAGE:'%6.2lf %sBps'",
+			"GPRINT:A:MAX:'%6.2lf %sBps'",
+			"GPRINT:A:LAST:'%6.2lf %sBps'")),
+		"all" => array(
+		    "dsdefinition" => array(
+			"DEF:A=".$this->get("rrdfile").":bytes_v4_in:AVERAGE ",
+			"DEF:B=".$this->get("rrdfile").":bytes_v4_out:AVERAGE ",
+			"DEF:C=".$this->get("rrdfile").":bytes_v6_in:AVERAGE ",
+			"DEF:D=".$this->get("rrdfile").":bytes_v6_out:AVERAGE ",
+			"DEF:E=".$this->get("rrdfile").":packets_v4_in_pass:AVERAGE ",
+			"DEF:F=".$this->get("rrdfile").":packets_v4_in_drop:AVERAGE ",
+			"DEF:G=".$this->get("rrdfile").":packets_v4_out_pass:AVERAGE ",
+			"DEF:H=".$this->get("rrdfile").":packets_v4_out_drop:AVERAGE ",
+			"DEF:J=".$this->get("rrdfile").":packets_v6_in_pass:AVERAGE ",
+			"DEF:K=".$this->get("rrdfile").":packets_v6_in_drop:AVERAGE ",
+			"DEF:L=".$this->get("rrdfile").":packets_v6_out_pass:AVERAGE ",
+			"DEF:M=".$this->get("rrdfile").":packets_v6_out_drop:AVERAGE ",
+			"DEF:N=".$this->get("rrdfile").":states_entries:AVERAGE ",
+			"DEF:O=".$this->get("rrdfile").":states_searches:AVERAGE ",
+			"DEF:P=".$this->get("rrdfile").":states_inserts:AVERAGE ",
+			"DEF:Q=".$this->get("rrdfile").":states_removals:AVERAGE ",
+			"DEF:R=".$this->get("rrdfile").":counters_match:AVERAGE ",
+			"DEF:S=".$this->get("rrdfile").":counters_badoffset:AVERAGE ",
+			"DEF:T=".$this->get("rrdfile").":counters_fragment:AVERAGE ",
+			"DEF:U=".$this->get("rrdfile").":counters_short:AVERAGE ",
+			"DEF:V=".$this->get("rrdfile").":counters_normalize:AVERAGE ",
+			"DEF:W=".$this->get("rrdfile").":counters_memory:AVERAGE "),    
+		    "graphdefinition" => array(
+			'COMMENT:"               min          avg          max          last\n"',
+			'LINE1:A#000000:"bytes_v4_in"',
+			"GPRINT:A:MIN:'%4.2lf %sBps'",
+			"GPRINT:A:AVERAGE:'%4.2lf %sBps'",
+			"GPRINT:A:MAX:'%4.2lf %sBps'",
+			'GPRINT:A:LAST:"%4.2lf %sBps\n"',
+			'LINE1:B#0B0B0B:"bytes_v4_out"',
+			"GPRINT:B:MIN:'%4.2lf %sBps'",
+			"GPRINT:B:AVERAGE:'%4.2lf %sBps'",
+			"GPRINT:B:MAX:'%4.2lf %sBps'",
+			'GPRINT:B:LAST:"%4.2lf %sBps\n"',
+			'LINE1:C#161616:"bytes_v6_in"',
+			"GPRINT:C:MIN:'%4.2lf %sBps'",
+			"GPRINT:C:AVERAGE:'%4.2lf %sBps'",
+			"GPRINT:C:MAX:'%4.2lf %sBps'",
+			'GPRINT:C:LAST:"%4.2lf %sBps\n"',
+			'LINE1:D#212121:"bytes_v6_out"',
+			"GPRINT:D:MIN:'%4.2lf %sBps'",
+			"GPRINT:D:AVERAGE:'%4.2lf %sBps'",
+			"GPRINT:D:MAX:'%4.2lf %sBps'",
+			'GPRINT:D:LAST:"%4.2lf %sBps\n"',
+			'LINE1:E#2C2C2C:"packets_v4_in_pass"',
+			"GPRINT:E:MIN:'%4.2lf      '",
+			"GPRINT:E:AVERAGE:'%4.2lf      '",
+			"GPRINT:E:MAX:'%4.2lf      '",
+			'GPRINT:E:LAST:"%4.2lf\n"',
+			'LINE1:F#373737:"packets_v4_in_drop"',
+			"GPRINT:F:MIN:'%4.2lf      '",
+			"GPRINT:F:AVERAGE:'%4.2lf      '",
+			"GPRINT:F:MAX:'%4.2lf      '",
+			'GPRINT:F:LAST:"%4.2lf\n"',
+			'LINE1:G#424242:"packets_v4_out_pass"',
+			"GPRINT:G:MIN:'%4.2lf      '",
+			"GPRINT:G:AVERAGE:'%4.2lf      '",
+			"GPRINT:G:MAX:'%4.2lf      '",
+			'GPRINT:G:LAST:"%4.2lf\n"',
+			'LINE1:H#4D4D4D:"packets_v4_out_drop"',
+			"GPRINT:H:MIN:'%4.2lf      '",
+			"GPRINT:H:AVERAGE:'%4.2lf      '",
+			"GPRINT:H:MAX:'%4.2lf      '",
+			'GPRINT:H:LAST:"%4.2lf\n"',
+			'LINE1:J#585858:"packets_v6_in_pass"',
+			"GPRINT:J:MIN:'%4.2lf      '",
+			"GPRINT:J:AVERAGE:'%4.2lf      '",
+			"GPRINT:J:MAX:'%4.2lf      '",
+			'GPRINT:J:LAST:"%4.2lf\n"',
+			'LINE1:K#636363:"packets_v6_in_drop"',
+			"GPRINT:K:MIN:'%4.2lf      '",
+			"GPRINT:K:AVERAGE:'%4.2lf      '",
+			"GPRINT:K:MAX:'%4.2lf      '",
+			'GPRINT:K:LAST:"%4.2lf\n"',
+			'LINE1:L#6E6E6E:"packets_v6_out_pass"',
+			"GPRINT:L:MIN:'%4.2lf      '",
+			"GPRINT:L:AVERAGE:'%4.2lf      '",
+			"GPRINT:L:MAX:'%4.2lf      '",
+			'GPRINT:L:LAST:"%4.2lf\n"',
+			'LINE1:M#797979:"packets_v6_out_drop"',
+			"GPRINT:M:MIN:'%4.2lf      '",
+			"GPRINT:M:AVERAGE:'%4.2lf      '",
+			"GPRINT:M:MAX:'%4.2lf      '",
+			'GPRINT:M:LAST:"%4.2lf\n"',
+			'LINE1:N#848484:"states_entries"',
+			"GPRINT:N:MIN:'%4.2lf      '",
+			"GPRINT:N:AVERAGE:'%4.2lf      '",
+			"GPRINT:N:MAX:'%4.2lf      '",
+			'GPRINT:N:LAST:"%4.2lf\n"',
+			'LINE1:O#8F8F8F:"states_searches"',
+			"GPRINT:O:MIN:'%4.2lf      '",
+			"GPRINT:O:AVERAGE:'%4.2lf      '",
+			"GPRINT:O:MAX:'%4.2lf      '",
+			'GPRINT:O:LAST:"%4.2lf\n"',
+			'LINE1:P#9A9A9A:"states_inserts"',
+			"GPRINT:P:MIN:'%4.2lf      '",
+			"GPRINT:P:AVERAGE:'%4.2lf      '",
+			"GPRINT:P:MAX:'%4.2lf      '",
+			'GPRINT:P:LAST:"%4.2lf\n"',
+			'LINE1:Q#A5A5A5:"states_removals"',
+			"GPRINT:Q:MIN:'%4.2lf      '",
+			"GPRINT:Q:AVERAGE:'%4.2lf      '",
+			"GPRINT:Q:MAX:'%4.2lf      '",
+			'GPRINT:Q:LAST:"%4.2lf\n"',
+			'LINE1:R#B0B0B0:"counters_match"',
+			"GPRINT:R:MIN:'%4.2lf      '",
+			"GPRINT:R:AVERAGE:'%4.2lf      '",
+			"GPRINT:R:MAX:'%4.2lf      '",
+			'GPRINT:R:LAST:"%4.2lf\n"',
+			'LINE1:S#BBBBBB:"counters_badoffset"',
+			"GPRINT:S:MIN:'%4.2lf      '",
+			"GPRINT:S:AVERAGE:'%4.2lf      '",
+			"GPRINT:S:MAX:'%4.2lf      '",
+			'GPRINT:S:LAST:"%4.2lf\n"',
+			'LINE1:T#C6C6C6:"counters_fragment"',
+			"GPRINT:T:MIN:'%4.2lf      '",
+			"GPRINT:T:AVERAGE:'%4.2lf      '",
+			"GPRINT:T:MAX:'%4.2lf      '",
+			'GPRINT:T:LAST:"%4.2lf\n"',
+			'LINE1:U#D1D1D1:"counters_short"',
+			"GPRINT:U:MIN:'%4.2lf      '",
+			"GPRINT:U:AVERAGE:'%4.2lf      '",
+			"GPRINT:U:MAX:'%4.2lf      '",
+			'GPRINT:U:LAST:"%4.2lf\n"',
+			'LINE1:V#DCDCDC:"counters_normalize"',
+			"GPRINT:V:MIN:'%4.2lf      '",
+			"GPRINT:V:AVERAGE:'%4.2lf      '",
+			"GPRINT:V:MAX:'%4.2lf      '",
+			'GPRINT:V:LAST:"%4.2lf\n"',
+			'LINE1:W#E7E7E7:"counters_memory  "',
+			"GPRINT:W:MIN:'%4.2lf      '",
+			"GPRINT:W:AVERAGE:'%4.2lf      '",
+			"GPRINT:W:MAX:'%4.2lf      '",
+			'GPRINT:W:LAST:"%4.2lf\n"')))));
+
+	$this->graphsettings["rawcmdline"] .=" -v 'pf'";
+	$this->graphdefaults = array_merge($this->graphdefaults,
+					   $this->shortcut["pf"]["all"]);
+
+	$this->url2options($url);
+    }
+}
+?>

+ 7 - 0
mon/mon2web/graph_pf.php

@@ -0,0 +1,7 @@
+<?php
+require_once("datasources.inc");
+require_once("class_pf.inc");
+$g = new PF_Graph();
+$g->execute($GLOBALS["QUERY_STRING"]);
+$g->sendimage();
+?>

+ 11 - 3
mon/mon2web/index.php

@@ -4,6 +4,7 @@ require_once('class_cpu.inc');
 require_once('class_if.inc');
 require_once('class_io.inc');
 require_once('class_mem.inc');
+require_once('class_pf.inc');
 
 if (!empty($GLOBALS["QUERY_STRING"])) {
     $args = $GLOBALS["QUERY_STRING"];
@@ -54,6 +55,8 @@ function make_graph_url($type, $new_args) {
     case 'mem':
 	$g = new MEM_Graph();
 	break;
+    case 'pf':
+	$g = new PF_Graph();
     }
     $g->execute($allargs);
     return ($url . $g->settings2url());
@@ -160,6 +163,7 @@ function print_index_url($new_args) {
 <?php
 // traverse through the monrrd tree
   $root_dir = dir($mon2web["tree"]);
+  $found_machine = 0;
   while ($machine = $root_dir->read()) {
       if ($machine != '.' && 
 	  $machine != '..' && 
@@ -174,7 +178,7 @@ function print_index_url($new_args) {
 	  while ($filename = $machine_dir->read()) {
 	      $file = $mon2web["tree"]."/".$machine."/".$filename;
 	      if (is_file($file) && 
-		  preg_match("/^(cpu|if|io|mem)(_([a-z]+))?([0-9]?).rrd$/", 
+		  preg_match("/^(cpu|if|io|mem|pf)(_([a-z]+))?([0-9]?).rrd$/", 
 			     $filename, $match)) {
 		  $rrdtype = $match[1];
 		  $rrdwhat = $match[3];
@@ -182,8 +186,9 @@ function print_index_url($new_args) {
 		  
 		  $cmd = make_graph_url($rrdtype,
 					"rrdfile=".$file.
-					"&name=".$rrdtype.$rrdwhat.$rrdwhich);
+					"&name=".$rrdwhat.$rrdwhich);
 		  print '<img src="' . $cmd . '">'."\n";
+		  $found_machine++;
 	      }
 	  }
 	  print '
@@ -192,7 +197,10 @@ function print_index_url($new_args) {
 
       }
   }
-
+  
+  if ($found_machine == 0) {
+      print 'Did not find any host directories in '.$mon2web["tree"].'<br>';
+  }
 ?>
        <div class="copyright">Copyright &copy; 2002 Willem Dijkstra</div>
       </div> <!-- end items div -->

+ 7 - 6
mon/monmux/c_monrrds.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
-# $Id: c_monrrds.sh,v 1.10 2002/08/31 16:09:55 dijkstra Exp $
+# $Id: c_monrrds.sh,v 1.11 2002/09/06 12:17:11 dijkstra Exp $
 
 #
 # Copyright (c) 2001-2002 Willem Dijkstra
@@ -55,6 +55,7 @@ RRA_SETUP=" RRA:AVERAGE:0.5:1:34560
 	    RRA:MIN:0.5:360:672 
 	    RRA:MIN:0.5:1440:600 
 	    RRA:MIN:0.5:17280:600"
+RRD_ARGS="--step=$INTERVAL --start=0"
 # --- user configuration ends here
 
 # All interfaces and disks
@@ -117,7 +118,7 @@ io|disks)
 
 cpu[0-9].rrd)
     # Build cpu file
-    rrdtool create $i --step=$INTERVAL \
+    rrdtool create $i $RRD_ARGS \
 	DS:user:GAUGE:5:0:100 \
 	DS:nice:GAUGE:5:0:100 \
 	DS:system:GAUGE:5:0:100 \
@@ -129,7 +130,7 @@ cpu[0-9].rrd)
 
 mem.rrd)
     # Build memory file
-    rrdtool create $i --step=$INTERVAL \
+    rrdtool create $i $RRD_ARGS \
 	DS:real_active:GAUGE:5:0:U \
 	DS:real_total:GAUGE:5:0:U \
 	DS:free:GAUGE:5:0:U \
@@ -141,7 +142,7 @@ mem.rrd)
 
 if_*.rrd)
     # Build interface files
-    rrdtool create $i --step=$INTERVAL \
+    rrdtool create $i $RRD_ARGS \
 	DS:ipackets:COUNTER:5:U:U DS:opackets:COUNTER:5:U:U \
 	DS:ibytes:COUNTER:5:U:U DS:obytes:COUNTER:5:U:U \
 	DS:imcasts:COUNTER:5:U:U DS:omcasts:COUNTER:5:U:U \
@@ -153,7 +154,7 @@ if_*.rrd)
 
 pf.rrd)
     # Build pf file
-    rrdtool create $i --step=$INTERVAL \
+    rrdtool create $i $RRD_ARGS \
 	DS:bytes_v4_in:DERIVE:5:0:U DS:bytes_v4_out:DERIVE:5:0:U \
 	DS:bytes_v6_in:DERIVE:5:0:U DS:bytes_v6_out:DERIVE:5:0:U \
 	DS:packets_v4_in_pass:DERIVE:5:0:U DS:packets_v4_in_drop:DERIVE:5:0:U \
@@ -176,7 +177,7 @@ pf.rrd)
 
 io_*.rrd)
     # Build disk files
-    rrdtool create $i --step=$INTERVAL \
+    rrdtool create $i $RRD_ARGS \
 	DS:transfers:COUNTER:5:U:U \
 	DS:seeks:COUNTER:5:U:U \
 	DS:bytes:COUNTER:5:U:U \

+ 3 - 2
mon/monmux/monmux.c

@@ -1,4 +1,4 @@
-/* $Id: monmux.c,v 1.20 2002/08/26 14:53:01 dijkstra Exp $ */
+/* $Id: monmux.c,v 1.21 2002/09/02 06:17:37 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -228,7 +228,7 @@ main(int argc, char *argv[])
 	 * the clients. This is the reason for the hasseling with stringptr.
 	 */
 	
-	offset = 0;
+	offset = mux->offset;
 	maxstringlen = shared_getmaxlen();
 	/* put time:ip: into shared region */
 	master_forbidread();
@@ -242,6 +242,7 @@ main(int argc, char *argv[])
 	stringptr = stringbuf + strlen(stringbuf);
 	
 	while (offset < packet.header.length) {
+	    bzero(&ps, sizeof(struct packedstream));
 	    offset += sunpack(packet.data + offset, &ps);
 	    
 	    /* find stream in source */

+ 10 - 12
mon/monmux/muxnet.c

@@ -1,4 +1,4 @@
-/* $Id: muxnet.c,v 1.8 2002/08/11 20:00:41 dijkstra Exp $ */
+/* $Id: muxnet.c,v 1.9 2002/09/02 06:17:37 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -164,7 +164,7 @@ recvmonpacket(struct mux *mux, struct sourcelist *sourcelist,
     do {
 	sl = sizeof(sind);
 
-	size = recvfrom(mux->monsocket, (void *)packet + received, 
+	size = recvfrom(mux->monsocket, (void *)packet->data + received, 
 			sizeof(struct monpacket) - received, 
 			0, (struct sockaddr *)&sind, &sl);
 	if (size > 0)
@@ -174,11 +174,11 @@ recvmonpacket(struct mux *mux, struct sourcelist *sourcelist,
     } while ((size == -1) && 
 	     (errno == EAGAIN || errno == EINTR) && 
 	     (tries < MONMUX_MAXREADTRIES) &&
-	     (received < sizeof(struct monpacket)));
+	     (received < sizeof(packet->data)));
 
     if ((size == -1) && 
 	errno) 
-      warning("recvfrom failed: %s", strerror(errno));
+      warning("recvfrom failed: %.200s", strerror(errno));
 
     sourceaddr = ntohl((u_int32_t)sind.sin_addr.s_addr);
     *source = find_source_ip(sourcelist, sourceaddr);
@@ -188,10 +188,13 @@ recvmonpacket(struct mux *mux, struct sourcelist *sourcelist,
 	      IPAS4BYTES(sourceaddr));
 	return 0;
     } else {
+	/* get header stream */
+	mux->offset = getheader(packet->data, &packet->header);
 	/* check crc */
-	crc = ntohl(packet->header.crc);
+	crc = packet->header.crc;
 	packet->header.crc = 0;
-	crc ^= crc32(packet, received);
+	setheader(packet->data, &packet->header);
+	crc ^= crc32(packet->data, received);
 	if ( crc != 0 ) {
 	    warning("ignored packet with bad crc from %u.%u.%u.%u",
 		    IPAS4BYTES(sourceaddr));
@@ -199,15 +202,10 @@ recvmonpacket(struct mux *mux, struct sourcelist *sourcelist,
 	}
 	/* check packet version */
 	if (packet->header.mon_version != MON_PACKET_VER) {
-	    warning("ignored packet with illegal type %d", 
+	    warning("ignored packet with wrong version %d", 
 		    packet->header.mon_version);
 	    return 0;
 	} else {
-	    /* rewrite structs to host order */
-	    packet->header.length = ntohs(packet->header.length);
-	    packet->header.crc = ntohs(packet->header.crc);
-	    packet->header.timestamp = ntohq(packet->header.timestamp);
-		
 	    if (flag_debug) 
 		debug("good data received from %u.%u.%u.%u",
 		      IPAS4BYTES(sourceaddr));

+ 1 - 5
mon/monmux/muxnet.h

@@ -1,4 +1,4 @@
-/* $Id: muxnet.h,v 1.4 2002/08/31 16:09:55 dijkstra Exp $ */
+/* $Id: muxnet.h,v 1.5 2002/09/02 06:17:24 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2002 Willem Dijkstra
@@ -35,10 +35,6 @@
 
 #include "data.h"
 
-/* Rewrite an ipadress uint32_t as 4 comma seperated bytes */
-#define IPAS4BYTES(x) \
-        ((x) >> 24), ((x) >> 16) & 0xff, ((x) >> 8) & 0xff, (x) & 0xff
-
 /* prototypes */
 __BEGIN_DECLS
 int  acceptconnection(int);

+ 32 - 8
mon/ports/mon/Makefile

@@ -1,11 +1,12 @@
 # $OpenBSD: $
 
 COMMENT=		"active monitoring tool"
-
-DISTNAME=		mon-2.3
-PKGNAME=		mon-2.3
+V=			2.4
+DISTNAME=		mon-${V}
+PKGNAME=		mon-${V}
 CATEGORIES=		net sysutils
 NEED_VERSION=		1.502
+MASTER_SITES=		http://www.xs4all.nl/~wpd/mon/
 
 HOMEPAGE=		http://www.xs4all.nl/~wpd/mon/
 
@@ -15,12 +16,35 @@ PERMIT_PACKAGE_CDROM=	Yes
 PERMIT_PACKAGE_FTP=	Yes
 PERMIT_DISTFILES_CDROM=	Yes
 PERMIT_DISTFILES_FTP=	Yes
+# flavors
+# static client
+
+# prepare package for client
+MULTI_PACKAGES+=	-monitor
+COMMENT-monitor=	"active host monitor"
+MON_DEPENDS=		
+
+# prepare package for server
+MULTI_PACKAGES+=	-mux
+COMMENT-mux=		"mon data gatherer"
+MONMUX_DEPENDS=		rrd.0.0::net/rrdtool
+
+# prepare package for web frontend
+MULTI_PACKAGES+=	-web
+COMMENT-web=		"mon web frontend"
+WEB_DEPENDS=		rrd.0.0::net/rrdtool
+
+.for i in ${MULTI_PACKAGES}
+FULLPKGNAME${i}=        mon${i}-${V}
+.endfor
+
+.if defined(PACKAGING) && !empty(SUBPACKAGE)
+MODULE_NAME=            ${SUBPACKAGE:S/-//g}
+LIB_DEPENDS=            ${${MODULE_NAME:U}_DEPENDS}
+MESSAGE=                ${PKGDIR}/MESSAGE
+.endif
 
-MASTER_SITES=		http://www.xs4all.nl/~wpd/mon/
-
-LIB_DEPENDS=		rrd.0.0::net/rrdtool
-
-#DESTDIR=		/usr/local
 WRKDIST=		${WRKDIR}/mon
 
 .include <bsd.port.mk>
+

+ 3 - 0
mon/ports/mon/pkg/DESCR

@@ -0,0 +1,3 @@
+mon is a lightweight system monitor that measures cpu, memory, interface and disk st
+atistics every 5 seconds. This information is then spooled over "the network" to monmux for further processing.
+

+ 4 - 0
mon/ports/mon/pkg/DESCR-monitor

@@ -0,0 +1,4 @@
+mon is a lightweight system monitor that measures cpu, memory, interface and
+disk st atistics every 5 seconds. This information is then spooled over "the
+network" to monmux for further processing.
+

+ 4 - 0
mon/ports/mon/pkg/DESCR-mux

@@ -0,0 +1,4 @@
+monmux is a heavyweight data gatherer for the lightweight mon system monitor.
+mon is a lightweight system monitor that measures cpu, memory, interface and
+disk st atistics every 5 seconds.
+

+ 6 - 0
mon/ports/mon/pkg/DESCR-web

@@ -0,0 +1,6 @@
+mon is a lightweight system monitor that measures cpu, memory, interface and
+disk st atistics every 5 seconds. This information is then spooled over "the
+network" to monmux for further processing.
+
+mon2web is a set of php scripts that provide a view on the data that monmux
+gathered.

+ 7 - 0
mon/ports/mon/pkg/MESSAGE

@@ -0,0 +1,7 @@
++---------------
+| Example configurations for both mon and monmux have been installed in
+| ${PREFIX}/share/mon.
+|
+| RRD files can be obtained by running
+| ${PREFIX}/share/mon/c_monrrds.sh
++---------------

+ 10 - 0
mon/ports/mon/pkg/PLIST

@@ -0,0 +1,10 @@
+@comment $Id:$
+@comment $OpenBSD$
+libexec/mon
+libexec/monmux
+man/cat8/mon.0
+man/cat8/monmux.0
+share/mon/c_monrrds.sh
+share/mon/mon.conf
+share/mon/monmux.conf
+@dirrm share/mon

+ 6 - 0
mon/ports/mon/pkg/PLIST-monitor

@@ -0,0 +1,6 @@
+@comment $Id:$
+@comment $OpenBSD$
+libexec/mon
+man/cat8/mon.0
+share/mon/mon.conf
+@dirrm share/mon

+ 7 - 0
mon/ports/mon/pkg/PLIST-mux

@@ -0,0 +1,7 @@
+@comment $Id:$
+@comment $OpenBSD$
+libexec/monmux
+man/cat8/monmux.0
+share/mon/c_monrrds.sh
+share/mon/monmux.conf
+@dirrm share/mon

+ 19 - 0
mon/ports/mon/pkg/PLIST-web

@@ -0,0 +1,19 @@
+@comment $Id:$
+@comment $OpenBSD$
+share/mon/web/class_cpu.inc        
+share/mon/web/class_graph.inc      
+share/mon/web/class_if.inc         
+share/mon/web/class_io.inc         
+share/mon/web/class_mem.inc        
+share/mon/web/class_pf.inc         
+share/mon/web/datasources.inc      
+share/mon/web/graph_cpu.php        
+share/mon/web/graph_if.php         
+share/mon/web/graph_io.php         
+share/mon/web/graph_mem.php        
+share/mon/web/graph_pf.php         
+share/mon/web/index.php            
+share/mon/web/mon.css              
+share/mon/web/mon.png              
+share/mon/web/spacer.png           
+@dirrm share/mon/web