Browse Source

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

Wictor Lund 3 years ago
parent
commit
bc1c0492f8

+ 10 - 2
symon/CHANGELOG

@@ -1,6 +1,14 @@
+19/03/2005 - 2.71
+
+   - Ulrich Spörlein updated mem probe for FreeBSD-current and removed some
+     bugs from FreeBSD/conf.sh.
+
+   - J. Martin Petersen contributed the FreeBSD io probe and a new probe called
+     pfq that can monitor pf altq queues on Free and OpenBSD.
+
 22/02/2005 - 2.70
 
-   - Ulrich Spoerlein updated the FreeBSD proc and mem probes, found a bug in
+   - Ulrich Spörlein updated the FreeBSD proc and mem probes, found a bug in
      the mem probe for OpenBSD and helped extend the shell config files for
      FreeBSD.
 
@@ -388,4 +396,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.41 2005/02/25 15:10:09 dijkstra Exp $
+$Id: CHANGELOG,v 1.43 2005/03/22 07:17:42 dijkstra Exp $

+ 32 - 0
symon/HACKERS

@@ -0,0 +1,32 @@
+$Id: HACKERS,v 1.1 2005/03/20 16:17:22 dijkstra Exp $
+
+Adding a new probe
+------------------
+
+Get your measurement as fast as possible with as little fuss as possible. Ideal
+is to get all items that the user might want to query in one gets() and give
+symon the readings for a particular item in a get().
+
+Places to touch:
+
+- lib/data.[ch]: define the new dataformat. MT_YOURSTREAM should be the old
+  MT_EOF to not break old versions.
+
+- lib/lex.[ch]: define the token for the lexer
+
+- sym[on|ux]/readconf.c: parse the new token
+
+- symux/c_smrrds.sh: add new rrdtool storage format
+
+- platform/stub/sm_<name>.c: insert your stub probe here. Makefile will look
+  for platform/<os>/sm_<name>.c after that.
+
+- platform/<os>/sm_<name>.c: your probe
+
+- symon/main.c: insert hooks into probe caller table
+
+- symon/symon.8, symux/symux.8: add your token and its internal format to the
+  manual pages.
+
+
+

+ 2 - 1
symon/INSTALL

@@ -16,6 +16,7 @@ NetBSD:   - sysctl: cpu, debug, if, io, mbuf, proc
 
 FreeBSD:  - sysctl: all
           - non-chroot on FreeBSD 5.x for CPU ticks in proc
+          - rw on /dev/pf for pf and pfq
 
 Linux:    - r on /proc/net/dev: if
           - r on /proc/stat: cpu
@@ -103,5 +104,5 @@ rudimentary support for FreeBSD, NetBSD and Linux.
 
 Willem Dijkstra - wpd@xs4all.nl
 
-$Id: INSTALL,v 1.17 2005/02/25 15:10:09 dijkstra Exp $
+$Id: INSTALL,v 1.18 2005/03/20 16:17:22 dijkstra Exp $
 

+ 2 - 2
symon/Makefile.inc

@@ -1,6 +1,6 @@
-# $Id: Makefile.inc,v 1.30 2005/02/25 15:10:09 dijkstra Exp $
+# $Id: Makefile.inc,v 1.31 2005/03/20 16:17:22 dijkstra Exp $
 
-V=2.70
+V=2.71
 OS!=uname -s
 
 AR?=	ar

+ 5 - 3
symon/client/SymuxClient.pm

@@ -1,6 +1,6 @@
-# $Id: SymuxClient.pm,v 1.9 2004/02/26 22:48:08 dijkstra Exp $
+# $Id: SymuxClient.pm,v 1.10 2005/03/20 16:17:22 dijkstra Exp $
 #
-# Copyright (c) 2001-2004 Willem Dijkstra
+# Copyright (c) 2001-2005 Willem Dijkstra
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,9 @@ my $streamitem =
 	        m_drops => 13, m_wait => 14, m_drain => 15 },
      sensor => {value => 1},
      io     => {total_rxfers => 1, total_wxfers => 2, total_seeks => 3,
-		total_rbytes => 4, total_rbytes => 5 }};
+		total_rbytes => 4, total_rbytes => 5 },
+     pfq    => {sent_bytes => 1, sent_packets => 2, drop_bytes => 3,
+		drop_packets => 4}};
 sub new {
     my ($class, %arg) = @_;
     my $self;

+ 7 - 5
symon/lib/data.c

@@ -1,7 +1,7 @@
-/* $Id: data.c,v 1.26 2004/08/07 12:21:36 dijkstra Exp $ */
+/* $Id: data.c,v 1.27 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2005 Willem Dijkstra
  * All rights reserved.
  *
  * The crc routine is by Rob Warnock <rpw3@sgi.com>, from the
@@ -83,7 +83,7 @@ struct {
     int strlen;
     int bytelen;
     u_int64_t max;
-}      streamvar[] = {
+} streamvar[] = {
     { 'L', ":%llu", " %20llu", 22, sizeof(u_int64_t), (u_int64_t) 0xffffffffffffffffLL },
     { 'D', ":%7.6f", " %7.6f", 23, sizeof(int64_t), (u_int64_t) 0xffffffffffffffffLL },
     { 'l', ":%lu", " %10lu", 12, sizeof(u_int32_t), (u_int64_t) 0xffffffff },
@@ -96,7 +96,7 @@ struct {
 struct {
     int type;
     char *form;
-}      streamform[] = {
+} streamform[] = {
     { MT_IO1, "LLL" },
     { MT_CPU, "ccccc" },
     { MT_MEM, "lllll" },
@@ -107,6 +107,7 @@ struct {
     { MT_MBUF, "lllllllllllllll" },
     { MT_SENSOR, "D" },
     { MT_IO2, "LLLLL" },
+    { MT_PFQ, "LLLL" },
     { MT_TEST, "LLLLDDDDllllssssccccbbbb" },
     { MT_EOT, "" }
 };
@@ -114,7 +115,7 @@ struct {
 struct {
     int type;
     int token;
-}      streamtoken[] = {
+} streamtoken[] = {
     { MT_IO1, LXT_IO1 },
     { MT_CPU, LXT_CPU },
     { MT_MEM, LXT_MEM },
@@ -125,6 +126,7 @@ struct {
     { MT_MBUF, LXT_MBUF },
     { MT_SENSOR, LXT_SENSOR },
     { MT_IO2, LXT_IO },
+    { MT_PFQ, LXT_PFQ },
     { MT_EOT, LXT_BADTOKEN }
 };
 /* parallel crc32 table */

+ 11 - 4
symon/lib/data.h

@@ -1,7 +1,7 @@
-/* $Id: data.h,v 1.25 2004/03/20 15:46:27 dijkstra Exp $ */
+/* $Id: data.h,v 1.26 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2005 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -151,8 +151,9 @@ SLIST_HEAD(muxlist, mux);
 #define MT_MBUF   7
 #define MT_SENSOR 8
 #define MT_IO2    9
-#define MT_TEST   10
-#define MT_EOT    11
+#define MT_PFQ    10
+#define MT_TEST   11
+#define MT_EOT    12
 
 /*
  * Unpacking of incoming packets is done via a packedstream structure. This
@@ -272,6 +273,12 @@ struct packedstream {
 	    u_int64_t mtotal_rbytes;
 	    u_int64_t mtotal_wbytes;
 	}      ps_io2;
+	struct {
+	    u_int64_t sent_bytes;
+	    u_int64_t sent_packets;
+	    u_int64_t drop_bytes;
+	    u_int64_t drop_packets;
+	}      ps_pfq;
 	struct {
 	    u_int64_t L[4];
 	    int64_t D[4];

+ 3 - 2
symon/lib/lex.c

@@ -1,7 +1,7 @@
-/* $Id: lex.c,v 1.24 2004/08/07 14:47:44 dijkstra Exp $ */
+/* $Id: lex.c,v 1.25 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2005 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -83,6 +83,7 @@ static struct {
     { "monitor", LXT_MONITOR },
     { "mux", LXT_MUX },
     { "pf", LXT_PF },
+    { "pfq", LXT_PFQ },
     { "port", LXT_PORT },
     { "proc", LXT_PROC },
     { "second", LXT_SECOND },

+ 3 - 2
symon/lib/lex.h

@@ -1,7 +1,7 @@
-/* $Id: lex.h,v 1.20 2004/02/26 22:48:08 dijkstra Exp $ */
+/* $Id: lex.h,v 1.21 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2005 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -72,6 +72,7 @@
 #define LXT_TO        26
 #define LXT_WRITE     27
 #define LXT_MBUF      28
+#define LXT_PFQ       29
 
 struct lex {
     char *buffer;		/* current line(s) */

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

@@ -1,2 +1,4 @@
-# $Id: Makefile.inc,v 1.2 2005/02/25 15:10:09 dijkstra Exp $
-LIBS= -lkvm
+# $Id: Makefile.inc,v 1.3 2005/03/20 16:17:22 dijkstra Exp $
+LIBS=-lkvm -ldevstat
+SYSCONFDIR=${PREFIX}/etc
+BINDIR=bin

+ 36 - 21
symon/platform/FreeBSD/conf.sh

@@ -1,25 +1,40 @@
-case `grep -cq "m_drops" /usr/include/sys/mbuf.h` in
-1)	echo "#define HAS_MBUF_MDROPS	1" ;;
-0)	echo "#undef HAS_MBUF_MDROPS" ;;
-esac;
-case `grep -cq "sf_allocfail" /usr/include/sys/mbuf.h` in
-1)	echo "#define HAS_MBUF_SFALLOCFAIL	1" ;;
-0)	echo "#undef HAS_MBUF_SFALLOCFAIL" ;;
-esac;
-case `grep -cq "VM_TOTAL" /usr/include/vm/vm_param.h` in
-0)      echo "#define VM_TOTAL VM_METER" ;;
-esac;
-sysctl -N vm.nswapdev 1>/dev/null 2>&1
-case $? in
-1)      echo "#undef HAS_VM_NSWAPDEV" ;;
-0)      echo "#define HAS_VM_NSWAPDEV	1" ;;
-esac;
+#!/bin/sh
+# $Id: conf.sh,v 1.3 2005/03/20 16:17:22 dijkstra Exp $
+if grep -q "m_drops" /usr/include/sys/mbuf.h; then
+    echo "#define HAS_MBUF_MDROPS	1"
+else
+    echo "#undef HAS_MBUF_MDROPS"
+fi
+if grep -q "sf_allocfail" /usr/include/sys/mbuf.h; then
+    echo "#define HAS_MBUF_SFALLOCFAIL	1"
+else
+    echo "#undef HAS_MBUF_SFALLOCFAIL"
+fi
+if ! grep -q "VM_TOTAL" /usr/include/vm/vm_param.h; then
+    echo "#define VM_TOTAL VM_METER"
+fi
+if grep -q "struct xswdev" /usr/include/vm/vm_param.h; then
+    echo "#define HAS_XSWDEV	1"
+else
+    echo "#undef HAS_XSWDEV"
+fi
 if [ -f /usr/include/net/pfvar.h ]; then
     echo "#define HAS_PFVAR_H	1"
 else
     echo "#undef HAS_PFVAR_H"
-fi;
-case `grep -cq "ki_paddr" /usr/include/sys/user.h` in
-1)      echo "#define HAS_KI_PADDR	1" ;;
-0)      echo "#undef HAS_KI_PADDR" ;;
-esac;
+fi
+if grep -q "ki_paddr" /usr/include/sys/user.h; then
+    echo "#define HAS_KI_PADDR	1"
+else
+    echo "#undef HAS_KI_PADDR"
+fi
+if grep -q "struct rusage_ext" /usr/include/sys/proc.h; then
+    echo "#define HAS_RUSAGE_EXT	1"
+else
+    echo "#undef HAS_RUSAGE_EXT"
+fi
+if grep -q "CPUSTATES" /usr/include/sys/resource.h; then
+    echo "#define HAS_RESOURCE_CPUSTATE	1"
+else
+    echo "#undef HAS_RESOURCE_CPUSTATE"
+fi

+ 141 - 0
symon/platform/FreeBSD/sm_io.c

@@ -0,0 +1,141 @@
+/* $Id: sm_io.c,v 1.1 2005/03/20 16:17:22 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2005 J. Martin Petersen
+ * 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.
+ *
+ */
+
+/*
+ * nr of reads : nr of writes : seeks (zero) : read bytes : written bytes
+ *
+ * Non re-entrant code
+ */
+
+#include "conf.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#ifdef HAS_RESOURCE_CPUSTATE
+#include <sys/resource.h>
+#else
+#include <sys/dkstat.h>
+#endif
+
+#include <devstat.h>
+
+#include "error.h"
+#include "symon.h"
+
+static struct statinfo io_stats;
+static int io_numdevs = 0;
+
+void
+privinit_io()
+{
+}
+
+void
+init_io(char *s)
+{
+    io_stats.dinfo = malloc(sizeof(struct devinfo));
+    if (io_stats.dinfo == NULL) {
+	fatal("io: could not allocate memory");
+    }
+
+    io_stats.dinfo->mem_ptr = NULL;
+    info("started module io(%.200s)",s);
+}
+
+void
+gets_io()
+{
+#if DEVSTAT_USER_API_VER == 5
+    io_numdevs = devstat_getnumdevs(NULL);
+#else
+    io_numdevs = getnumdevs();
+#endif
+
+    if (io_numdevs == -1) {
+	fatal("io: numdevs error");
+    }
+
+    if (io_stats.dinfo->mem_ptr != NULL) {
+	free(io_stats.dinfo->mem_ptr);
+    }
+
+    /* clear the devinfo struct, as getdevs expects it to be all zeroes */
+    bzero(io_stats.dinfo, sizeof(struct devinfo));
+
+#if DEVSTAT_USER_API_VER == 5
+    devstat_getdevs(NULL, &io_stats);
+#else
+    getdevs(&io_stats);
+#endif
+}
+
+int
+get_io(char *symon_buf, int maxlen, char *dev)
+{
+    unsigned int i;
+    struct devstat *ds;
+
+    for (i=0; i < io_numdevs; i++) {
+	ds = &io_stats.dinfo->devices[i];
+
+	if (strncmp(ds->device_name, dev, strlen(ds->device_name)) == 0 &&
+	    strlen(ds->device_name) < strlen(dev) &&
+	    isdigit(dev[strlen(ds->device_name)]) &&
+	    atoi(&dev[strlen(ds->device_name)]) == ds->unit_number) {
+#if DEVSTAT_USER_API_VER == 5
+	    return snpack(symon_buf, maxlen, dev, MT_IO2,
+			  ds->operations[DEVSTAT_READ],
+			  ds->operations[DEVSTAT_WRITE],
+			  (uint64_t) 0, /* don't know how to find #seeks */
+			  ds->bytes[DEVSTAT_READ],
+			  ds->bytes[DEVSTAT_WRITE]);
+
+#else
+	    return snpack(symon_buf, maxlen, dev, MT_IO2,
+			  ds->num_reads,
+			  ds->num_writes,
+			  (uint64_t) 0, /* don't know how to find #seeks */
+			  ds->bytes_read,
+			  ds->bytes_written);
+#endif
+	}
+    }
+
+    return 0;
+}

+ 5 - 8
symon/platform/FreeBSD/sm_mem.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mem.c,v 1.3 2005/02/25 15:10:09 dijkstra Exp $ */
+/* $Id: sm_mem.c,v 1.4 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -104,7 +104,7 @@ init_mem(char *s)
 int
 get_mem(char *symon_buf, int maxlen, char *s)
 {
-#ifdef HAS_VM_NSWAPDEV
+#ifdef HAS_XSWDEV
     int i;
     int vmnswp_dat, vmnswp_siz;
 #endif
@@ -119,17 +119,12 @@ get_mem(char *symon_buf, int maxlen, char *s)
     me_stats[1] = pagetob(me_vmtotal.t_rm);
     me_stats[2] = pagetob(me_vmtotal.t_free);
 
-#ifdef HAS_VM_NSWAPDEV
+#ifdef HAS_XSWDEV
     vmnswp_siz = sizeof (int);
     if (sysctl(me_vmnswp_mib_nam, me_vmnswp_mib_len, &vmnswp_dat, (void *)&vmnswp_siz, NULL, 0) < 0) {
 	warning("%s:%d: sysctl nswapdev failed", __FILE__, __LINE__);
 	vmnswp_dat = 0;
     }
-#endif
-
-    me_stats[3] = me_stats[4] = 0;
-
-#ifdef HAS_VM_NSWAPDEV
     for (i = 0; i < vmnswp_dat; i++) {
 	struct xswdev vmiswp_dat;
 	int vmiswp_siz;
@@ -139,6 +134,8 @@ get_mem(char *symon_buf, int maxlen, char *s)
 	me_stats[3] += (vmiswp_dat.xsw_used * DEV_BSIZE);
 	me_stats[4] += (vmiswp_dat.xsw_nblks * DEV_BSIZE);
     }
+#else
+    me_stats[3] = me_stats[4] = 0;
 #endif
 
     return snpack(symon_buf, maxlen, s, MT_MEM,

+ 233 - 0
symon/platform/FreeBSD/sm_pfq.c

@@ -0,0 +1,233 @@
+/* $Id: sm_pfq.c,v 1.1 2005/03/20 16:17:22 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2005 J. Martin Petersen
+ * 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 altq statistics from pf and return them in symon_buf as
+ * sent_bytes : sent_packets : drop_bytes : drop_packets
+ *
+ * Non re-entrant code: gets_pfq messes with the globals without locking.
+ */
+
+#include "conf.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAS_PFVAR_H
+#include <net/pfvar.h>
+#include <altq/altq.h>
+#include <altq/altq_cbq.h>
+#include <altq/altq_priq.h>
+#include <altq/altq_hfsc.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "error.h"
+#include "symon.h"
+#include "xmalloc.h"
+
+#ifndef HAS_PFVAR_H
+void
+privinit_pfq()
+{
+    fatal("pf support not available");
+}
+void
+init_pfq(char *s)
+{
+    fatal("pf support not available");
+}
+void
+gets_pfq()
+{
+    fatal("pf support not available");
+}
+
+int
+get_pfq(char *b, int l, char *s)
+{
+  fatal("pf support not available");
+  return 0;
+}
+
+#else
+
+union class_stats {
+    class_stats_t cbq;
+    struct priq_classstats priq;
+    struct hfsc_classstats hfsc;
+};
+
+/*
+ * We don't reuse the data structures from altq/altq_{cbq|hfsc|priq}.h as they
+ * are overly complex. For now we only grab the interesting stuff.
+ */
+
+struct altq_stats {
+    char qname[PF_QNAME_SIZE];
+    u_int64_t sent_bytes;
+    u_int64_t sent_packets;
+    u_int64_t drop_bytes;
+    u_int64_t drop_packets;
+};
+
+static struct altq_stats *pfq_stats = NULL;
+static int pfq_numstats = 0;
+int pfq_dev = -1;
+
+void
+privinit_pfq()
+{
+    if ((pfq_dev = open("/dev/pf", O_RDONLY)) == -1) {
+	warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
+    }
+}
+
+void
+init_pfq(char *s)
+{
+    if (pfq_dev == -1) {
+	privinit_pfq();
+    }
+
+    info("started module pfq(%.200s)",s);
+}
+
+void
+gets_pfq()
+{
+    struct pfioc_altq qs;
+    struct pfioc_qstats stats;
+    union class_stats q;
+    unsigned int nqs;
+    unsigned int i;
+
+    bzero(&qs, sizeof(qs));
+    bzero(&stats, sizeof(stats));
+    bzero(&q, sizeof(q));
+
+    if (ioctl(pfq_dev, DIOCGETALTQS, &qs)) {
+	fatal("pfq: DIOCGETALTQS failed");
+    }
+    nqs = qs.nr;
+
+    if (nqs > pfq_numstats) {
+	if (pfq_stats) {
+	    xfree(pfq_stats);
+	}
+
+	pfq_stats = xmalloc(nqs * sizeof(struct altq_stats));
+	pfq_numstats = nqs;
+    }
+
+    /* loop through the queues, copy info */
+    for (i = 0; i < nqs; i++) {
+	qs.nr = i;
+	if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
+	    fatal("pfq: DIOCGETALTQ failed");
+	}
+
+	/* only process the non-empty queues */
+	if (qs.altq.qid > 0) {
+	    stats.nr = qs.nr;
+	    stats.ticket = qs.ticket;
+	    stats.buf = &q;
+	    stats.nbytes = sizeof(q);
+
+	    if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
+		fatal("pfq: DIOCGETQSTATS failed");
+	    }
+
+	    strncpy(pfq_stats[i].qname, qs.altq.qname, PF_QNAME_SIZE);
+
+	    switch (qs.altq.scheduler) {
+	    case ALTQT_CBQ:
+		pfq_stats[i].sent_bytes = q.cbq.xmit_cnt.bytes;
+		pfq_stats[i].sent_packets = q.cbq.xmit_cnt.packets;
+		pfq_stats[i].drop_bytes = q.cbq.drop_cnt.bytes;
+		pfq_stats[i].drop_packets = q.cbq.drop_cnt.packets;
+		break;
+
+	    case ALTQT_PRIQ:
+		pfq_stats[i].sent_bytes = q.priq.xmitcnt.bytes;
+		pfq_stats[i].sent_packets = q.priq.xmitcnt.packets;
+		pfq_stats[i].drop_bytes = q.priq.dropcnt.bytes;
+		pfq_stats[i].drop_packets = q.priq.dropcnt.packets;
+		break;
+
+	    case ALTQT_HFSC:
+		pfq_stats[i].sent_bytes = q.hfsc.xmit_cnt.bytes;
+		pfq_stats[i].sent_packets = q.hfsc.xmit_cnt.packets;
+		pfq_stats[i].drop_bytes = q.hfsc.drop_cnt.bytes;
+		pfq_stats[i].drop_packets = q.hfsc.drop_cnt.packets;
+		break;
+
+	    default:
+		warning("pfq: unknown altq scheduler type (%d) encountered",
+			qs.altq.scheduler);
+		break;
+	    }
+	} else {
+	    /* Make sure the lookup in get_pfq fails immediately whenever
+	     * there's no queue in the slot. We do this by nul'ing the name */
+	    pfq_stats[i].qname[0] = '\0';
+	}
+    }
+}
+
+int
+get_pfq(char *symon_buf, int maxlen, char *queue)
+{
+    unsigned int i;
+
+    for (i = 0; i < pfq_numstats; i++) {
+	if (strncmp(pfq_stats[i].qname, queue, PF_QNAME_SIZE) == 0) {
+	    return snpack(symon_buf, maxlen, queue, MT_PFQ,
+			  pfq_stats[i].sent_bytes,
+			  pfq_stats[i].sent_packets,
+			  pfq_stats[i].drop_bytes,
+			  pfq_stats[i].drop_packets);
+	}
+    }
+
+    return 0;
+}
+
+#endif

+ 43 - 37
symon/platform/FreeBSD/sm_proc.c

@@ -1,4 +1,4 @@
-/* $Id: sm_proc.c,v 1.3 2005/02/25 15:10:10 dijkstra Exp $ */
+/* $Id: sm_proc.c,v 1.4 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -176,44 +176,50 @@ get_proc(char *symon_buf, int maxlen, char *process)
 
     for (pp = proc_ps, i = 0; i < proc_cur; pp++, i++) {
 #ifdef HAS_KI_PADDR
-	 if (strncmp(process, pp->ki_comm, strlen(process)) == 0) {
-	      /* cpu time - accumulated */
-	      if (proc_kd) {
-		   if (kvm_read(proc_kd, (unsigned long)pp->ki_paddr, &pproc,
-				  sizeof(pproc)) == sizeof(pproc)) {
-			cpu_uticks += pproc.p_uticks;  /* user */
-			cpu_sticks += pproc.p_sticks;  /* sys  */
-			cpu_iticks += pproc.p_iticks;  /* int  */
-		   } else {
-			warning("while reading kvm: %s", kvm_geterr(proc_kd));
-		   }
-	      }
-	     /* cpu time - percentage since last measurement */
-	     cpu_pct = pctdouble(pp->ki_pctcpu) * 100.0;
-	     cpu_pcti += cpu_pct;
-	     /* memory size - shared pages are counted multiple times */
-	     mem_procsize += pagetob(pp->ki_tsize + /* text pages */
-				     pp->ki_dsize + /* data */
-				     pp->ki_ssize); /* stack */
-	     mem_rss += pagetob(pp->ki_rssize);     /* rss  */
+	if (strncmp(process, pp->ki_comm, strlen(process)) == 0) {
+	    /* cpu time - accumulated */
+	    if (proc_kd) {
+		if (kvm_read(proc_kd, (unsigned long)pp->ki_paddr, &pproc,
+			     sizeof(pproc)) == sizeof(pproc)) {
+#ifdef HAS_RUSAGE_EXT
+		    cpu_uticks += pproc.p_rux.p_uticks;  /* user */
+		    cpu_sticks += pproc.p_rux.p_sticks;  /* sys  */
+		    cpu_iticks += pproc.p_rux.p_iticks;  /* int  */
 #else
-	 if (strncmp(process, pp->kp_proc.p_comm, strlen(process)) == 0) {
-	     /* cpu time - accumulated */
-	     cpu_uticks += pp->kp_proc.p_uticks;  /* user */
-	     cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
-	     cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
-
-	     /* cpu time - percentage since last measurement */
-	     cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
-	     cpu_pcti += cpu_pct;
-	     /* memory size - shared pages are counted multiple times */
-	     mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
-				     pp->kp_eproc.e_vm.vm_dsize + /* data */
-				     pp->kp_eproc.e_vm.vm_ssize); /* stack */
-	     mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
+		    cpu_uticks += pproc.p_uticks;  /* user */
+		    cpu_sticks += pproc.p_sticks;  /* sys  */
+		    cpu_iticks += pproc.p_iticks;  /* int  */
 #endif
-	     n++;
-	 }
+		} else {
+		    warning("while reading kvm: %s", kvm_geterr(proc_kd));
+		}
+	    }
+	    /* cpu time - percentage since last measurement */
+	    cpu_pct = pctdouble(pp->ki_pctcpu) * 100.0;
+	    cpu_pcti += cpu_pct;
+	    /* memory size - shared pages are counted multiple times */
+	    mem_procsize += pagetob(pp->ki_tsize + /* text pages */
+				    pp->ki_dsize + /* data */
+				    pp->ki_ssize); /* stack */
+	    mem_rss += pagetob(pp->ki_rssize);     /* rss  */
+#else
+	if (strncmp(process, pp->kp_proc.p_comm, strlen(process)) == 0) {
+	    /* cpu time - accumulated */
+	    cpu_uticks += pp->kp_proc.p_uticks;  /* user */
+	    cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
+	    cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
+
+	    /* cpu time - percentage since last measurement */
+	    cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
+	    cpu_pcti += cpu_pct;
+	    /* memory size - shared pages are counted multiple times */
+	    mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
+				    pp->kp_eproc.e_vm.vm_dsize + /* data */
+				    pp->kp_eproc.e_vm.vm_ssize); /* stack */
+	    mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
+#endif
+	    n++;
+	}
     }
 
     /* calc total cpu_secs spent */

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

@@ -1 +1,2 @@
-# $Id: Makefile.inc,v 1.1 2004/09/25 10:21:56 dijkstra Exp $
+# $Id: Makefile.inc,v 1.2 2005/03/22 07:17:43 dijkstra Exp $
+MANDIR=man

+ 235 - 0
symon/platform/OpenBSD/sm_pfq.c

@@ -0,0 +1,235 @@
+/* $Id: sm_pfq.c,v 1.1 2005/03/20 16:17:22 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2005 J. Martin Petersen
+ * 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 altq statistics from pf and return them in symon_buf as
+ * sent_bytes : sent_packets : drop_bytes : drop_packets
+ *
+ * Non re-entrant code: gets_pfq messes with the globals without locking.
+ */
+
+#include "conf.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAS_PFVAR_H
+#include <net/pfvar.h>
+#include <altq/altq.h>
+#include <altq/altq_cbq.h>
+#include <altq/altq_priq.h>
+#include <altq/altq_hfsc.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "error.h"
+#include "symon.h"
+#include "xmalloc.h"
+
+#ifndef HAS_PFVAR_H
+void
+privinit_pfq()
+{
+    fatal("pf support not available");
+}
+void
+init_pfq(char *s)
+{
+    fatal("pf support not available");
+}
+void
+gets_pfq()
+{
+    fatal("pf support not available");
+}
+
+int
+get_pfq(char *b, int l, char *s)
+{
+  fatal("pf support not available");
+  return 0;
+}
+
+#else
+
+union class_stats {
+    class_stats_t cbq;
+    struct priq_classstats priq;
+    struct hfsc_classstats hfsc;
+};
+
+/*
+ * We don't reuse the data structures from altq/altq_{cbq|hfsc|priq}.h as they
+ * are overly complex. For now we only grab the interesting stuff.
+ */
+
+struct altq_stats {
+    char qname[PF_QNAME_SIZE];
+    u_int64_t sent_bytes;
+    u_int64_t sent_packets;
+    u_int64_t drop_bytes;
+    u_int64_t drop_packets;
+};
+
+static struct altq_stats *pfq_stats = NULL;
+static int pfq_numstats = 0;
+int pfq_dev = -1;
+
+void
+privinit_pfq()
+{
+    if ((pfq_dev = open("/dev/pf", O_RDONLY)) == -1) {
+	warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
+    }
+}
+
+void
+init_pfq(char *s)
+{
+    if (pfq_dev == -1) {
+	privinit_pfq();
+    }
+
+    info("started module pfq(%.200s)",s);
+}
+
+void
+gets_pfq()
+{
+    struct pfioc_altq qs;
+    struct pfioc_qstats stats;
+    union class_stats q;
+    unsigned int nqs;
+    unsigned int i;
+
+    bzero(&qs, sizeof(qs));
+    bzero(&stats, sizeof(stats));
+    bzero(&q, sizeof(q));
+
+    if (ioctl(pfq_dev, DIOCGETALTQS, &qs)) {
+	fatal("pfq: DIOCGETALTQS failed");
+    }
+    nqs = qs.nr;
+
+    /* Allocate memory for info for the nqs queues */
+    if (nqs > pfq_numstats) {
+	if (pfq_stats) {
+	    xfree(pfq_stats);
+	}
+
+	pfq_stats = xmalloc(nqs * sizeof(struct altq_stats));
+	pfq_numstats = nqs;
+    }
+
+    /* Loop through the queues, copy info */
+    for (i = 0; i < nqs; i++) {
+	qs.nr = i;
+	if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
+	    fatal("pfq: DIOCGETALTQ failed");
+	}
+
+	/* only process the non-empty queues */
+	if (qs.altq.qid > 0) {
+	    stats.nr = qs.nr;
+	    stats.ticket = qs.ticket;
+	    stats.buf = &q;
+	    stats.nbytes = sizeof(q);
+
+	    if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
+		fatal("pfq: DIOCGETQSTATS failed");
+	    }
+
+	    /* We're now ready to copy the data we want. */
+	    strncpy(pfq_stats[i].qname, qs.altq.qname, PF_QNAME_SIZE);
+
+	    switch (qs.altq.scheduler) {
+	    case ALTQT_CBQ:
+		pfq_stats[i].sent_bytes = q.cbq.xmit_cnt.bytes;
+		pfq_stats[i].sent_packets = q.cbq.xmit_cnt.packets;
+		pfq_stats[i].drop_bytes = q.cbq.drop_cnt.bytes;
+		pfq_stats[i].drop_packets = q.cbq.drop_cnt.packets;
+		break;
+
+	    case ALTQT_PRIQ:
+		pfq_stats[i].sent_bytes = q.priq.xmitcnt.bytes;
+		pfq_stats[i].sent_packets = q.priq.xmitcnt.packets;
+		pfq_stats[i].drop_bytes = q.priq.dropcnt.bytes;
+		pfq_stats[i].drop_packets = q.priq.dropcnt.packets;
+		break;
+
+	    case ALTQT_HFSC:
+		pfq_stats[i].sent_bytes = q.hfsc.xmit_cnt.bytes;
+		pfq_stats[i].sent_packets = q.hfsc.xmit_cnt.packets;
+		pfq_stats[i].drop_bytes = q.hfsc.drop_cnt.bytes;
+		pfq_stats[i].drop_packets = q.hfsc.drop_cnt.packets;
+		break;
+
+	    default:
+		warning("pfq: unknown altq scheduler type encountered");
+		break;
+	    }
+	} else {
+	    /* Make sure the lookup in get_pfq fails immediately whenever
+	     * there's no queue in the slot. We do this by nul'ing the name */
+	    pfq_stats[i].qname[0] = '\0';
+	}
+    }
+}
+
+int
+get_pfq(char *symon_buf, int maxlen, char *queue)
+{
+    unsigned int i;
+
+    for (i = 0; i < pfq_numstats; i++) {
+	if (strncmp(pfq_stats[i].qname, queue, PF_QNAME_SIZE) == 0) {
+	    return snpack(symon_buf, maxlen, queue, MT_PFQ,
+			  pfq_stats[i].sent_bytes,
+			  pfq_stats[i].sent_packets,
+			  pfq_stats[i].drop_bytes,
+			  pfq_stats[i].drop_packets
+		);
+	}
+    }
+
+    return 0;
+}
+
+#endif

+ 32 - 0
symon/platform/stub/sm_pfq.c

@@ -0,0 +1,32 @@
+/* $Id: sm_pfq.c,v 1.1 2005/03/20 16:17:22 dijkstra Exp $ */
+
+#include <stdlib.h>
+
+#include "error.h"
+
+void
+privinit_pfq()
+{
+    fatal("pfq module not available");
+}
+
+void
+init_pfq(char *s)
+{
+    fatal("pfq module not available");
+}
+
+void
+gets_pfq()
+{
+    fatal("pfq module not available");
+}
+
+int
+get_pfq(char *b, int l, char *s)
+{
+    fatal("pfq module not available");
+
+    /* NOT REACHED */
+    return 0;
+}

+ 3 - 3
symon/symon/Makefile

@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.38 2005/02/25 15:10:10 dijkstra Exp $
+# $Id: Makefile,v 1.39 2005/03/20 16:17:22 dijkstra Exp $
 .include "../Makefile.inc"
 .include "../platform/${OS}/Makefile.inc"
 
@@ -26,9 +26,9 @@ symon: ${OBJS}
 clean:
 	rm -f conf.h symon symon.cat8 symon.core ${OBJS}
 
-install: symon symon.cat8 symon.conf
+install: symon symon.8 symon.conf
 	${INSTALL} -c -m 555  -g wheel -o root symon      ${PREFIX}/${BINDIR}
-	${INSTALL} -c -m 444  -g wheel -o root symon.cat8 ${PREFIX}/${MANDIR}/cat8/symon.0
+	${INSTALL} -c -m 444  -g wheel -o root symon.8 ${PREFIX}/${MANDIR}/man8/symon.8
 	${INSTALL} -d -m 555  -g bin   -o root ${PREFIX}/${SHRDIR}
 	${INSTALL} -c -m 555  -g wheel -o root c_config.sh ${PREFIX}/${SHRDIR}
 	${INSTALL} -d -m 555  -g bin   -o root ${PREFIX}/${EXADIR}

+ 4 - 3
symon/symon/readconf.c

@@ -1,4 +1,4 @@
-/* $Id: readconf.c,v 1.21 2004/08/07 12:21:36 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.22 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -87,7 +87,7 @@ read_host_port(struct muxlist * mul, struct mux * mux, struct lex * l)
 
     return 1;
 }
-/* parse "<cpu(arg)|mem|if(arg)|io(arg)|debug|pf|proc(arg)>", end condition == "}" */
+/* parse "<cpu(arg)|mem|if(arg)|io(arg)|debug|pf|pfq(arg)|proc(arg)>", end condition == "}" */
 int
 read_symon_args(struct mux * mux, struct lex * l)
 {
@@ -104,6 +104,7 @@ read_symon_args(struct mux * mux, struct lex * l)
 	case LXT_IO1:
 	case LXT_MEM:
 	case LXT_PF:
+	case LXT_PFQ:
 	case LXT_MBUF:
 	case LXT_DEBUG:
 	case LXT_PROC:
@@ -142,7 +143,7 @@ read_symon_args(struct mux * mux, struct lex * l)
 		return 0;
 	    }
 
-	    break;		/* LXT_CPU/IF/IO/IO1/MEM/PF/MBUF/DEBUG/PROC/SENSOR */
+	    break;		/* LXT_CPU/IF/IO/IO1/MEM/PF/PFQ/MBUF/DEBUG/PROC/SENSOR */
 	case LXT_COMMA:
 	    break;
 	default:

+ 5 - 6
symon/symon/symon.8

@@ -59,10 +59,9 @@ instances in a LAN.
 .Lp
 By default,
 .Nm
-will drop privileges and chroot(2) to home of
-.Ar "_symon".
-This behaviour is not strictly needed for the cpu, mem, mbuf, disk debug and
-interface probes as these will work even when
+will drop privileges and chroot(2) to home of the symon user.  This behaviour
+is not strictly needed for the cpu, mem, mbuf, disk debug and interface probes
+as these will work even when
 .Nm
 is started as
 .Ar "nobody".
@@ -106,8 +105,8 @@ monitor-rule = "monitor" "{" resources "}" [every]
                "stream" ["to"] host [ port ]
 resources    = resource ["(" argument ")"] [ ","|" " resources ]
 argument     = number | interfacename | diskname
-resource     = "cpu" | "mem" | "if" | "io" | "pf" | "debug" |
-               "proc" | "mbuf" | "sensor"
+resource     = "cpu" | "mem" | "if" | "io" | "pf" | "pfq" |
+               "debug" | "proc" | "mbuf" | "sensor"
 every        = "every" time
 time         = "second" | number "seconds"
 host         = ip4addr | ip6addr | hostname

+ 3 - 2
symon/symon/symon.c

@@ -1,7 +1,7 @@
-/* $Id: symon.c,v 1.40 2004/08/08 19:56:03 dijkstra Exp $ */
+/* $Id: symon.c,v 1.41 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2005 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -79,6 +79,7 @@ struct funcmap streamfunc[] = {
     {MT_MBUF, 0, NULL, init_mbuf, NULL, get_mbuf},
     {MT_SENSOR, 0, privinit_sensor, init_sensor, NULL, get_sensor},
     {MT_IO2, 0, NULL, init_io, gets_io, get_io},
+    {MT_PFQ, 0, privinit_pfq, init_pfq, gets_pfq, get_pfq},
     {MT_EOT, 0, NULL, NULL, NULL}
 };
 

+ 9 - 3
symon/symon/symon.h

@@ -1,4 +1,4 @@
-/* $Id: symon.h,v 1.32 2005/01/15 17:31:11 dijkstra Exp $ */
+/* $Id: symon.h,v 1.33 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -49,8 +49,8 @@
  *
  * - privinit = priviledged init, called before chroot
  * - init     = called once, right after configuration
- * - gets     = called every monitor interval, can be used by modules that get all
- *              their measurements in one go.
+ * - gets     = called every monitor interval, can be used by modules that get
+ *              all their measurements in one go.
  * - get      = obtain measurement
  */
 struct funcmap {
@@ -91,6 +91,12 @@ extern void privinit_pf();
 extern void init_pf(char *);
 extern int get_pf(char *, int, char *);
 
+/* sm_pfq.c */
+extern void privinit_pfq();
+extern void init_pfq(char *);
+extern void gets_pfq();
+extern int get_pfq(char *, int, char *);
+
 /* sm_mbuf.c */
 extern void init_mbuf(char *);
 extern int get_mbuf(char *, int, char *);

+ 5 - 4
symon/symux/Makefile

@@ -1,5 +1,6 @@
-# $Id: Makefile,v 1.22 2005/02/25 15:10:10 dijkstra Exp $
+# $Id: Makefile,v 1.23 2005/03/20 16:17:22 dijkstra Exp $
 .include "../Makefile.inc"
+.include "../platform/${OS}/Makefile.inc"
 
 SRCS=	symux.c readconf.c symuxnet.c share.c
 OBJS+=	${SRCS:R:S/$/.o/g}
@@ -17,9 +18,9 @@ symux: ${OBJS}
 clean:
 	rm -f conf.h symux symux.cat8 symux.core ${OBJS}
 
-install: symux symux.cat8 c_smrrds.sh symux.conf
-	${INSTALL} -c -m 555 -g bin   -o root symux      ${PREFIX}/${BINDIR}
-	${INSTALL} -c -m 444 -g wheel -o root symux.cat8 ${PREFIX}/${MANDIR}/cat8/symux.0
+install: symux symux.8 c_smrrds.sh symux.conf
+	${INSTALL} -c -m 555 -g bin   -o root symux	   ${PREFIX}/${BINDIR}
+	${INSTALL} -c -m 444 -g wheel -o root symux.8	   ${PREFIX}/${MANDIR}/man8/symux.8
 	${INSTALL} -d -m 555 -g bin   -o root ${PREFIX}/${SHRDIR}
 	${INSTALL} -c -m 544 -g bin   -o root c_smrrds.sh  ${PREFIX}/${SHRDIR}
 	${INSTALL} -d -m 555 -g bin   -o root ${PREFIX}/${EXADIR}

+ 15 - 4
symon/symux/c_smrrds.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
-# $Id: c_smrrds.sh,v 1.29 2005/02/25 15:10:10 dijkstra Exp $
+# $Id: c_smrrds.sh,v 1.30 2005/03/20 16:17:22 dijkstra Exp $
 
 #
 # Copyright (c) 2001-2005 Willem Dijkstra
@@ -149,7 +149,7 @@ if [ X"$1$2$3$4$5$6$7$8$9" = "X" ]; then
 Create rrd files for symux.
 
 Usage: `basename $0` [oneday] [interval <seconds>] all | cpu0 | mem |
-		   pf | mbuf | debug | proc_<process> |
+		   pf | pfq_<queue> | mbuf | debug | proc_<process> |
 		   <if> | <io> | sensor[0-25]
 
 Where:
@@ -157,6 +157,8 @@ oneday  = modify rrds to only contain one day of information
 seconds = modify rrds for non standard monitoring interval
 process = the name of a process as specified in sy{mon,mux}.conf
 	  e.g. proc(httpd) -> proc_httpd
+queue = the name of a queue as specified in sy{mon,mux}.conf
+	  e.g. pfq(root) -> pfq_root
 
 if=	`echo $INTERFACES|
    awk 'BEGIN  {FS="|"}
@@ -177,7 +179,7 @@ io=	`echo $DISKS|
 		}
 		print " ";}'`
 
-Pre 3.5 disk statistics are available via the io1_<disk> argument.
+OpenBSD pre-3.5 disk statistics are available via the io1_<disk> argument.
 EOF
     exit 1;
 fi
@@ -190,7 +192,7 @@ if [ `echo $i | egrep -e "^($VIRTUALINTERFACES)$"` ]; then i=if_$i.rrd; fi
 # add io_*.rrd if it is a disk
 if [ `echo $i | egrep -e "^($DISKS)$"` ]; then i=io_$i.rrd; fi
 # add .rrd if it is a cpu, etc.
-if [ `echo $i | egrep -e "^(cpu[0-9]$|mem$|pf$|mbuf$|debug$|proc_|sensor[0-9]$|sensor[0-9][0-9]$|io1_)"` ]; then i=$i.rrd; fi
+if [ `echo $i | egrep -e "^(cpu[0-9]$|mem$|pf$|pfq_|mbuf$|debug$|proc_|sensor[0-9]$|sensor[0-9][0-9]$|io1_)"` ]; then i=$i.rrd; fi
 
 if [ -f $i ]; then
     echo "$i exists - ignoring"
@@ -300,6 +302,15 @@ pf.rrd)
 	DS:counters_memory:DERIVE:$INTERVAL:0:U
     ;;
 
+pfq_*.rrd)
+	# Build pfq file
+	create_rrd $i \
+	    DS:sent_bytes:COUNTER:$INTERVAL:0:U \
+	    DS:sent_packets:COUNTER:$INTERVAL:0:U \
+	    DS:drop_bytes:COUNTER:$INTERVAL:0:U \
+	    DS:drop_packets:COUNTER:$INTERVAL:0:U
+	;;
+
 mbuf.rrd)
     # Build mbuf file
     create_rrd $i \

+ 13 - 6
symon/symux/readconf.c

@@ -1,7 +1,7 @@
-/* $Id: readconf.c,v 1.26 2004/08/07 12:21:36 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.27 2005/03/20 16:17:22 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2005 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -85,6 +85,10 @@ insert_filename(char *path, int maxlen, int type, char *args)
 	ts = "pf";
 	ta = "";
 	break;
+    case MT_PFQ:
+	ts  = "pfq_";
+	ta = args;
+	break;
     case MT_MBUF:
 	ts = "mbuf";
 	ta = "";
@@ -107,10 +111,11 @@ insert_filename(char *path, int maxlen, int type, char *args)
 	return 0;
     }
 
-    if ((snprintf(path, maxlen, "/%s%s.rrd", ts, ta)) >= maxlen)
+    if ((snprintf(path, maxlen, "/%s%s.rrd", ts, ta)) >= maxlen) {
 	return 0;
-    else
+    } else {
 	return 1;
+    }
 }
 /* mux <host> (port|,| ) <number> */
 int
@@ -195,6 +200,7 @@ read_source(struct sourcelist * sol, struct lex * l)
 		case LXT_IO1:
 		case LXT_MEM:
 		case LXT_PF:
+		case LXT_PFQ:
 		case LXT_MBUF:
 		case LXT_DEBUG:
 		case LXT_PROC:
@@ -307,9 +313,9 @@ read_source(struct sourcelist * sol, struct lex * l)
 
 		    /* try filename */
 		    if ((fd = open(path, O_RDWR | O_NONBLOCK, 0)) == -1) {
+			/* warn, but allow */
 			warning("%.200s:%d: file '%.200s', guessed by datadir,  cannot be opened",
 				l->filename, l->cline, path);
-			return 0;
 		    } else {
 			close(fd);
 			stream->file = xstrdup(path);
@@ -327,6 +333,7 @@ read_source(struct sourcelist * sol, struct lex * l)
 	    case LXT_IO1:
 	    case LXT_MEM:
 	    case LXT_PF:
+	    case LXT_PFQ:
 	    case LXT_MBUF:
 	    case LXT_DEBUG:
 	    case LXT_PROC:
@@ -386,7 +393,7 @@ read_source(struct sourcelist * sol, struct lex * l)
 			stream->file = xstrdup(l->token);
 		    }
 		}
-		break;		/* LXT_CPU/IF/IO/IO1/MEM/PF/MBUF/DEBUG/PROC/SENSOR */
+		break;		/* LXT_CPU/IF/IO/IO1/MEM/PF/PFQ/MBUF/DEBUG/PROC/SENSOR */
 	    default:
 		parse_error(l, "{cpu|if|io|mem|pf|mbuf|debug|proc|sensor}");
 		return 0;

+ 5 - 2
symon/symux/symux.8

@@ -113,8 +113,8 @@ accept-stmts = accept-stmt [accept-stmts]
 accept-stmt  = "accept" "{" resources "}"
 resources    = resource version ["(" argument ")"]
                [ ","|" " resources ]
-resource     = "cpu" | "mem" | "if" | "io" | "pf" | "debug" |
-               "proc" | "mbuf" | "sensor"
+resource     = "cpu" | "mem" | "if" | "io" | "pf" | "pfq" |
+               "debug" | "proc" | "mbuf" | "sensor"
 version      = "" | number
 argument     = number | interfacename | diskname
 datadir-stmt = "datadir" dirname
@@ -248,6 +248,9 @@ totmem : totpct : m_drops : m_wait : m_drain ).
 .It sensor
 Single sensor value. ( value ) Value is a double that is offered with 7.6
 precision. Value depends on sensor type.
+.It pfq
+pf/altq queue statistics ( sent_bytes : sent_packets : drop_bytes :
+drop_packets ). Values are 64 bit unsigned integers.
 .El
 .Sh SIGNALS
 .Bl -tag -width Ds