[Prev][Next][Index][Thread]

# Re: @hoststats code

- Date: Fri, 5 Jan 1996 06:45:18 PST
- From:
- Content-Md5: NRQwfCr7Ewbd8tWqwVfK3A==
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii

    Oh, OK.  I did consider this, but since it's more than a little Solaris-centric
    I wasn't sure how useful it would be.  I'll include 2 versions of the shell
    script, the one that's best and the one that works on Solaris 2.3 (the
    /usr/ucb/ps in 2.3 and below is crap) and the MOO verb that is required to use
    it.  I suggest you try the best one first, then the lesser one, and play about
    with the fields taken from the ls and ps commands if it looks wrong.  The main
    thing here is the use of the /proc directory, which should be in most SVR4
    systems.  If you don't have it, you'll have to take the SZ field from the ps,
    which is a little less accurate (it's in K not bytes, and over 10M tends to
    collide with the previous column).

    Like I say, it needs FUP installed to allow executables.

    The Scripts are:

    Best:

    #! /bin/csh -f
    set prog = moostat
    set name = moo
    set size = 0
    set mem = 0
    set cpu = 0
    set pid = `/usr/bin/ps -e | grep $name |grep -v grep |grep -v $prog| awk '{print
    $1}'`
    foreach a ($pid)
     set onesize = `cd /proc; /usr/bin/ls -l *$a | awk '{print $5}'`
     set onestat = `/usr/ucb/ps -au | grep $a|grep -v grep| awk -F" " '{printf
    "%2.2f %%Memory, %2.2f
     %%CPU.", $4, $3}'`
     @ size=$size + $onesize
     set mem = `echo $mem + $onestat[1] |bc`
     set cpu = `echo $cpu + $onestat[3] |bc`
     echo "Size of $name (pid $a)" = $onesize Bytes, $onestat
    end
    echo "Total size:           = "$size Bytes, $mem %Memory, $cpu %CPU.
    set swap = `/usr/sbin/swap -s | awk '{print $11}'`
    echo Swap available: $swap Bytes
    set host = `w -u`
    echo System: $host
    uname -a

    -----

    Lesser:

    #! /bin/csh -f
    set prog = moostat
    set name = moo
    set size = 0
    set mem = 0
    set cpu = 0
    set pid = `/usr/bin/ps -e | grep $name |grep -v grep |grep -v $prog| awk '{print
    $1}'`
    foreach a ($pid)
     set onesize = `cd /proc; /usr/bin/ls -l *$a | awk '{print $5}'`
     @ size=$size + $onesize
     echo "Size of $name (pid $a)" = $onesize Bytes.
    end
    echo "Total size:           = "$size Bytes.
    set swap = `/usr/sbin/swap -s | awk '{print $11}'`
    echo Swap available: $swap Bytes
    set host = `w -u`
    echo System: $host
    /usr/bin/uname -a

    -----

    Verb spiffy wizard:@hoststats:

    "Calls a shellscript in the FUP bin directory to gain some quick stats about the
    MOOs host.";
    if (!player.wizard)
      player:tell("Bug off!");
      return;
    endif
    if (filerun("moostat",{},{"","mooout"}) != 1)
      player:tell("Unable to execute the moostat script!");
    else
    output = fileread("","mooout");
    player:tell("Current Host stats:");
    player:tell_lines(output);
    endif

    -----
    Hope some of you find this useful.  Doesn't need root perms, BTW.

    Moredhel/TC.

- Prev: @hoststats code
- Next: [APROG] re: overflow output buffer
- Index: MOO-cows
- Thread: MOO-cows

Home | Subject Index | Thread Index