Exemple #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);
  }
Exemple #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);
  }
Exemple #3
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);
  }