Package org.hyperic.sigar

Examples of org.hyperic.sigar.Sigar


    public void testGlobalInstance() throws Exception {
        runTests(Humidor.getInstance().getSigar());
    }

    public void testInstance() throws Exception {
        Sigar sigar = new Sigar();
        runTests(new Humidor(sigar).getSigar());
        sigar.close();
    }
View Full Code Here


    public TestLoadAverage(String name) {
        super(name);
    }

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

        try {
            double[] loadavg = sigar.getLoadAverage();

            assertTrue(loadavg.length == 3);

            traceln("1min=" + loadavg[0]);
            traceln("5min=" + loadavg[1]);
View Full Code Here

    public TestProcFd(String name) {
        super(name);
    }

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

        try {
            sigar.getProcFd(getInvalidPid());
        } catch (SigarException e) {
        }

        try {
            long pid = sigar.getPid();

            long total = sigar.getProcFd(pid).getTotal();

            SigarLoader loader = new SigarLoader(Sigar.class);
            String path = loader.findJarPath(null);
            File file = new File(path, loader.getJarName());

            traceln("Opening " + file);

            FileInputStream is = new FileInputStream(file);

            assertEqualsTrace("Total", total + 1,
                              sigar.getProcFd(pid).getTotal());

            is.close();

            assertEqualsTrace("Total", total,
                              sigar.getProcFd(pid).getTotal());
        } catch (SigarNotImplementedException e) {
            //ok
        } catch (SigarPermissionDeniedException e) {
            //ok
        }
View Full Code Here

    public TestUptime(String name) {
        super(name);
    }

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

        Uptime uptime = sigar.getUptime();

        long now = System.currentTimeMillis();
        traceln("\nboottime=" +
                new Date(now - (long)uptime.getUptime()*1000));
        assertTrue(uptime.getUptime() > 0);
View Full Code Here

        }
    }

    public Sigar getSigar() {
        if (sigar == null) {
            sigar = new Sigar();
            if (getVerbose()) {
                sigar.enableLogging(true);
            }
        }
        return sigar;
View Full Code Here

            assertGtEqZeroTrace(NetConnection.getStateString(i), states[i]);
        }
    }

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

        NetInterfaceConfig ifconfig =
            sigar.getNetInterfaceConfig(null);

        ArrayList addrs = new ArrayList();
        addrs.add(ifconfig.getAddress());
        addrs.add(NetFlags.LOOPBACK_ADDRESS);
        if (JDK_14_COMPAT) {
View Full Code Here

public class SystemUtils {

  public static SystemType getStatus(SystemType st, List<SystemType> stList) {
    try {
      Sigar sigar = new Sigar();
      // 初始化系统状态
      st.setCpuInfos(sigar.getCpuInfoList());
      st.setCpuPercs(sigar.getCpuPercList());
      st.setMem(sigar.getMem());
      st.setSwap(sigar.getSwap());
      st.setSys(OperatingSystem.getInstance());
      st.setUptime(sigar.getUptime().getUptime());

      String netNames[] = sigar.getNetInterfaceList();
      st.setNetNames(netNames);
      Map<String, NetInterfaceConfig> netConfigs = new HashMap<String, NetInterfaceConfig>();
      Map<String, NetInterfaceStat> netStats = new HashMap<String, NetInterfaceStat>();
      Map<String, Double> netRxSpeed = new HashMap<String, Double>();
      Map<String, Double> netTxSpeed = new HashMap<String, Double>();
      SystemType stTemp = stList.get(stList.size() - 1);
      for (int i = 0; i < netNames.length; i++) {
        // if (netNames[i].toLowerCase().equals("lo")) {
        // continue;
        // }
        NetInterfaceConfig netConfig = sigar
            .getNetInterfaceConfig(netNames[i]);
        NetInterfaceStat netStat = sigar
            .getNetInterfaceStat(netNames[i]);
        netConfigs.put(netNames[i], netConfig);
        netStats.put(netNames[i], netStat);
        double doubRx = 0.0;
        double doubTx = 0.0;
View Full Code Here

    return st;
  }

  public static SystemType getVariables(SystemType st) {
    try {
      Sigar sigar = new Sigar();
      // 初始化系统状态
      st.setCpuInfos(sigar.getCpuInfoList());
      st.setCpuPercs(sigar.getCpuPercList());
      st.setMem(sigar.getMem());
      st.setSwap(sigar.getSwap());
      st.setSys(OperatingSystem.getInstance());
      st.setUptime(sigar.getUptime().getUptime());

      String netNames[] = sigar.getNetInterfaceList();
      st.setNetNames(netNames);
      Map<String, NetInterfaceConfig> netConfigs = new HashMap<String, NetInterfaceConfig>();
      Map<String, NetInterfaceStat> netStats = new HashMap<String, NetInterfaceStat>();
      Map<String, Double> netRxSpeed = new HashMap<String, Double>();
      Map<String, Double> netTxSpeed = new HashMap<String, Double>();
      for (int i = 0; i < netNames.length; i++) {
        // if (netNames[i].toLowerCase().equals("lo")) {
        // continue;
        // }
        NetInterfaceConfig netConfig = sigar
            .getNetInterfaceConfig(netNames[i]);
        NetInterfaceStat netStat = sigar
            .getNetInterfaceStat(netNames[i]);
        netConfigs.put(netNames[i], netConfig);
        netStats.put(netNames[i], netStat);
        double doubRx = 0.0;
        double doubTx = 0.0;
View Full Code Here

   */
  protected void stopProcess(String mode) {
    String pid = agentConfig.getAgentPidProperties(mode);
    try {
      if (StringUtils.isNotBlank(pid)) {
        new Sigar().kill(pid, 15);
      }
      agentConfig.updateAgentPidProperties(mode);
    } catch (SigarException e) {
      printHelpAndExit(String.format("Error occurred while terminating %s process.\n"
          + "It can be already stopped or you may not have the permission.\n"
View Full Code Here

   * Check if the process is already running in this env.
   *
   * @param startMode monitor or agent
   */
  public void checkDuplicatedRun(String startMode) {
    Sigar sigar = new Sigar();
    String existingPid = this.agentConfig.getAgentPidProperties(startMode);
    if (StringUtils.isNotEmpty(existingPid)) {
      try {
        ProcState procState = sigar.getProcState(existingPid);
        if (procState.getState() == ProcState.RUN || procState.getState() == ProcState.IDLE
            || procState.getState() == ProcState.SLEEP) {
          printHelpAndExit("Currently " + startMode + " is running with pid " + existingPid
              + ". Please stop it before run");
        }
        agentConfig.updateAgentPidProperties(startMode);
      } catch (SigarException e) {
        noOp();
      }
    }
    this.agentConfig.saveAgentPidProperties(String.valueOf(sigar.getPid()), startMode);
  }
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.Sigar

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.