Package org.hyperic.sigar

Examples of org.hyperic.sigar.Mem


    return dataMap;
  }

  public static void getServerMemoryInfo(Sigar sigar, ServerStatus status) {
    try {
      Mem mem = sigar.getMem();
      status.setTotalMem(mem.getTotal() / (1024 * 1024));
      status.setUsedMem(mem.getUsed() / (1024 * 1024));
      status.setFreeMem(mem.getFree() / (1024 * 1024));
      // 交换区
      Swap swap = sigar.getSwap();
      status.setTotalSwap(swap.getTotal() / (1024 * 1024));
      status.setUsedSwap(swap.getUsed() / (1024 * 1024));
      status.setFreeSwap(swap.getFree() / (1024 * 1024));
 
View Full Code Here


  @Override
  public void run() {
    boolean skip = false;
    CpuInfo[] cpuinfo = null;
    CpuPerc[] cpuPerc = null;
    Mem mem = null;
    FileSystem[] fs = null;
    String[] netIf = null;
    Uptime uptime = null;
    double[] loadavg = null;
    JSONObject json = new JSONObject();
    try {
      // CPU utilization
      cpuinfo = sigar.getCpuInfoList();
      cpuPerc = sigar.getCpuPercList();
      JSONArray cpuList = new JSONArray();
      for (int i = 0; i < cpuinfo.length; i++) {
        JSONObject cpuMap = new JSONObject();
        cpuMap.putAll(cpuinfo[i].toMap());
        cpuMap.put("combined", cpuPerc[i].getCombined());
        cpuMap.put("user", cpuPerc[i].getUser());
        cpuMap.put("sys", cpuPerc[i].getSys());
        cpuMap.put("idle", cpuPerc[i].getIdle());
        cpuMap.put("wait", cpuPerc[i].getWait());
        cpuMap.put("nice", cpuPerc[i].getNice());
        cpuMap.put("irq", cpuPerc[i].getIrq());
        cpuList.add(cpuMap);
      }
      sigar.getCpuPerc();
      json.put("cpu", cpuList);
     
      // Uptime
      uptime = sigar.getUptime();
      json.put("uptime", uptime.getUptime());
     
      // Load Average
      loadavg = sigar.getLoadAverage();
      JSONArray load = new JSONArray();
      load.add(loadavg[0]);
      load.add(loadavg[1]);
      load.add(loadavg[2]);
      json.put("loadavg", load);

      // Memory Utilization
      mem = sigar.getMem();
      JSONObject memMap = new JSONObject();
      memMap.putAll(mem.toMap());
      json.put("memory", memMap);
     
      // Network Utilization
      netIf = sigar.getNetInterfaceList();
      JSONArray netInterfaces = new JSONArray();
View Full Code Here

    @Test(enabled = ENABLED)
    public void testNativeMemory() throws Exception {
        Sigar sigar = new Sigar();
        try {
            Mem allMemory = sigar.getMem();
            Swap allSwap = sigar.getSwap();

            NumberFormat nf = NumberFormat.getNumberInstance();
            System.out.println("All Memory:" + "\nActualFreeMem=" + nf.format(allMemory.getActualFree())
                + "\nActualUsedMem=" + nf.format(allMemory.getActualUsed()) + "\n       RamMem="
                + nf.format(allMemory.getRam()) + "\n      FreeMem=" + nf.format(allMemory.getFree())
                + "\n      UsedMem=" + nf.format(allMemory.getUsed()) + "\n     TotalMem="
                + nf.format(allMemory.getTotal()) + "\n     FreeSwap=" + nf.format(allSwap.getFree())
                + "\n     UsedSwap=" + nf.format(allSwap.getUsed()) + "\n    TotalSwap="
                + nf.format(allSwap.getTotal()));
            assert allMemory.getActualFree() > 0 : allMemory.getActualFree();
            assert allMemory.getFree() > 0 : allMemory.getFree();
            assert allMemory.getTotal() > 1000000 : allMemory.getTotal();
            if (allSwap.getTotal()>0) {
                assert allSwap.getTotal() > 1000000 : allSwap.getTotal();
                assert allSwap.getFree() > 0 : allSwap.getFree();
            }
View Full Code Here

        }

        // just a side test - need to make sure this works
        assert SystemInfoFactory.getNativeSystemInfoVersion() != null;

        Mem allMemory = sysinfo.getMemoryInfo();
        ProcMem procMemory = sysinfo.getThisProcess().getMemory();

        assert allMemory != null;
        assert procMemory != null;
        assert allMemory.getUsed() > procMemory.getResident() : allMemory.getUsed() + "->" + procMemory.getSize();
    }
View Full Code Here

    }

    public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) {
        SystemInfo info = this.resourceContext.getSystemInformation();
        boolean isNative = info.isNative();
        Mem platformMemoryInfo = null;
        Swap platformSwapInfo = null;
        CpuPerc cpuPerc = null;
        try {
            cpuPerc = SigarAccess.getSigar().getCpuPerc();
        } catch (Exception e) {
View Full Code Here

    private static Long format(long value) {
        return new Long(value / 1024);
    }

    public void output(String[] args) throws SigarException {
        Mem mem   = this.sigar.getMem();
        Swap swap = this.sigar.getSwap();

        Object[] header = new Object[] { "total", "used", "free" };

        Object[] memRow = new Object[] {
            format(mem.getTotal()),
            format(mem.getUsed()),
            format(mem.getFree())
        };

        Object[] actualRow = new Object[] {
            format(mem.getActualUsed()),
            format(mem.getActualFree())
        };

        Object[] swapRow = new Object[] {
            format(swap.getTotal()),
            format(swap.getUsed()),
            format(swap.getFree())
        };

        printf("%18s %10s %10s", header);

        printf("Mem:    %10ld %10ld %10ld", memRow);

        //e.g. linux
        if ((mem.getUsed() != mem.getActualUsed()) ||
            (mem.getFree() != mem.getActualFree()))
        {
            printf("-/+ buffers/cache: " + "%10ld %10d", actualRow);
        }

        printf("Swap:   %10ld %10ld %10ld", swapRow);

        printf("RAM:    %10ls", new Object[] { mem.getRam() + "MB" });
    }
View Full Code Here

    }

    private MemoryObject getMemoryInfo() {
        MemoryObject memObj = new MemoryObject();
        try {
            Mem temp = sigar.getMem();
            memObj.setActualFree(temp.getActualFree());
            memObj.setActualUsed(temp.getActualUsed());

            memObj.setUsedMemory(temp.getUsed());
            memObj.setFreeMemory(temp.getFree());
            memObj.setTotalMemory(temp.getTotal());

            memObj.setUsedPrecentage(temp.getUsedPercent());
            memObj.setFreePrecentage(temp.getFreePercent());
        } catch (SigarException ex) {
            Logger.getLogger(Memory.class.getName()).log(Level.SEVERE, null, ex);
        }

        return memObj;
View Full Code Here

    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        Mem mem = sigar.getMem();

        assertGtZeroTrace("Total", mem.getTotal());

        assertGtZeroTrace("Used", mem.getUsed());

        traceln("UsedPercent=" + mem.getUsedPercent());
        assertGtZeroTrace("(long)UsedPercent", (long)mem.getUsedPercent());

        assertTrue(mem.getUsedPercent() <= 100);

        traceln("FreePercent=" + mem.getFreePercent());
        assertGtEqZeroTrace("(long)FreePercent", (long)mem.getFreePercent());

        assertTrue(mem.getFreePercent() < 100);

        assertGtZeroTrace("Free", mem.getFree());

        assertGtZeroTrace("ActualUsed", mem.getUsed());

        assertGtZeroTrace("ActualFree", mem.getFree());

        assertGtZeroTrace("Ram", mem.getRam());

        assertTrue((mem.getRam() % 8) == 0);
    }
View Full Code Here

    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        Mem mem = sigar.getMem();

        assertGtZeroTrace("Total", mem.getTotal());

        assertGtZeroTrace("Used", mem.getUsed());

        traceln("UsedPercent=" + mem.getUsedPercent());
        assertGtZeroTrace("(long)UsedPercent", (long)mem.getUsedPercent());

        assertTrue(mem.getUsedPercent() <= 100);

        traceln("FreePercent=" + mem.getFreePercent());
        assertGtEqZeroTrace("(long)FreePercent", (long)mem.getFreePercent());

        assertTrue(mem.getFreePercent() < 100);

        assertGtZeroTrace("Free", mem.getFree());

        assertGtZeroTrace("ActualUsed", mem.getActualUsed());

        assertGtZeroTrace("ActualFree", mem.getActualFree());

        assertGtZeroTrace("Ram", mem.getRam());

        assertTrue((mem.getRam() % 8) == 0);
    }
View Full Code Here

  @Override
  public void run() {
    boolean skip = false;
    CpuInfo[] cpuinfo = null;
    CpuPerc[] cpuPerc = null;
    Mem mem = null;
    Swap swap = null;
    FileSystem[] fs = null;
    String[] netIf = null;
    Uptime uptime = null;
    double[] loadavg = null;
    JSONObject json = new JSONObject();
    try {
      // CPU utilization
      cpuinfo = sigar.getCpuInfoList();
      cpuPerc = sigar.getCpuPercList();
      JSONArray cpuList = new JSONArray();
      for (int i = 0; i < cpuinfo.length; i++) {
        JSONObject cpuMap = new JSONObject();
        cpuMap.putAll(cpuinfo[i].toMap());
        cpuMap.put("combined", cpuPerc[i].getCombined());
        cpuMap.put("user", cpuPerc[i].getUser());
        cpuMap.put("sys", cpuPerc[i].getSys());
        cpuMap.put("idle", cpuPerc[i].getIdle());
        cpuMap.put("wait", cpuPerc[i].getWait());
        cpuMap.put("nice", cpuPerc[i].getNice());
        cpuMap.put("irq", cpuPerc[i].getIrq());
        cpuList.add(cpuMap);
      }
      sigar.getCpuPerc();
      json.put("cpu", cpuList);
     
      // Uptime
      uptime = sigar.getUptime();
      json.put("uptime", uptime.getUptime());
     
      // Load Average
      loadavg = sigar.getLoadAverage();
      JSONArray load = new JSONArray();
      load.add(loadavg[0]);
      load.add(loadavg[1]);
      load.add(loadavg[2]);
      json.put("loadavg", load);

      // Memory Utilization
      mem = sigar.getMem();
      JSONObject memMap = new JSONObject();
      memMap.putAll(mem.toMap());
      json.put("memory", memMap);

      // Swap Utilization
      swap = sigar.getSwap();
      JSONObject swapMap = new JSONObject();
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.Mem

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.