Esempio n. 1
0
  /**
   * Executes the commands and process the results to return the AIX OS memory pm data.
   *
   * @param params the performance metrices to be monitored by this task.
   * @param flags parameter and command flags.
   * @return returns the PMData instance.
   */
  private static PMData getAixPMData(String[] params, boolean[][] flags) {

    if (flags == null) {
      flags = isParamsExists(params);
    }

    boolean[] cmdflag = flags[0];
    boolean[] pflag = flags[1];

    long exectime = System.currentTimeMillis();

    // execute the opc_utl command
    String aixmemoryResult = null;
    if (cmdflag[TOP]) {
      try {
        aixmemoryResult = RunCommand.exec(AIX_AIXMEMORYCMD);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // execute the swap command
    String swapResult = null;
    if (cmdflag[SWAP]) {
      try {
        swapResult = RunCommand.exec(AIX_SWAPCMD, 10000);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // process the opc_utl command result
    Vector paramlist = new Vector();
    if (cmdflag[TOP] && (aixmemoryResult != null)) {
      /* output looks like:
      /users/donjiang/opc009/agent/bin>opc_utl -m
      RealMemory:     16384.0M
      FreeMemory:     523.4M
      */
      StringTokenizer rtokenizer = new StringTokenizer(aixmemoryResult, "\n");
      String line = null;
      long realmemory = 0;
      long freememory = 0;
      while (rtokenizer.hasMoreTokens()) {
        line = rtokenizer.nextToken().trim();
        if (line.startsWith("RealMemory")) {
          StringTokenizer ltokenizer = new StringTokenizer(line, " \t");
          ltokenizer.nextToken();
          realmemory = getMemorySize(ltokenizer.nextToken());
        }
        if (line.startsWith("FreeMemory")) {
          StringTokenizer ltokenizer = new StringTokenizer(line, " \t");
          ltokenizer.nextToken();
          freememory = getMemorySize(ltokenizer.nextToken());
        }
      }
      if (realmemory == 0 || freememory == 0) {
        IsmMonAgentUtil.debug(
            "Error: OsMemoryTask, invalid number of lines for opc_utl report." + aixmemoryResult,
            IsmMonAgentUtil.MAJOR);
      }

      if (pflag[REALMEMORY]) {
        paramlist.addElement(
            new PmMeasurement(REALMEMORYNAME, String.valueOf(realmemory), true, null));
      }
      if (pflag[FREEMEMORY]) {
        paramlist.addElement(
            new PmMeasurement(FREEMEMORYNAME, String.valueOf(freememory), true, null));
      }
    }

    // process the swap command
    if (cmdflag[SWAP] && (swapResult != null)) {

      if (pflag[SWAPUSED] || pflag[SWAPFREE]) {

        String swapused = "n/a";
        String swapfree = "n/a";
        long totalpagingspace = 0;
        long percentused = 0;

        StringTokenizer rtokenizer = new StringTokenizer(swapResult, "\n");
        String line = null;
        if (rtokenizer.countTokens() >= 2) {
          line = rtokenizer.nextToken();
          line = rtokenizer.nextToken();
          StringTokenizer ltokenizer = new StringTokenizer(line, " ");

          if (ltokenizer.countTokens() >= 2) {
            totalpagingspace = getMemorySize(ltokenizer.nextToken().trim());
            String temp = ltokenizer.nextToken().trim();
            temp = temp.substring(0, temp.length() - 1); // remove "%" sign
            percentused = (Long.valueOf(temp)).longValue();

            // Figure out swapused & swapfree
            swapused = String.valueOf((totalpagingspace * percentused) / 100);
            swapfree = String.valueOf(totalpagingspace - (Long.valueOf(swapused)).longValue());
          }
        }

        if (pflag[SWAPUSED]) {
          paramlist.addElement(new PmMeasurement(SWAPUSEDNAME, swapused, true, null));
        }

        if (pflag[SWAPFREE]) {
          paramlist.addElement(new PmMeasurement(SWAPFREENAME, swapfree, true, null));
        }
      }
    }

    return getPMData(paramlist, params, pflag, cmdflag, exectime);
  }
Esempio n. 2
0
  /**
   * Executes the commands and process the results to return the HP-UX memory data.
   *
   * @param params the performance metrices to be monitored by this task.
   * @param flags parameter and command flags.
   * @return returns the PMData instance.
   */
  private static PMData getHpUxPMData(String[] params, boolean[][] flags) {

    if (flags == null) {
      flags = isParamsExists(params);
    }

    boolean[] cmdflag = flags[0];
    boolean[] pflag = flags[1];

    long exectime = System.currentTimeMillis();

    // execute the top command
    String topResult = null;
    if (cmdflag[TOP]) {
      try {
        topResult = RunCommand.exec(HPUX_TOPCMD);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // execute the top command
    String swapResult = null;
    if (cmdflag[SWAP]) {
      try {
        swapResult = RunCommand.exec(HPUX_SWAPCMD, 10000);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    Vector paramlist = new Vector();
    // process the top command
    if (cmdflag[TOP] && (topResult != null)) {

      StringTokenizer rtokenizer = new StringTokenizer(topResult, "\n");
      String line = null;
      while (rtokenizer.hasMoreTokens()) {
        line = rtokenizer.nextToken();
        if (line.startsWith("Memory")) {
          break;
        }
      }
      long realmemory = 0;
      long freememory = 0;
      if (line != null && line.startsWith("Memory")) {
        StringTokenizer ltokenizer = new StringTokenizer(line.substring(8), " ,");
        if (ltokenizer.countTokens() >= 7) {
          String real = ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          String free = ltokenizer.nextToken();
          freememory = getMemorySize(free);
          realmemory = getMemorySize(real) + freememory;
        }
      } else {
        IsmMonAgentUtil.debug(
            "Error parsing top command result." + topResult, IsmMonAgentUtil.MAJOR);
      }

      if (pflag[REALMEMORY]) {
        paramlist.addElement(
            new PmMeasurement(REALMEMORYNAME, String.valueOf(realmemory), true, null));
      }
      if (pflag[FREEMEMORY]) {
        paramlist.addElement(
            new PmMeasurement(FREEMEMORYNAME, String.valueOf(freememory), true, null));
      }
    }

    // process the swap command
    if (cmdflag[SWAP] && (swapResult != null)) {

      if (pflag[SWAPUSED] || pflag[SWAPFREE]) {

        String swapused = "n/a";
        String swapfree = "n/a";

        StringTokenizer rtokenizer = new StringTokenizer(swapResult, "\n");
        String line = null;
        while (rtokenizer.hasMoreTokens()) {
          line = rtokenizer.nextToken();
          if (line.startsWith("total")) {
            StringTokenizer ltokenizer = new StringTokenizer(line, " ");
            if (ltokenizer.countTokens() >= 3) {
              ltokenizer.nextToken();
              swapused = ltokenizer.nextToken();
              swapfree = ltokenizer.nextToken();
            }
            break;
          }
        }

        if (pflag[SWAPUSED]) {
          paramlist.addElement(new PmMeasurement(SWAPUSEDNAME, swapused, true, null));
        }

        if (pflag[SWAPFREE]) {
          paramlist.addElement(new PmMeasurement(SWAPFREENAME, swapfree, true, null));
        }
      }
    }

    return getPMData(paramlist, params, pflag, cmdflag, exectime);
  }
Esempio n. 3
0
  /**
   * Executes the commands and process the results to return the Solaris OS memory pm data.
   *
   * @param params the performance metrices to be monitored by this task.
   * @param flags parameter and command flags.
   * @return returns the PMData instance.
   */
  private static PMData getSolarisPMData(String[] params, boolean[][] flags) {

    if (flags == null) {
      flags = isParamsExists(params);
    }

    boolean[] cmdflag = flags[0];
    boolean[] pflag = flags[1];

    long exectime = System.currentTimeMillis();

    // execute the top command
    String topResult = null;
    if (cmdflag[TOP]) {
      try {
        topResult = RunCommand.exec(SOLARIS_TOPCMD);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // execute the swap command
    String swapResult = null;
    if (cmdflag[SWAP]) {
      try {
        swapResult = RunCommand.exec(SOLARIS_SWAPCMD, 10000);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // process the top command result
    Vector paramlist = new Vector();
    if (cmdflag[TOP] && (topResult != null)) {

      StringTokenizer rtokenizer = new StringTokenizer(topResult, "\n");
      String line = null;
      while (rtokenizer.hasMoreTokens()) {
        line = rtokenizer.nextToken();
        if (line.startsWith("Memory")) {
          break;
        }
      }
      String realmemory = "0";
      String freememory = "0";
      if (line != null && line.startsWith("Memory")) {
        StringTokenizer ltokenizer = new StringTokenizer(line.substring(8), ",");
        if (line.indexOf(" real,") > 0 && ltokenizer.hasMoreTokens()) {
          realmemory = String.valueOf(getMemorySize(ltokenizer.nextToken().trim()));
        }
        if (line.indexOf(" free,") > 0 && ltokenizer.hasMoreTokens()) {
          freememory = String.valueOf(getMemorySize(ltokenizer.nextToken().trim()));
        }
      } else {
        IsmMonAgentUtil.debug(
            "Error parsing top command result." + topResult, IsmMonAgentUtil.MAJOR);
      }

      if (pflag[REALMEMORY]) {
        paramlist.addElement(new PmMeasurement(REALMEMORYNAME, realmemory, true, null));
      }
      if (pflag[FREEMEMORY]) {
        paramlist.addElement(new PmMeasurement(FREEMEMORYNAME, freememory, true, null));
      }
    }

    // process the swap command result
    if (cmdflag[SWAP] && swapResult != null && swapResult.trim().length() > 0) {

      if (pflag[SWAPUSED]) {
        String swapused = null;
        try {
          String temp = swapResult.substring(0, swapResult.indexOf(" used"));
          String swapuseddata = temp.substring(temp.lastIndexOf(" "));
          swapused = String.valueOf(getMemorySize(swapuseddata.trim()));
        } catch (Exception e) {
          IsmMonAgentUtil.debug("Error parsing SwapUsed." + IsmMonAgentUtil.MAJOR);
          IsmMonAgentUtil.trace(e);
          swapused = "0";
        }
        paramlist.addElement(new PmMeasurement(SWAPUSEDNAME, swapused, true, null));
      }
      if (pflag[SWAPFREE]) {
        String swapfree = null;
        try {
          String temp = swapResult.substring(0, swapResult.indexOf(" available"));
          String swapfreedata = temp.substring(temp.lastIndexOf(" "));
          swapfree = String.valueOf(getMemorySize(swapfreedata.trim()));
        } catch (Exception e) {
          IsmMonAgentUtil.debug("Error parsing SwapFree." + IsmMonAgentUtil.MAJOR);
          IsmMonAgentUtil.trace(e);
          swapfree = "0";
        }
        paramlist.addElement(new PmMeasurement(SWAPFREENAME, swapfree, true, null));
      }
    }

    return getPMData(paramlist, params, pflag, cmdflag, exectime);
  }
Esempio n. 4
0
  /**
   * Executes the commands and process the results to return the LINUX OS memory pm data.
   *
   * @param params the performance metrices to be monitored by this task.
   * @param flags parameter and command flags.
   * @return returns the PMData instance.
   */
  private static PMData getLinuxPMData(String[] params, boolean[][] flags) {

    if (flags == null) {
      flags = isParamsExists(params);
    }

    boolean[] cmdflag = flags[0];
    boolean[] pflag = flags[1];

    long exectime = System.currentTimeMillis();

    // execute free command
    Vector paramlist = new Vector();
    String freeResult = null;
    if (cmdflag[TOP] || cmdflag[SWAP]) {
      try {
        freeResult = RunCommand.exec(LINUX_FREECMD);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // process the free command result
    if (freeResult != null) {
      if (cmdflag[TOP]) {
        try {
          StringTokenizer rtokenizer = new StringTokenizer(freeResult, "\n");
          String line = null;
          while (rtokenizer.hasMoreTokens()) {
            line = rtokenizer.nextToken();
            if (line.startsWith("Mem")) {
              break;
            }
          }
          String realmemory = "0";
          String freememory = "0";
          if (line != null && line.startsWith("Mem")) {
            StringTokenizer ltokenizer = new StringTokenizer(line);
            ltokenizer.nextToken();
            realmemory = ltokenizer.nextToken();
            ltokenizer.nextToken();
            freememory = ltokenizer.nextToken();
          } else {
            IsmMonAgentUtil.debug(
                "Error parsing Realmemory and Freememory." + freeResult, IsmMonAgentUtil.MAJOR);
          }

          if (pflag[REALMEMORY]) {
            paramlist.addElement(new PmMeasurement(REALMEMORYNAME, realmemory, true, null));
          }
          if (pflag[FREEMEMORY]) {
            paramlist.addElement(new PmMeasurement(FREEMEMORYNAME, freememory, true, null));
          }
        } catch (Exception e) {
          IsmMonAgentUtil.debug("Error parsing free command top result." + IsmMonAgentUtil.MAJOR);
          IsmMonAgentUtil.trace(e);
        }
      }

      if (cmdflag[SWAP]) {
        try {
          StringTokenizer rtokenizer = new StringTokenizer(freeResult, "\n");
          String line = null;
          while (rtokenizer.hasMoreTokens()) {
            line = rtokenizer.nextToken();
            if (line.startsWith("Swap")) {
              break;
            }
          }
          if (line != null && line.startsWith("Swap")) {
            StringTokenizer ltokenizer = new StringTokenizer(line);
            String swapused = null;
            String swapfree = null;
            ltokenizer.nextToken();
            ltokenizer.nextToken();
            swapused = ltokenizer.nextToken();
            swapfree = ltokenizer.nextToken();
            if (pflag[SWAPUSED]) {
              paramlist.addElement(new PmMeasurement(SWAPUSEDNAME, swapused, true, null));
            }
            if (pflag[SWAPFREE]) {
              paramlist.addElement(new PmMeasurement(SWAPFREENAME, swapfree, true, null));
            }
          } else {
            IsmMonAgentUtil.debug("Error parsing SwapUsed and SwapFree." + IsmMonAgentUtil.MAJOR);
          }
        } catch (Exception e) {
          IsmMonAgentUtil.debug("Error parsing free command swap result." + IsmMonAgentUtil.MAJOR);
          IsmMonAgentUtil.trace(e);
        }
      }
    }
    return getPMData(paramlist, params, pflag, cmdflag, exectime);
  }
Esempio n. 5
0
  /**
   * Executes the commands and process the results to return the PMData.
   *
   * @return returns the PMData instance.
   */
  static PMData getPMData() {

    long exectime = System.currentTimeMillis();
    // execute df or bdf command
    String dfResult = null;
    try {
      if (IsmPmAgentImpl.OS == IsmMaConstants.SOLARIS) {
        dfResult = RunCommand.exec(SOLARIS_DFCMD, 10000);
      } else if (IsmPmAgentImpl.OS == IsmMaConstants.HPUX) {
        dfResult = RunCommand.exec(HPUX_BDFCMD, 10000);
      } else if (IsmPmAgentImpl.OS == IsmMaConstants.AIX) {
        dfResult = RunCommand.exec(AIX_DFCMD, 10000);
      }
    } catch (Exception e) {
      IsmMonAgentUtil.debug(e.getMessage());
    }

    Vector paramlist = new Vector();
    // process the df or bdf command result
    if (dfResult != null && dfResult.trim().length() > 0) {
      Vector devList = new Vector();
      StringTokenizer rtokenizer = new StringTokenizer(dfResult, "\n");
      rtokenizer.nextToken();
      while (rtokenizer.hasMoreTokens()) {
        String line = rtokenizer.nextToken();
        if (line.indexOf("Permission") != -1) {
          continue;
        }
        StringTokenizer ltokenizer = new StringTokenizer(line, " \t");
        if (ltokenizer.hasMoreTokens()) {
          // Filesystem
          String fsName = ltokenizer.nextToken();
          if (!ltokenizer.hasMoreTokens()) {
            if (!rtokenizer.hasMoreTokens()) break;
            line = rtokenizer.nextToken();
            ltokenizer = new StringTokenizer(line, " \t");
          }

          // Total
          String total = ltokenizer.nextToken();
          if (total.equals("-")) {
            continue; // AIX presented this case
          }
          if (!ltokenizer.hasMoreTokens()) {
            if (!rtokenizer.hasMoreTokens()) break;
            line = rtokenizer.nextToken();
            ltokenizer = new StringTokenizer(line, " \t");
          }
          float totalVal = ((float) Long.parseLong(total)) / 1024;

          // Used
          String used = ltokenizer.nextToken();
          if (used.equals("-")) {
            continue; // AIX presented this case
          }
          if (!ltokenizer.hasMoreTokens()) {
            if (!rtokenizer.hasMoreTokens()) break;
            line = rtokenizer.nextToken();
            ltokenizer = new StringTokenizer(line, " \t");
          }
          float usedVal = ((float) Long.parseLong(used)) / 1024;

          // Free
          String free = ltokenizer.nextToken();
          if (free.equals("-")) {
            continue; // AIX presented this case
          }
          if (!ltokenizer.hasMoreTokens()) {
            if (!rtokenizer.hasMoreTokens()) break;
            line = rtokenizer.nextToken();
            ltokenizer = new StringTokenizer(line, " \t");
          }
          float freeVal = ((float) Long.parseLong(free)) / 1024;

          // Capacity
          String capacity = ltokenizer.nextToken();
          capacity = capacity.substring(0, capacity.length() - 1);
          if (!ltokenizer.hasMoreTokens()) {
            if (!rtokenizer.hasMoreTokens()) break;
            line = rtokenizer.nextToken();
            ltokenizer = new StringTokenizer(line, " \t");
          }

          // Mounted on
          String mountFS = ltokenizer.nextToken() + "/";

          addParams(paramlist, fsName, totalVal, usedVal, freeVal, capacity, mountFS);
        }
      }
    }

    // construct the pm data
    PmMeasurement[] pmlist = new PmMeasurement[paramlist.size()];
    paramlist.copyInto(pmlist);
    paramlist.removeAllElements();
    paramlist = null;

    return new PMData(
        IsmPmAgentImpl.LOGSPACE, -1, IsmPmConstants.LOCATION_OS, new Date(exectime), pmlist);
  }