From: <jt...@hy...> - 2007-11-20 00:47:39
|
Author: jtravis Date: 2007-11-19 16:47:36 -0800 (Mon, 19 Nov 2007) New Revision: 6863 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=6863 Modified: trunk/ui_plugins/health/app/HealthController.groovy Log: Divide CPU usage by # of processors. Other small cleanups Modified: trunk/ui_plugins/health/app/HealthController.groovy =================================================================== --- trunk/ui_plugins/health/app/HealthController.groovy 2007-11-20 00:39:23 UTC (rev 6862) +++ trunk/ui_plugins/health/app/HealthController.groovy 2007-11-20 00:47:36 UTC (rev 6863) @@ -3,7 +3,6 @@ import org.hyperic.util.units.UnitsFormat import org.hyperic.util.units.UnitsConstants import org.hyperic.util.units.UnitNumber - import org.hyperic.hq.hqu.rendit.html.HtmlUtil import org.hyperic.hq.hqu.rendit.html.DojoUtil import org.hyperic.hq.hqu.rendit.BaseController @@ -11,9 +10,10 @@ import org.hyperic.sigar.Sigar import org.hyperic.sigar.CpuPerc import org.hyperic.hq.common.DiagnosticThread -import net.sf.ehcache.CacheManager import org.hyperic.hq.common.Humidor +import net.sf.ehcache.CacheManager + import java.text.SimpleDateFormat; class HealthController @@ -125,59 +125,54 @@ } def getSystemStats(params) { - //def s = new Sigar() def s = Humidor.instance.sigar def loadAvgFmt = new PrintfFormat('%.2f') def dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm a"); - try { - def cpu = s.cpuPerc - def sysMem = s.mem - def sysSwap = s.swap - def pid = s.pid - def procFds = 'unknown' - def procMem = s.getProcMem(pid) - def procCpu = s.getProcCpu(pid) - def procTime = s.getProcTime(pid) - def loadAvg = s.loadAverage - def runtime = Runtime.runtime + def cpu = s.cpuPerc + def sysMem = s.mem + def sysSwap = s.swap + def pid = s.pid + def procFds = 'unknown' + def procMem = s.getProcMem(pid) + def procCpu = s.getProcCpu(pid) + def procTime = s.getProcTime(pid) + def loadAvg = s.loadAverage + def runtime = Runtime.runtime - try { - procFds = s.getProcFd(pid).total - } catch(Exception e) { - } - - return [sysUserCpu: (int)(cpu.user * 100), - sysSysCpu: (int)(cpu.sys * 100), - sysNiceCpu: (int)(cpu.nice * 100), - sysIdleCpu: (int)(cpu.idle * 100), - sysWaitCpu: (int)(cpu.wait * 100), - sysPercCpu: (int)(100 - cpu.idle * 100), - loadAvg1: loadAvgFmt.sprintf(loadAvg[0]), - loadAvg5: loadAvgFmt.sprintf(loadAvg[1]), - loadAvg15: loadAvgFmt.sprintf(loadAvg[2]), - totalMem: formatBytes(sysMem.total), - usedMem: formatBytes(sysMem.used), - freeMem: formatBytes(sysMem.free), - percMem: (int)(sysMem.used * 100 / sysMem.total), - totalSwap: formatBytes(sysSwap.total), - usedSwap: formatBytes(sysSwap.used), - freeSwap: formatBytes(sysSwap.free), - percSwap: (int)(sysSwap.used * 100 / sysSwap.total), - pid: pid, - procStartTime: dateFormat.format(procTime.startTime), - procOpenFds: procFds, - procMemSize: formatBytes(procMem.size), - procMemRes: formatBytes(procMem.resident), - procMemShare: formatBytes(procMem.share), - procCpu: (int)(procCpu.percent * 100), - jvmTotalMem: formatBytes(runtime.totalMemory()), - jvmFreeMem: formatBytes(runtime.freeMemory()), - jvmMaxMem: formatBytes(runtime.maxMemory()), - jvmPercMem: (int)((runtime.maxMemory() - runtime.freeMemory()) * 100 / runtime.maxMemory()), - ] - } finally { - //s.close() + try { + procFds = s.getProcFd(pid).total + } catch(Exception e) { } + + return [sysUserCpu: (int)(cpu.user * 100), + sysSysCpu: (int)(cpu.sys * 100), + sysNiceCpu: (int)(cpu.nice * 100), + sysIdleCpu: (int)(cpu.idle * 100), + sysWaitCpu: (int)(cpu.wait * 100), + sysPercCpu: (int)(100 - cpu.idle * 100), + loadAvg1: loadAvgFmt.sprintf(loadAvg[0]), + loadAvg5: loadAvgFmt.sprintf(loadAvg[1]), + loadAvg15: loadAvgFmt.sprintf(loadAvg[2]), + totalMem: formatBytes(sysMem.total), + usedMem: formatBytes(sysMem.used), + freeMem: formatBytes(sysMem.free), + percMem: (int)(sysMem.used * 100 / sysMem.total), + totalSwap: formatBytes(sysSwap.total), + usedSwap: formatBytes(sysSwap.used), + freeSwap: formatBytes(sysSwap.free), + percSwap: (int)(sysSwap.used * 100 / sysSwap.total), + pid: pid, + procStartTime: dateFormat.format(procTime.startTime), + procOpenFds: procFds, + procMemSize: formatBytes(procMem.size), + procMemRes: formatBytes(procMem.resident), + procMemShare: formatBytes(procMem.share), + procCpu: (int)(procCpu.percent * 100.0 / runtime.availableProcessors()), + jvmTotalMem: formatBytes(runtime.totalMemory()), + jvmFreeMem: formatBytes(runtime.freeMemory()), + jvmMaxMem: formatBytes(runtime.maxMemory()), + jvmPercMem: (int)((runtime.maxMemory() - runtime.freeMemory()) * 100 / runtime.maxMemory()), + ] } } |