Date: 11 Dec 2002 01:45:46 -0500 From: Joe Marcus Clarke <marcus@marcuscom.com> To: George Hartzell <hartzell@kestrel.alerce.com> Cc: James Pole <james.pole@paradise.net.nz>, freebsd-gnome@FreeBSD.ORG Subject: Re: gnome2, FreeBSD4.7p2, system load applet doesn't do network traffic Message-ID: <1039589145.340.34.camel@gyros> In-Reply-To: <15862.56369.942861.984708@rosebud.alerce.com> References: <15862.45748.578341.891916@rosebud.alerce.com> <1039579485.340.23.camel@gyros> <1039587894.283.6.camel@localhost> <1039588032.340.28.camel@gyros> <15862.56369.942861.984708@rosebud.alerce.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-+b1i/Sey/A5g+DVy5SlA Content-Type: text/plain Content-Transfer-Encoding: 7bit On Wed, 2002-12-11 at 01:33, George Hartzell wrote: > Joe Marcus Clarke writes: > > On Wed, 2002-12-11 at 01:24, James Pole wrote: > > > On Wed, 2002-12-11 at 17:04, Joe Marcus Clarke wrote: > > > > This doesn't work. netload wants /proc to be the Linux proc > > > > filesystem. This isn't going to happen. We would need to write > > > > specific FreeBSD modules for multiload. I would be happy to accept > > > > patches. > > > > > > Can't we use linprocfs(5) rather than FreeBSD's native procfs? > > > > No. We need /proc/dev/net. I'm actually finishing up some hacked > > patches that may get this working under FreeBSD. Interested? > > Rats. And here I thought I'd actually found a bite-sized project that > was just festering in the corner so no one would do-it-before-I-did. > > I'm game to wack at it tomorrow or Thursday, and probably have all of > the requisite system-y concepts down. It'll be a good intro to a bit > more gnome-y stuff. > > If it isn't finished, and you have other things to do, let me know. Well, it probably could be better (and it may not work), but here it is. If you're volunteering for FreeBSD GNOME-related projects, I can come up with a few. For example, anyone want to fix it so scrollkeeper uses XML_CATALOG_FILES so that we can use an alternate catalog directory? Joe > > g. -- PGP Key : http://www.marcuscom.com/pgp.asc --=-+b1i/Sey/A5g+DVy5SlA Content-Disposition: attachment; filename=patch-multiload_linux-proc.c Content-Type: text/x-c; name=patch-multiload_linux-proc.c; charset=ISO8859-1 Content-Transfer-Encoding: 7bit --- multiload/linux-proc.c.orig Wed Dec 11 00:59:16 2002 +++ multiload/linux-proc.c Wed Dec 11 01:39:33 2002 @@ -1,14 +1,17 @@ /* From wmload.c, v0.9.2, licensed under the GPL. */ #include <config.h> #include <sys/types.h> +#include <sys/socket.h> #include <math.h> #include <fcntl.h> #include <unistd.h> #include <assert.h> +#include <net/if.h> #include <glibtop.h> #include <glibtop/cpu.h> #include <glibtop/mem.h> +#include <glibtop/netload.h> #include <glibtop/swap.h> #include <glibtop/loadavg.h> @@ -33,6 +36,10 @@ static unsigned needed_loadavg_flags = (1 << GLIBTOP_LOADAVG_LOADAVG); +static unsigned needed_netload_flags = +(1 << GLIBTOP_NETLOAD_IF_FLAGS) + +(1 << GLIBTOP_NETLOAD_PACKETS_TOTAL); + void GetLoad (int Maximum, int data [4], LoadGraph *g) { @@ -229,12 +236,6 @@ #define ETH_COUNT 2 #define OTHER_COUNT 3 #define COUNT_TYPES 4 - int fields[4], present[COUNT_TYPES], delta[COUNT_TYPES], i; - static int ticks, past[COUNT_TYPES]; - static char *netdevfmt; - char *cp, buffer[256]; - int found = 0; - FILE *fp; /* * We use the maximum number of bits we've seen come through to scale @@ -247,102 +248,32 @@ */ static int max = 500; - if (!netdevfmt) - { - FILE *fp = popen("uname -r", "r"); /* still wins if /proc isn't */ - - /* pre-linux-2.2 format -- transmit packet count in 8th field */ - netdevfmt = "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d"; - - if (!fp) - return; - else - { - int major, minor; - - if (fscanf(fp, "%d.%d.%*d", &major, &minor) != 2) - { - pclose(fp); - return; - } - - if (major >= 2 && minor >= 2) - /* Linux 2.2 -- transmit packet count in 10th field */ - netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %*d %d %*d %d"; - pclose(fp); - } - } + struct if_nameindex *ifs, *ifstart; + glibtop_netload netload; - fp = fopen("/proc/net/dev", "r"); - if (!fp) - return; - - memset(present, '0', sizeof(present)); - - while (fgets(buffer, sizeof(buffer) - 1, fp)) - { - int *resp; - - for (cp = buffer; *cp == ' '; cp++) - continue; - - resp = present + OTHER_COUNT; - switch (cp[0]) { - case 'l': - if (cp[1] == 'o') - continue; - break; - case 's': - if (!strncmp (cp+1, "lip", 3)) - resp = present + SLIP_COUNT; - break; - case 'p': - if (!strncmp (cp+1, "pp", 2)) - resp = present + PPP_COUNT; - break; - case 'e': - if (!strncmp (cp+1, "th", 2)) - resp = present + ETH_COUNT; - break; - } + ifs = ifstart = if_nameindex(); - if ((cp = strchr(buffer, ':'))) - { - cp++; - if (sscanf(cp, netdevfmt, - fields, fields+1, fields+2, - fields+3,&found)>4) - *resp += fields[0] + fields[2]; + while (ifs && ifs->if_name) { + if (strncmp(ifs->if_name, "lo0", 3)) { + glibtop_get_netload (&netload, ifs->if_name); + assert ((netload.flags & needed_netload_flags) == needed_netload_flags); + if (strncmp(ifs->if_name, "sl", 2)) { + data[SLIP_COUNT] = rint((float) Maximum * (netload.packets_total / max)); + } + else if (strncmp(ifs->if_name, "tun", 3) || + strncmp(ifs->if_name, "ppp", 3)) { + data[PPP_COUNT] = rint((float) Maximum * (netload.packets_total / max)); + } + /* XXX BIG HACK! */ + else if (netload.if_flags & (GLIBTOP_IF_FLAGS_UP | GLIBTOP_IF_FLAGS_BROADCAST)) { + data[ETH_COUNT] = rint((float) Maximum * (netload.packets_total / max)); + } + else { + data[OTHER_COUNT] = rint((float) Maximum * (netload.packets_total / max)); + } } } - fclose(fp); + if_freenameindex(ifstart); - memset(data, '\0', sizeof(data)); - if (ticks++ > 0) /* avoid initial spike */ - { - int total = 0; - - for (i = 0; i < COUNT_TYPES; i++) - { - delta[i] = (present[i] - past[i]); - total += delta[i]; - } - if (total > max) - max = total; - for (i = 0; i < COUNT_TYPES; i++) - data[i] = rint (Maximum * (float)delta[i] / max); - -#if 0 - printf("dSLIP: %9d dPPP: %9d dOther: %9d, max: %9d\n", - delta[SLIP_COUNT], delta[PPP_COUNT], delta[OTHER_COUNT], max); - - printf("vSLIP: %9d vPPP: %9d vOther: %9d, Maximum: %9d\n", - data[0], data[1], data[2], Maximum); -#endif - } - memcpy(past, present, sizeof(present)); } - - - --=-+b1i/Sey/A5g+DVy5SlA-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-gnome" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1039589145.340.34.camel>