//
// Examples from the Performance Co-Pilot User's and Administrator's Guide
//

//
// a simple expression, with multiple values
//
iops = disk.dev.total;


//
// total disk write percentage
//
wrt_pct = (disk.all.write / disk.all.total) * 100;

//
// some varied expressions
//
pct_wrt = (disk.all.write / disk.all.total) * 100;
busy_wrt = disk.dev.total > 10 &&
	   disk.dev.write > disk.dev.read;
busy = some_inst disk.dev.total > 60 -> print "[%i] high disk i/o ";


//
// simple use of a macro
//
disk = "disk.all";
pct_wrt = ($disk.write / $disk.total) * 100;



//
// perverse example to show all possible choices of units for numeric
// constants
//
mem.freemem > 1 byte;
mem.freemem > 1 Kbyte; 
mem.freemem > 1 Mbyte;
mem.freemem > 1 Gbyte;
mem.freemem > 1 Tbyte;

disk.dev.blktotal > 1 Mbyte / nsec;
disk.dev.blktotal > 1 Mbyte / nanosecond;
disk.dev.blktotal > 1 Mbyte / usec;
disk.dev.blktotal > 1 Mbyte / microsecond;
disk.dev.blktotal > 1 Mbyte / msec;
disk.dev.blktotal > 1 Mbyte / millisecond;
disk.dev.blktotal > 1 Mbyte / sec;
disk.dev.blktotal > 1 Mbyte / second;
disk.dev.blktotal > 1 Mbyte / min;
disk.dev.blktotal > 1 Mbyte / minute;
disk.dev.blktotal > 1 Mbyte / hour;

hinv.ncpu > 1 count;
hinv.ncpu > 1 Kcount;
hinv.ncpu > 1 count;
hinv.ncpu > 1 Gcount;
hinv.ncpu > 1 Tcount;

mem.freemem > 1 bytes;
mem.freemem > 1 Kbytes; 
mem.freemem > 1 Mbytes;
mem.freemem > 1 Gbytes;
mem.freemem > 1 Tbytes;

disk.dev.blktotal > 1 Mbyte / nsecs;
disk.dev.blktotal > 1 Mbyte / nanoseconds;
disk.dev.blktotal > 1 Mbyte / usecs;
disk.dev.blktotal > 1 Mbyte / microseconds;
disk.dev.blktotal > 1 Mbyte / msecs;
disk.dev.blktotal > 1 Mbyte / milliseconds;
disk.dev.blktotal > 1 Mbyte / secs;
disk.dev.blktotal > 1 Mbyte / seconds;
disk.dev.blktotal > 1 Mbyte / mins;
disk.dev.blktotal > 1 Mbyte / minutes;
disk.dev.blktotal > 1 Mbyte / hours;

hinv.ncpu > 1 counts;
hinv.ncpu > 1 Kcounts;
hinv.ncpu > 1 counts;
hinv.ncpu > 1 Gcounts;
hinv.ncpu > 1 Tcounts;


//
// metric expressions

// all instances
// 
enet = network.interface.total.packets;

// restricted instance (loopback interface only)
// 
enet_r = network.interface.total.packets #lo0;

// restricted instances with weird instance names ...
// note instance names are "identifiers" in the grammar, so single
// quotes required for tricky characters, like /, spaces, etc, _not_
// double quotes
//
root_n_usr = filesys.free #'/dev/root' #'/dev/usr';

// multiple hosts
//
num_cpu = hinv.ncpu :babylon.engr.sgi.com :gonzo :sandpit;

// multiple sample times
//
mem_trend = mem.freemem @0..3;

// multi-dimension variations
//

// missing instance for non-singular instance domain, plus multiple hosts
//
net_view = network.interface.total.packets :gonzo :moomba;

//
// relational (logical) expressions
//
hosts = ":gonzo";
intfs = "#ec0 #ec2";
all_intf = network.interface.in.packets
		$hosts $intfs @0..2 > 300 count/sec;

//
// quantification examples
//

// some_instance
all_intf = network.interface.in.packets
		#ec0 #ec2 @0..2 > 300 count/sec;
any_sample = some_sample
		network.interface.in.packets
		    #ec0 #ec2 @0..2 > 300 count/sec;



//
// nested quantification
//

Servers = ":moomba :gonzo";		// change as desired

// read and write rate per disk per host
//
rd = disk.dev.read $Servers;
wr = disk.dev.write $Servers;

// one value per host, true if 20% or more of the disks are doing
// significant reading or writing
//
rd_20 = 20%_inst disk.dev.read $Servers > 40;
wr_20 = 20%_inst disk.dev.write $Servers > 40;

// single truth value: more than 20% of the disks busy reading or writing
//			on all hosts?
//
summary = all_host ( 
		20%_inst disk.dev.read $Servers > 40 || 
		20%_inst disk.dev.write $Servers > 40
	    );

// alternate form
//
summary2 = all_host (
		20%_inst (
		    disk.dev.read $Servers > 40 ||
		    disk.dev.write $Servers > 40
		)
	  );

//
// a rule expression with multiple actions and %-binding in the
// arguments for the action methods
//
some_inst ( disk.dev.total > 60 )
    -> syslog 10 mins "[%i] busy, %v IOPS " &
       shell 1 hour "echo 'Disk %i is REALLY busy. Running at %v I/Os per second' | Mail -s 'pmie alarm' sysadm";

//
// a rule expression with multiple actions and %-binding in the
// arguments for the action methods ... use some creative string
// composition for the final message
//
some_inst ( disk.dev.total > 50 )
    -> syslog 10 mins "Busy disks: " "%i @ %v IOPS " &
       shell 1 hour "echo 'REALLY busy disks: " "%i @ %v I/Os per second " "' | Mail -s 'pmie alarm' sysadm";


//
// intrinsic operators
//

m = mem.freemem;
rate_m = rate mem.freemem;

// At least 2 CPUs doing some reasonable amount of work
//
poke = ":moomba :'mac-larry' :bitbucket";    // note '' to escape - in host name
u = kernel.percpu.cpu.user $poke;
s = kernel.percpu.cpu.sys $poke;
some_host (
    count_inst ( kernel.percpu.cpu.user $poke +
		 kernel.percpu.cpu.sys $poke > 0.7 ) >= 2
    )
	-> alarm "2 or more busy CPUs";

