//
// Examples from the pmie(1) man page
//

delta = 1 sec;		// force evaluation once per second

//
// If the total context switch rate exceeds 10000 per second per CPU
// then display an alarm notifier
//
kernel.all.pswitch / hinv.ncpu > 10000 count/sec
    -> alarm "high context switch rate %v";

all_sample (
    kernel.all.pswitch @0..9 > 10 Kcount/sec * hinv.ncpu
) -> shell 5 min "xterm -e 'top'";


delta = 5 sec;		// force evaluation once every 5 seconds from here on

// If for any disk, for all 4 samples (20 seconds), the disk is performing
// more than 40 I/Os per second, then print a message to standard output and
// then launch dkvis(1)
//
some_inst all_sample
    disk.dev.total @0..3 > 40 count/sec
	-> print "disks busy for 20 sec:" " %i" &
	   shell 5 min "dkvis";

// If any disk is performing more than 60 I/Os per second, then
// print a message identifying the busy disk to standard output and
// launch dkvis(1)
some_inst (
    disk.dev.total > 60 count/sec
) -> print "busy disks:" " %i" &
     shell 5 min "dkvis";


//
// Refine the preceding rule to apply only between the hours of 9am and 5pm,
// and to require that just 3 of the four samples exceed the threshold
//
$hour >= 9 && $hour <= 17 && some_inst 75 %_sample
    disk.dev.total @0..3 > 40 count/sec
	-> print "disk busy for 20 sec" &
	   shell 5 min "dkvis";

//
// Refine the preceding rule further to print the host name and disk name
// for which the threshold is exceeded
//
$hour >= 9 && $hour <= 17 &&
some_inst (
    75 %_sample (
	disk.dev.total @0..3 > 40 count/sec
    )
) -> print "disks busy for 20 sec:" " [%h]%i";

//
// Macro for use ...
//
bc = "buffer_cache";
// Using the above macro; If the buffer cache is in use (more than 50 read
// requests) with hit ratio less than 90%, then popup an alarm
//
$bc.getblks > 50 && $bc.getfound / $bc.getblks < 0.9
    -> alarm "poor buffer cache hit rate";

delta = 10 mins;	// force evaluation once every 10 minutes from here on

// If either the / or the /usr filesystem is more than 95% full, display
// an alarm popup, but not if it has already been displayed during the last
// 24 hours
//
filesys.free #'/dev/root' / filesys.capacity #'/dev/root' < 0.05
    -> alarm 24 hour "root filesystem (almost) full";
filesys.free #'/dev/usr' / filesys.capacity #'/dev/usr' < 0.05
    -> alarm 24 hour "/usr filesystem (almost) full";

//
// The following rule requires a machine that supports the PCP environment
// metrics. If the machine environment temperature rises more than 2
// degrees over a 10 minute interval, write an entry in the system log
//
environ.temp @1 - environ.temp @0 > 2
    -> alarm "temperature rising fast" &
       syslog "machine room temperature rise alarm";

//
// Something interesting if you have performance problems with
// your Oracle data base ...
//
db = "oracle.ptg1";
host = ":moomba.melbourne.sgi.com";
lru = "#'cache buffers lru chain'";
gets = "$db.latch.gets $host $lru";
total = "$db.latch.gets $host $lru + $db.latch.misses $host $lru +
	$db.latch.immisses $host $lru";

$total > 100 && $gets / $total < 0.2
    -> alarm "high LRU latch contention";

// Busy disk?

delta = 20 sec;		// force evaluation once every 20 seconds from here on

// If any disk is performing more than 60 I/Os per second, then
// print a message to standard output and launch dkvis(1)
//
some_inst
    disk.dev.total > 60 count/sec
	-> print "disk busy for 20 sec" "%v IOPS %i@%h" &
	   shell 5 min "dkvis";

delta = 1 minute;
ruleset
     kernel.all.load #'1 minute' > 10 * hinv.ncpu ->
         print "extreme load average %v"
else kernel.all.load #'1 minute' > 2 * hinv.ncpu ->
         print "moderate load average %v"
unknown ->
         print "load average unavailable"
otherwise ->
         print "load average OK"
;

