// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// Examples from the Performance Co-Pilot User's and Administrator's Guide
//

// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// a simple expression, with multiple values
//
iops = disk.dev.total;


// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// total disk write percentage
//
wrt_pct = (disk.all.write / disk.all.total) * 100;

// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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 ";


// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// simple use of a macro
//
disk = "disk.all";
pct_wrt = ($disk.write / $disk.total) * 100;



// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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;


// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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;

// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// relational (logical) expressions
//
hosts = ":gonzo";
intfs = "#ec0 #ec2";
all_intf = network.interface.in.packets
		$hosts $intfs @0..2 > 300 count/sec;

// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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;



// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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
		)
	  );

// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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";

// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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";


// Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// 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";

