< ?
//SYSVERSION:0.0.4
//
//This Function does change management on the processor and memory subsystem,
//What it will do is tell us when we are adding or changing processors and memory
//Get the information.
//Created on 2006-05-18
function SYS_cmproc($DEBUG,$hostname,$OS,$OSRevision,$Arch) {
if ($OS == "SunOS") {
//We are going to look at the output of several commands:
//psrinfo -p to get number of physcial processors
//psrinfo to get the total number of cores
//psrinfo -v to get the processor speed
//prtconf to get the memory in the machine
$NumberOfPhysical=trim(shell_exec("/usr/sbin/psrinfo -p"));
if (!is_numeric($NumberOfPhysical)) {
//Must be the latest patches are not on the machine to show the -p, it probably also does not have virutalprocessors
//Therefore need to do NumberOfPhyiscal will be like NumberOfVirutal
$NumberOfPhysical=trim(shell_exec("/usr/sbin/psrinfo | /bin/wc -l | /bin/sed ’s/ //g’"));
//Also need to drop the OSRevision back to 5.8 so it can grab the info from prtconf as opposed to psrinfo
$OSRevision="5.8";
}
$NumberOfVirtual=trim(shell_exec("/usr/sbin/psrinfo | /bin/wc -l | /bin/sed ’s/ //g’"));
$FirstProcessor=trim(shell_exec("/usr/sbin/psrinfo | /bin/head -1 | /bin/awk ‘{print $1}’"));
$ProcessorSpeed=trim(shell_exec("/usr/sbin/psrinfo -v $FirstProcessor | /bin/grep operates | /bin/awk ‘{print $6}’"));
$MemorySize=trim(shell_exec("/usr/sbin/prtconf | /bin/grep Memory | /bin/head -1 | /bin/awk ‘{print $3}’"));
//Processor type, different ways for 5.8,5.9 and 5.10
if ($OSRevision=="5.8") {
//psrinfo command does not work for this OS as it is missing the -p option, so get the info out
//of prtconf -v grep for Ultra (we don’t really have any machines running 8 that are not Ultra’s anymore
//This will also assume that the machine is running the same type of processor for all processors
if ($Arch == "sparc" ) {
$ProcessorType=shell_exec("/usr/sbin/prtconf | /bin/grep Ultra | /bin/awk -F’,’ ‘{print $2}’ | /bin/awk ‘{print $1}’ | /bin/head -1");
}
if ($Arch == "i86pc" ) {
$ProcessorType="Generic Intel";
}
}
if ($OSRevision=="5.9") {
//Need to find the first processor, do NOT assume that 0 will be it. that does not work on the E25K!
//Use the $FirstProcessor from above
if ($Arch == "sparc") {
$ProcessorType=shell_exec("/usr/sbin/psrinfo -pv $FirstProcessor | /bin/awk ‘{print $2}’");
}
if ($Arch == "i86pc" ) {
$ProcessorType="Intel";
}
}
if ($OSRevision=="5.10") {
//Need to find first processor same as for 5.9, but the output of psrinfo has changed
if ($Arch == "sparc" ) {
$ProcessorType=shell_exec("/usr/sbin/psrinfo -pv $FirstProcessor |/bin/tail -1 | /bin/awk ‘{print $1}’");
}
if ($Arch == "i86pc" ) {
$ProcessorTypeT=shell_exec("/usr/sbin/psrinfo -pv $FirstProcessor | /bin/tail -1");
$ProcessorType=trim($ProcessorTypeT);
}
}
$ProcessorType=trim($ProcessorType);
}
if ($OS == "AIX" ) {
//Going to use the following commands to get the number of processors and memory
//lsdev -C | grep -c proc
//lsattr -El proc# to get the speed and processor type
$NumberOfPhysical=trim(shell_exec("/usr/sbin/lsdev -C | /usr/bin/grep -c proc"));
$FirstProcessor=trim(shell_exec("/usr/sbin/lsdev -C | /usr/bin/grep proc | /usr/bin/head -1 | /usr/bin/awk ‘{print $1}’"));
$ProcessorType=trim(shell_exec("/usr/sbin/lsattr -El $FirstProcessor | /usr/bin/grep type | /usr/bin/awk ‘{print $2}’"));
$ProcessorSpeed=trim(shell_exec("/usr/sbin/lsattr -El $FirstProcessor | /usr/bin/grep Speed | /usr/bin/awk ‘{print $2}’"));
$ProcessorSpeed=sprintf("%d",$ProcessorSpeed/1024/1024); //Speed in MHZ
$MemorySize=trim(shell_exec("/usr/sbin/lsattr -El mem0 | /usr/bin/grep Total | /usr/bin/awk ‘{print $2}’"));
$NumberOfVirtual=$NumberOfPhysical; //Not sure how to find them at the moment as we have no machines that have them
}
if ($OS == "Linux" ) {
//cat /proc/cpuinfo | grep -c processor
//cat /proc/meminfo
$NumberOfPhysical=trim(shell_exec("/bin/cat /proc/cpuinfo | /bin/grep -c processor"));
$ProcessorType=trim(shell_exec("/bin/cat /proc/cpuinfo | /bin/grep \"model name\" | /bin/awk -F: ‘{print $2}’ |/usr/bin/uniq"));
$ProcessorSpeed=trim(shell_exec("/bin/cat /proc/cpuinfo | /bin/grep \"cpu MHz\" | /bin/awk -F: ‘{print $2}’ | /bin/awk -F. ‘{print $1}’ | /usr/bin/uniq"));
$MemorySizeT=trim(shell_exec("/bin/cat /proc/meminfo | /bin/grep MemTotal | /bin/awk ‘{print $2}’"));
$MemorySize=sprintf("%d",$MemorySizeT/1024);
$NumberOfVirtualT=trim(shell_exec("/bin/cat /proc/cpuinfo | /bin/grep -ci siblings"));
if ($NumberOfVirtualT !=0 ) {
//We have more than 1 core per processor, linux being stupid presents each core as a seperate processor and then
//just puts a siblings line in the /proc/cpuinfo
$NumberOfVirtual=$NumberOfVirtualT;
$NumberOfPhysical=$NumberOfPhysical/$NumberOfVirtual;
} else {
$NumberOfVirtual=$NumberOfPhysical;
}
}
if ($OS == "Darwin") {
//Use the system_profiler command
//system_profiler SPHardwareDataType
$NumberOfPhysical=trim(shell_exec("/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep \"Number Of CPUs\" | /usr/bin/awk -F’:’ ‘{print $2}’"));
//$NumberOfVirtual=trim(shell_exec("/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep \"Number Of CPUs\" | /usr/bin/awk -F’:’ ‘{print $2}’"));
$NumberOfVirtual=0;
//$NumberOfVirtual=trim(shell_exec("/usr/sbin/psrinfo | /bin/wc -l | /bin/sed ’s/ //g’");
$ProcessorSpeedTEMP=trim(shell_exec("/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep \"CPU Speed\" | /usr/bin/awk -F’:’ ‘{print $2}’"));
if (ereg("GHz",$ProcessorSpeedTEMP)){
$ProcessorSpeed=ereg_replace(" GHz","",$ProcessorSpeedTEMP);
$ProcessorSpeed=$ProcessorSpeed*1024;
}
if (ereg("MHz", $ProcessorSpeedTEMP)){
$ProcessorSpeed=ereg_replace(" MHz","",$ProcessorSpeedTEMP);
}
$ProcessorType=trim(shell_exec("/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep \"CPU Type\" | /usr/bin/awk -F’:’ ‘{print $2}’"));
$MemorySizeTemp=trim(shell_exec("/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep \"Memory\" | /usr/bin/awk -F’:’ ‘{print $2}’"));
if (ereg("GB",$MemorySizeTemp)) {
$MemorySize=ereg_replace(" GB","",$MemorySizeTemp);
$MemorySize=$MemorySize*1024;
}
if (ereg("MB",$MemorySizeTemp)) {
$MemorySize=ereg_replace(" MB","",$MemorySizeTemp);
};
}
if ($DEBUG) echo "Machine has $NumberOfPhysical processors of $ProcessorType with $NumberOfVirtual cores running at $ProcessorSpeed MHZ with $MemorySize MB of Memory\n";
//Check to see if there is an entry in the cm_proc_mem table if it is, compare with current to see if any changes, if not
//insert the record
$CMResult=mysql_query("select * from cm_proc_mem where hostname=’$hostname’ order by date desc") or die(mysql_error());
$CMN=mysql_num_rows($CMResult);
if ($CMN==0) {
//Insert new record
mysql_query("insert into cm_proc_mem values (’$hostname’,'$ProcessorType’,'$NumberOfPhysical’,'$ProcessorSpeed’,'$NumberOfVirtual’,'$MemorySize’,NOW(),”)") or die(mysql_error());
} else {
//Must be a previous entry If the info is different then add new record otherwise just bail
//Only care about the most recent which should be on top
$SProcessor_Type=mysql_result($CMResult,0,"processor_type");
$SProcessor_Count=mysql_result($CMResult,0,"processor_count");
$SProcessor_Speed=mysql_result($CMResult,0,"processor_speed");
$SProcessor_Cores=mysql_result($CMResult,0,"processor_cores");
$SMemory=mysql_result($CMResult,0,"memory");
$Changed="NO";
if ($SProcessor_Type != $ProcessorType) {
$Changed="YES";
}
if ($SProcessor_Count != $NumberOfPhysical) {
$Changed="YES";
}
if ($SProcessor_Speed != $ProcessorSpeed) {
$Changed="YES";
}
if ($SProcessor_Cores != $NumberOfVirtual) {
$Changed="YES";
}
if ($SMemory != $MemorySize ) {
$Changed="YES";
}
if ($Changed=="YES" ) {
mysql_query("insert into cm_proc_mem values (’$hostname’,'$ProcessorType’,'$NumberOfPhysical’,'$ProcessorSpeed’,'$NumberOfVirtual’,'$MemorySize’,NOW(),”)") or die(mysql_error());
}
}
}