Пример #1
0
  private static void addParams(
      Vector paramlist,
      String fsName,
      float totalVal,
      float usedVal,
      float freeVal,
      String capacity,
      String mountFS) {

    for (Enumeration en = logSpaceList.keys(); en.hasMoreElements(); ) {
      String logSpaceName = (String) en.nextElement();
      String[] logDirList = (String[]) logSpaceList.get(logSpaceName);
      for (int i = 0; i < logDirList.length; i++) {
        String logDirPath = logDirList[i];

        // Get actual filesystem name for the directory
        String fs = (String) filesystemMap.get(logDirPath) + "/";

        if (fs != null && fs.equals(mountFS)) {
          String modifier = logSpaceName + "=" + logDirPath;
          paramlist.addElement(
              new PmMeasurement(
                  DIRPATHUSEDSPACENAME,
                  String.valueOf(getDirDiskSpace(logDirPath)),
                  true,
                  modifier));
          paramlist.addElement(new PmMeasurement(FILESYSTEMNAME, fsName, true, modifier));
          paramlist.addElement(
              new PmMeasurement(TOTALSPACENAME, String.valueOf(totalVal), true, modifier));
          paramlist.addElement(
              new PmMeasurement(USEDSPACENAME, String.valueOf(usedVal), true, modifier));
          paramlist.addElement(
              new PmMeasurement(AVAILSPACENAME, String.valueOf(freeVal), true, modifier));
          paramlist.addElement(new PmMeasurement(USEDCAPACITYNAME, capacity, true, modifier));
        }
      }
    }
  }
Пример #2
0
  /**
   * Executes the commands and process the results to return the memory pm data.
   *
   * @param paramlist pm parameter values list.
   * @param params the performance metrices to be monitored.
   * @param pflag parameter flags.
   * @param cmdflag command flags.
   * @param exectime time the data collected.
   * @return returns the PMData instance.
   */
  private static PMData getPMData(
      Vector paramlist, String[] params, boolean[] pflag, boolean[] cmdflag, long exectime) {

    // execute the vmstat command
    String vmstatResult = null;
    // execute the vmstat command twice for AIX to retrieve page fault information
    String vmstatResult1 = null;
    String vmstatResult2 = null;
    if (cmdflag[VMSTAT]) {
      try {
        vmstatResult = RunCommand.exec(VMSTATCMD, 10000);
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }

      if (IsmPmAgentImpl.OS == IsmMaConstants.AIX) {
        try {
          vmstatResult1 = RunCommand.exec(AIX_VMSTATCMD);
        } catch (Exception e) {
          IsmMonAgentUtil.debug(e.getMessage());
        }
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        ;
        try {
          vmstatResult2 = RunCommand.exec(AIX_VMSTATCMD);
        } catch (Exception e) {
          IsmMonAgentUtil.debug(e.getMessage());
        }
      }
    }

    // execute the vmstat command to get swap info
    // AIX does not have -S option for vmstat
    String vmstatswapResult = null;
    if (cmdflag[VMSTATSWAP] && IsmPmAgentImpl.OS != IsmMaConstants.AIX) {
      try {
        if (IsmPmAgentImpl.OS != IsmMaConstants.LINUX) {
          vmstatswapResult = RunCommand.exec(VMSTATSWAPLINUXCMD, 10000);
        } else {
          vmstatswapResult = RunCommand.exec(VMSTATSWAPCMD, 10000);
        }
      } catch (Exception e) {
        IsmMonAgentUtil.debug(e.getMessage());
      }
    }

    // process the vmstat result
    if (cmdflag[VMSTAT] && (vmstatResult != null)) {
      StringTokenizer rtokenizer = new StringTokenizer(vmstatResult, "\n");
      String line = null;
      if (rtokenizer.hasMoreTokens()) line = rtokenizer.nextToken(); // column groupings header

      if (IsmPmAgentImpl.OS == IsmMaConstants.AIX) {
        // AIX has an additional line
        if (rtokenizer.hasMoreTokens()) line = rtokenizer.nextToken(); // dashed lines
      }

      if (rtokenizer.hasMoreTokens()) line = rtokenizer.nextToken(); // column labels

      if (rtokenizer.hasMoreTokens()) line = rtokenizer.nextToken(); // first line of results;

      // Skip the first line of results and collect data from the
      // second line.
      // Only parsing a single line of data, but use a while loop
      // so that we can easily break out of the processing if we
      // don't have enough tokens.
      while (rtokenizer.hasMoreTokens()) {
        line = rtokenizer.nextToken(); // second line of results;

        StringTokenizer ltokenizer = new StringTokenizer(line, " \t");

        int cnt = ltokenizer.countTokens();

        // Need at least 14 tokens that will be needed for all OS's
        if (cnt < 14) break;

        String r = ltokenizer.nextToken();
        String b = ltokenizer.nextToken();

        // AIX and Linux does not have a w column
        if (IsmPmAgentImpl.OS == IsmMaConstants.SOLARIS
            || IsmPmAgentImpl.OS == IsmMaConstants.HPUX) {
          ltokenizer.nextToken(); // Skip w column
        }
        String swap = ltokenizer.nextToken();
        String free = "n/a";
        free = ltokenizer.nextToken();

        String re = ltokenizer.nextToken();
        if (IsmPmAgentImpl.OS == IsmMaConstants.LINUX) {
          re = "0";
        }
        String mf = null;
        if (IsmPmAgentImpl.OS == IsmMaConstants.SOLARIS
            || IsmPmAgentImpl.OS == IsmMaConstants.HPUX) {
          mf = ltokenizer.nextToken();
        } else if (IsmPmAgentImpl.OS == IsmMaConstants.LINUX) {
          mf = "0";
        } else {
          // AIX doesn't supply mf or at via vmstat, so use vmstat command twice
          // to retrieve
          /* output will look like:
          /users/donjiang>vmstat -s
                     3565041603 total address trans. faults
                       59621208 page ins
                      187195152 page outs
                          37598 paging space page ins
                         255904 paging space page outs
                              0 total reclaims
                     1162272236 zero filled pages faults
                      114011306 executable filled pages faults
                       38332962 pages examined by clock
                              8 revolutions of the clock hand
                       15545326 pages freed by the clock
                       33240616 backtracks
                              0 lock misses
                          56054 free frame waits
                              2 extend XPT waits
                       19326700 pending I/O waits
                      108413391 start I/Os
                      108420004 iodones
                     2929261290 cpu context switches
                     2842949964 device interrupts
                              0 software interrupts
                              0 traps
                    71007291963 syscalls
          */
          long total_address_trans_fault1 = 0;
          long total_address_trans_fault2 = 0;
          if (vmstatResult1 != null) {
            StringTokenizer rvmstattokenizer = new StringTokenizer(vmstatResult1, "\n");
            String vmstatline = null;
            while (rvmstattokenizer.hasMoreTokens()) {
              vmstatline = rvmstattokenizer.nextToken().trim();
              int index = vmstatline.indexOf("total address trans. faults");
              if (index >= 0) {
                total_address_trans_fault1 = Long.parseLong(vmstatline.substring(0, index).trim());
                break;
              }
            }
          }

          if (vmstatResult2 != null) {
            StringTokenizer rvmstattokenizer = new StringTokenizer(vmstatResult2, "\n");
            String vmstatline = null;
            while (rvmstattokenizer.hasMoreTokens()) {
              vmstatline = rvmstattokenizer.nextToken().trim();
              int index = vmstatline.indexOf("total address trans. faults");
              if (index >= 0) {
                total_address_trans_fault2 = Long.parseLong(vmstatline.substring(0, index).trim());
                break;
              }
            }
          }
          if (total_address_trans_fault1 != 0 && total_address_trans_fault2 != 0) {
            mf = String.valueOf(Math.abs(total_address_trans_fault2 - total_address_trans_fault1));
          }
        }
        // At this point, there should be at least 10 tokens left.
        if (ltokenizer.countTokens() < 10) break;
        String pi = ltokenizer.nextToken();
        String po = ltokenizer.nextToken();
        String fr = ltokenizer.nextToken();
        String de = null;
        if (IsmPmAgentImpl.OS == IsmMaConstants.SOLARIS
            || IsmPmAgentImpl.OS == IsmMaConstants.HPUX) {
          de = ltokenizer.nextToken();
        } else {
          // AIX doesn't support
          de = "0";
        }
        String sr = ltokenizer.nextToken();

        if (IsmPmAgentImpl.OS == IsmMaConstants.SOLARIS) {
          // Solaris has up to 4 columns for disk operations.
          // Determine if there are less than 4 disk columns.
          // int cnt2 = ltokenizer.countTokens();
          // IsmMonAgentUtil.debug("vmstat counts, cnt=" + cnt + "  cnt2=" + cnt2,
          // IsmMonAgentUtil.MAJOR);
          while (ltokenizer.countTokens() > 6) {
            ltokenizer.nextToken(); // Skip disk operations
          }
        }

        if (ltokenizer.countTokens() < 6) break;

        ltokenizer.nextToken(); // Skip in
        ltokenizer.nextToken(); // Skip sy
        ltokenizer.nextToken(); // Skip cs
        String us = ltokenizer.nextToken();
        String sy = ltokenizer.nextToken();
        String id = ltokenizer.nextToken();

        if (pflag[PAGESRECLAIMED]) {
          paramlist.addElement(new PmMeasurement(PAGESRECLAIMEDNAME, re, true, null));
        }
        if (pflag[PAGEFAULTS]) {
          paramlist.addElement(new PmMeasurement(PAGEFAULTSNAME, mf, true, null));
        }
        if (pflag[PAGESPAGEDIN]) {
          paramlist.addElement(new PmMeasurement(PAGESPAGEDINNAME, pi, true, null));
        }
        if (pflag[PAGESPAGEDOUT]) {
          paramlist.addElement(new PmMeasurement(PAGESPAGEDOUTNAME, po, true, null));
        }
        if (pflag[PAGESFREED]) {
          paramlist.addElement(new PmMeasurement(PAGESFREEDNAME, fr, true, null));
        }
        if (pflag[ANTICIPATEDMEMORYSHORTFALL]) {
          paramlist.addElement(new PmMeasurement(ANTICIPATEDMEMORYSHORTFALLNAME, de, true, null));
        }
        if (pflag[PAGESSCANRATE]) {
          paramlist.addElement(new PmMeasurement(PAGESSCANRATENAME, sr, true, null));
        }

        if (pflag[RUNQUEUE]) {
          paramlist.addElement(new PmMeasurement(RUNQUEUENAME, r, true, null));
        }
        if (pflag[BLOCKEDQUEUE]) {
          paramlist.addElement(new PmMeasurement(BLOCKEDQUEUENAME, b, true, null));
        }
        if (pflag[VMSWAP]) {
          paramlist.addElement(new PmMeasurement(VMSWAPNAME, swap, true, null));
        }
        if (pflag[VMFREE]) {
          paramlist.addElement(new PmMeasurement(VMFREENAME, free, true, null));
        }
        if (pflag[VMUSR]) {
          paramlist.addElement(new PmMeasurement(VMUSRNAME, us, true, null));
        }
        if (pflag[VMSYS]) {
          paramlist.addElement(new PmMeasurement(VMSYSNAME, sy, true, null));
        }
        if (pflag[VMIDL]) {
          paramlist.addElement(new PmMeasurement(VMIDLNAME, id, true, null));
        }

        break; // Break out of while loop.  Only want to process one line
        // of results.
      }
    }

    // process swap result
    String si = "n/a";
    String so = "n/a";
    if (cmdflag[VMSTATSWAP] && (vmstatswapResult != null)) {
      StringTokenizer rtokenizer = new StringTokenizer(vmstatswapResult, "\n");
      if (rtokenizer.countTokens() >= 4) {
        String line = rtokenizer.nextToken();
        line = rtokenizer.nextToken();
        line = rtokenizer.nextToken();
        // Skip the first line of results and collect data from the
        // second line.
        line = rtokenizer.nextToken();

        StringTokenizer ltokenizer = new StringTokenizer(line, " \t");
        if (ltokenizer.countTokens() >= 7) {
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          ltokenizer.nextToken();
          if (IsmPmAgentImpl.OS == IsmMaConstants.LINUX) {
            ltokenizer.nextToken();
          }
          si = ltokenizer.nextToken();
          so = ltokenizer.nextToken();
        }
      }
    }
    if (pflag[PAGESSWAPPEDIN]) {
      paramlist.addElement(new PmMeasurement(PAGESSWAPPEDINNAME, si, true, null));
    }
    if (pflag[PAGESSWAPPEDOUT]) {
      paramlist.addElement(new PmMeasurement(PAGESSWAPPEDOUTNAME, so, true, null));
    }

    PmMeasurement[] pmlist = new PmMeasurement[paramlist.size()];
    paramlist.copyInto(pmlist);
    paramlist.removeAllElements();
    paramlist = null;

    return new PMData(
        IsmPmAgentImpl.MEMORY, -1, IsmPmConstants.LOCATION_OS, new Date(exectime), pmlist);
  }
Пример #3
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);
  }
Пример #4
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);
  }
Пример #5
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);
  }
Пример #6
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);
  }
Пример #7
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);
  }