[comp.sys.dec] average load statistics on DS300?

macomber@thoreau.nsc.com (Robert Macomber) (03/03/90)

I'm having trouble extracting average load statistics on a DS3100.
It's a loaner machine running ULTRIX (version 3.0, I think).
I've tried compiling the "stats" remote statistics server and the "top"
performance monitor, but both come up with zero values for the avenrun
variables.  There must be some way, because "xload" seems to work
okay.

If some kind soul knows the answer (or better yet has a working version
of rstatd) I'd be grateful to learn about it.

Thanks in Advance.
-- 
			Robert L. Macomber
 		      National Semiconductor
		       South Portland, Maine
		      macomber@thoreau.nsc.com

alan@shodha.dec.com ( Alan's Home for Wayward Notes File.) (03/03/90)

In article <33@thoreau.nsc.com>, macomber@thoreau.nsc.com (Robert Macomber) writes:
> 
> I'm having trouble extracting average load statistics on a DS3100.
> It's a loaner machine running ULTRIX (version 3.0, I think).
> I've tried compiling the "stats" remote statistics server and the "top"
> performance monitor, but both come up with zero values for the avenrun
> variables.  There must be some way, because "xload" seems to work
> okay.

	The load average is stored in a data structure called
	"avenrun" (you probably already know this).  On a VAX
	system type of avenrun is double.  On the DECstation it
	is type "fix".  There is an include file you'll be interested
	in called <sys/fixpoint.h>.  To convert fix to double use
	FIX_TO_DBL().

> 
> Thanks in Advance.

	You're welcome.

> -- 
> 			Robert L. Macomber
-- 
Alan Rollow				alan@nabeth.enet.dec.com

bin@primate.wisc.edu (Brain in Neutral) (03/04/90)

Something I have used to get load average out of a MIPS M/120.  Might
be useful on a DECstation as well... strip out the irrelevant junk...

/*
	RISC/os 4.0 version

	xloadback - back end for xload for machines with no X server.
	Just sends load average to stdout every now and then.  Should
	attach over network to xloadfront process on machine with X
	server that reads it and displays it a la regular xload.

	Sends the load*100 as a 32-bit quantity in network byte order.

	12 July 1989	Paul DuBois	dubois@rhesus.primate.wisc.edu
*/

# include	<stdio.h>
# include	<nlist.h>
# include	<sys/fixpoint.h>
# include	<sys/file.h>


# define	UNIX		"/unix"
# define	KMEM_FILE	"/dev/kmem"
# define	KMEM_ERROR	"cannot open /dev/kmem"


# define	LOADAV	0

struct nlist namelist[] = {		    /* namelist for vmunix grubbing */
	{"avenrun"},
	{0}
};

char	hostname[256];


main ()
{
register	int kmem;		/* kmem pointer */
long		lavgSeek;		/* offset to load average in kmem */

ufix	tmpLoad;	/* system load info */
long	iLoad;

	if (gethostname (hostname, sizeof (hostname)))
		smerror ("don't know hostname");

	/* Get name list. Then open kmem so we can seek for information */

	nlist(UNIX, namelist);
	if (namelist[LOADAV].n_type == 0)
		smerror("cannot get name list");
	lavgSeek = namelist[LOADAV].n_value;
	kmem = open(KMEM_FILE, O_RDONLY);
	if (kmem < 0)
		smerror(KMEM_ERROR);
	write (1, hostname, strlen (hostname) + 1);
	for (;;)
	{
		sleep (5);
		lseek(kmem, lavgSeek, 0);
		read(kmem, (char *) &tmpLoad, sizeof (tmpLoad));
		iLoad = (long) (FIX_TO_DBL (tmpLoad) * 100.0);
		iLoad = htonl (iLoad);
printf ("%d %d %g\n", iLoad, ntohl (iLoad), FIX_TO_DBL (tmpLoad));
		/*write(1, (char *) &iLoad, sizeof (iLoad));*/
		fflush (stdout);
	}
}



/* Diagnostic printer - Print message and exit */

smerror(message)
char	*message;
{
	fprintf (stderr, "%s\n", message);
	exit(1);
}

litwack@dccs.upenn.edu (Mark Litwack) (03/07/90)

jim@mango.miami.edu (jim brown) just posted patches for top
on comp.sources.bugs that fixes the problems on the DS3100.

-mark