Package org.rioproject.system.measurable.memory

Examples of org.rioproject.system.measurable.memory.SystemMemoryUtilization


            if(cName.equals(Constants.UTIL_PERCENT_CPU)) {
                CpuUtilization cpu = cru.getCpuUtilization();
                value = (cpu == null ? "?" : formatPercent(cpu.getValue()));

            } else if(cName.equals(Constants.UTIL_PERCENT_MEMORY)) {
                SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
                value = (mem == null ? "?" : formatPercent(mem.getValue()));

            } else if(cName.equals(Constants.UTIL_TOTAL_MEMORY)) {
                SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
                value = (mem == null ? "?" : format(mem.getTotal()," MB"));

            } else if(cName.equals(Constants.UTIL_FREE_MEMORY)) {
                SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
                value = (mem == null ? "?" : format(mem.getFree()," MB"));

            } else if(cName.equals(Constants.UTIL_USED_MEMORY)) {
                SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
                value = (mem == null ? "?" : format(mem.getUsed()," MB"));

            } else if(cName.equals(Constants.UTIL_PERCENT_DISK)) {
                DiskSpaceUtilization disk = cru.getDiskSpaceUtilization();
                value = (disk==null?"?" : formatPercent(disk.getValue()));

            } else if(cName.equals(Constants.UTIL_AVAIL_DISK)) {
                DiskSpaceUtilization disk = cru.getDiskSpaceUtilization();
                value = (disk==null?"?" : format(disk.getAvailable()/MeasuredValueHelper.GB," GB"));

            } else if(cName.equals(Constants.UTIL_TOTAL_DISK)) {
                DiskSpaceUtilization disk = cru.getDiskSpaceUtilization();
                value = (disk==null?"?" : format(disk.getCapacity()/MeasuredValueHelper.GB," GB"));
            }
        }

        if(cName.equals(Constants.UTIL_PERCENT_CPU_PROC)) {
            value = formatPercent(MeasuredValueHelper.getMeasuredValue(SystemWatchID.PROC_CPU, cru));

        } else if(cName.equals(Constants.UTIL_PERCENT_HEAP_JVM)) {
            value = formatPercent(MeasuredValueHelper.getMeasuredValue(SystemWatchID.JVM_MEMORY, cru));
            //ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            //value = (mem==null?"?" : format(mem.getUsedHeap()));

        } else if(cName.equals(Constants.UTIL_HEAP_MEM_JVM)) {
            ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            //value = (mem==null?"?" : format(mem.getCommittedHeap())+" MB");
            value = (mem==null?"?" : format(mem.getUsedHeap()," MB"));

        } else if(cName.equals(Constants.UTIL_HEAP_MEM_AVAIL)) {
            ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            //value = (mem==null?"?" : format(mem.getCommittedHeap())+" MB");
            value = (mem==null?"?" : format(mem.getCommittedHeap(), " MB"));

        } else if(cName.equals(Constants.UTIL_REAL_MEM_PROC)) {
            ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            value = (mem==null?"?" : format(mem.getResident(), " MB"));
        }
        if(isAThresholdColumn(cName)) {
            return getThresholdLabel(cName, value, cru);
        }
        return (value);
View Full Code Here


        if (cName.equals(Constants.UTIL_PERCENT_CPU)) {
            CpuUtilization cpu = cru.getCpuUtilization();
            value = (cpu == null ? 0 : cpu.getValue());

        } else if (cName.equals(Constants.UTIL_PERCENT_MEMORY)) {
            SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
            value = (mem == null ? 0 : mem.getValue());

        } else if (cName.equals(Constants.UTIL_TOTAL_MEMORY)) {
            SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
            value = (mem == null ? 0 : mem.getTotal());

        } else if (cName.equals(Constants.UTIL_FREE_MEMORY)) {
            SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
            value = (mem == null ? 0 : mem.getFree());

        } else if (cName.equals(Constants.UTIL_USED_MEMORY)) {
            SystemMemoryUtilization mem = cru.getSystemMemoryUtilization();
            value = (mem == null ? 0 : mem.getUsed());

        } else if (cName.equals(Constants.UTIL_PERCENT_DISK)) {
            DiskSpaceUtilization disk = cru.getDiskSpaceUtilization();
            value = (disk == null ? 0 : disk.getValue());

        } else if (cName.equals(Constants.UTIL_AVAIL_DISK)) {
            DiskSpaceUtilization disk = cru.getDiskSpaceUtilization();
            value = (disk == null ? 0 : disk.getAvailable() / GB);

        } else if (cName.equals(Constants.UTIL_TOTAL_DISK)) {
            DiskSpaceUtilization disk = cru.getDiskSpaceUtilization();
            value = (disk == null ? 0 : disk.getCapacity() / GB);

        } else if (cName.equals(Constants.UTIL_PERCENT_CPU_PROC)) {
            value = getMeasuredValue("CPU (JVM)", cru);

        } else if (cName.equals(Constants.UTIL_PERCENT_HEAP_JVM)) {
            value = getMeasuredValue("Memory", cru);

        } else if (cName.equals(Constants.UTIL_HEAP_MEM_JVM)) {
            ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            value = (mem == null ? 0 : mem.getUsedHeap());

        } else if (cName.equals(Constants.UTIL_HEAP_MEM_AVAIL)) {
            ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            value = (mem == null ? 0 : mem.getCommittedHeap());

        } else if (cName.equals(Constants.UTIL_REAL_MEM_PROC)) {
            ProcessMemoryUtilization mem = cru.getProcessMemoryUtilization();
            value = (mem == null ? 0 : mem.getResident());
        }

        return value;
    }
View Full Code Here

    public void testParsing() {
        MemInfoMonitor memInfoMonitor = new MemInfoMonitor();
        memInfoMonitor.setID("System Memory");
        memInfoMonitor.setThresholdValues(new ThresholdValues(0, 1.0));
        memInfoMonitor.setMemInfoFile("src/test/resources/meminfo");
        SystemMemoryUtilization memoryUtilization = memInfoMonitor.getMeasuredResource();
        Assert.assertNotNull(memoryUtilization);
        System.out.println("Free:   "+memoryUtilization.getFree()+" MB");
        System.out.println("Active: "+memoryUtilization.getUsed()+" MB");
        System.out.println("Total:  "+memoryUtilization.getTotal()+" MB");
        System.out.println("Used %: "+memoryUtilization.getUsedPercentage());
        System.out.println("Free %: "+memoryUtilization.getFreePercentage());
        Assert.assertTrue(1.0==memoryUtilization.getUsedPercentage()+memoryUtilization.getFreePercentage());
    }
View Full Code Here

        this.memInfo = memInfo;
    }

    @Override
    public SystemMemoryUtilization getMeasuredResource() {
        SystemMemoryUtilization memoryUtilization;
        BufferedReader br = null;
        try {
            long total = 0;
            long active = 0;

            File file = new File(memInfo);
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String str;
            StringTokenizer token;
            while ((str = br.readLine()) != null) {
                token = new StringTokenizer(str);
                if (!token.hasMoreTokens())
                    continue;

                str = token.nextToken();
                if (!token.hasMoreTokens())
                    continue;

                if (str.equalsIgnoreCase("MemTotal:"))
                    total = Long.parseLong(token.nextToken());
                else if (str.equalsIgnoreCase("Active:"))
                    active = Long.parseLong(token.nextToken());
            }

            long free = total - active;
            double usedPercent = (double)active/(double)total;
            double freePercent = (double)free/(double)total;

            double KB = 1024;
            memoryUtilization = new SystemMemoryUtilization(id,
                                                            usedPercent,
                                                            ((double)total)/ KB,
                                                            ((double)free)/ KB,
                                                            ((double)active)/ KB,
                                                            freePercent,
                                                            usedPercent,
                                                            total,
                                                            thresholdValues);
        } catch (IOException e) {
            memoryUtilization = new SystemMemoryUtilization(id, thresholdValues);
        } finally {
            if(br!=null)
                try {
                    br.close();
                } catch (IOException e) {
View Full Code Here

    public void setThresholdValues(ThresholdValues tVals) {
        this.tVals = tVals;
    }

    public SystemMemoryUtilization getMeasuredResource() {
        SystemMemoryUtilization smu;
        if(sigar==null) {
            smu = new SystemMemoryUtilization(id, tVals);
        } else {
            long total = sigar.getTotalSystemMemory();
            long free = sigar.getFreeSystemMemory();
            long used = sigar.getUsedSystemMemory();

            double utilization = (double)used/(double)total;
            if(logger.isTraceEnabled()) {
                StringBuilder builder = new StringBuilder();
                NumberFormat nf = NumberFormat.getInstance();
                nf.setMaximumFractionDigits(2);
                long ram = sigar.getRam();
                double d = ((double)total)/MB;
                double e = ((double)used)/MB;
                double f = ((double)ram)/KB;
                double g = ((double)free)/MB;
                String usedPerc = nf.format(sigar.getUsedSystemMemoryPercent());
                String freePerc = nf.format(sigar.getFreeSystemMemoryPercent());
                builder.append("\nTotal:       ").append(nf.format(d)).append(" MB\n");
                builder.append("Used:        ").append(nf.format(e)).append(" MB, ").append(usedPerc).append(" %\n");
                builder.append("Free:        ").append(nf.format(g)).append(" MB, ").append(freePerc).append(" %\n");
                builder.append("RAM:         ").append(nf.format(f)).append(" GB\n");
                builder.append("Utilization: ").append(utilization).append(" %");
                logger.trace(builder.toString());
            }

            smu = new SystemMemoryUtilization(id,
                                              utilization,
                                              ((double)total)/MB,
                                              ((double)free)/MB,
                                              ((double)used)/MB,
                                              sigar.getFreeSystemMemoryPercent(),
View Full Code Here

     * @return The latest
     * {@link org.rioproject.system.measurable.memory.SystemMemoryUtilization}
     * taken from the compute resource. If not available, return null.
     */
    public SystemMemoryUtilization getSystemMemoryUtilization() {
        SystemMemoryUtilization mem = null;
        for (MeasuredResource m : mRes) {
            if(m instanceof SystemMemoryUtilization) {
                mem = (SystemMemoryUtilization)m;
                break;
            }
View Full Code Here

        this.description = description;
        define(NAME, ID);
    }

    public void addCalculable(CalculableSystemMemory calculable) {
        SystemMemoryUtilization memoryUtilization = calculable.getMemoryUtilization();
        Double dFree = memoryUtilization.getFree();
        Double dTotal = memoryUtilization.getTotal();

        /* The values will come to us in MB, need to convert to bytes */
        dTotal = dTotal*MB;
        dFree = dFree*MB;
        capabilities.put(CAPACITY, dTotal);
View Full Code Here

TOP

Related Classes of org.rioproject.system.measurable.memory.SystemMemoryUtilization

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.