示例#1
0
  /** Task run() implementation. */
  public void run() {

    PMData pmData = null;
    try {
      pmData = getPMData(pmparams, pmflags);
    } catch (Exception e) {
      IsmMonAgentUtil.debug(e.getMessage(), IsmMonAgentUtil.CRITICAL);
      IsmMonAgentUtil.trace(e);
    }
    if (pmData != null) {
      if (listenerList != null && listenerList.size() > 0) {
        TaskEvent taskEvent = new TaskEvent(this, getLastExecutionTime(), pmData);
        for (Enumeration en = listenerList.elements(); en.hasMoreElements(); ) {
          ((TaskListener) en.nextElement()).taskExecuted(taskEvent);
        }
      }
    }
  }
示例#2
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);
  }
示例#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);
  }