private void createRuntimeProps(MemberStateImpl memberState) {
    Runtime runtime = Runtime.getRuntime();
    ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean();
    MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemory = memoryMxBean.getHeapMemoryUsage();
    MemoryUsage nonHeapMemory = memoryMxBean.getNonHeapMemoryUsage();

    Map<String, Long> map = new HashMap<String, Long>();
    map.put(
        "runtime.availableProcessors", Integer.valueOf(runtime.availableProcessors()).longValue());
    map.put("date.startTime", runtimeMxBean.getStartTime());
    map.put("seconds.upTime", runtimeMxBean.getUptime());

    map.put("memory.maxMemory", runtime.maxMemory());
    map.put("memory.freeMemory", runtime.freeMemory());
    map.put("memory.totalMemory", runtime.totalMemory());
    map.put("memory.heapMemoryMax", heapMemory.getMax());
    map.put("memory.heapMemoryUsed", heapMemory.getUsed());
    map.put("memory.nonHeapMemoryMax", nonHeapMemory.getMax());
    map.put("memory.nonHeapMemoryUsed", nonHeapMemory.getUsed());
    map.put("runtime.totalLoadedClassCount", clMxBean.getTotalLoadedClassCount());
    map.put(
        "runtime.loadedClassCount", Integer.valueOf(clMxBean.getLoadedClassCount()).longValue());
    map.put("runtime.unloadedClassCount", clMxBean.getUnloadedClassCount());
    map.put("runtime.totalStartedThreadCount", threadMxBean.getTotalStartedThreadCount());
    map.put("runtime.threadCount", Integer.valueOf(threadMxBean.getThreadCount()).longValue());
    map.put(
        "runtime.peakThreadCount", Integer.valueOf(threadMxBean.getPeakThreadCount()).longValue());
    map.put(
        "runtime.daemonThreadCount",
        Integer.valueOf(threadMxBean.getDaemonThreadCount()).longValue());
    memberState.setRuntimeProps(map);
  }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see com.orientechnologies.common.test.SpeedTest#startTimer(java.lang.String)
   */
  public void startTimer(final String iName) {
    Runtime.getRuntime().runFinalization();
    Runtime.getRuntime().gc();

    try {
      Thread.sleep(TIME_WAIT);
    } catch (InterruptedException e) {
    }

    final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();

    currentTestName = iName;

    currentTestHeapCommittedMemory = heapMemoryUsage.getCommitted();
    currentTestHeapUsedMemory = heapMemoryUsage.getUsed();
    currentTestHeapMaxMemory = heapMemoryUsage.getMax();

    currentTestNonHeapCommittedMemory = nonHeapMemoryUsage.getCommitted();
    currentTestNonHeapUsedMemory = nonHeapMemoryUsage.getUsed();
    currentTestNonHeapMaxMemory = nonHeapMemoryUsage.getMax();

    System.out.println("-> Started the test of '" + currentTestName + "' (" + cycles + " cycles)");

    currentTestTimer = System.currentTimeMillis();
  }
Ejemplo n.º 3
0
 private void doMemoryUpdates() {
   MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
   MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
   MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
   metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed() / M);
   metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted() / M);
   metrics.setMetric("memHeapUsedM", memHeap.getUsed() / M);
   metrics.setMetric("memHeapCommittedM", memHeap.getCommitted() / M);
 }
Ejemplo n.º 4
0
  public static JSONObject loadMemoryInfo(String app) {
    try {
      MemoryMXBean mBean = JMConnManager.getMemoryMBean(app);
      MemoryUsage nonHeap = mBean.getNonHeapMemoryUsage();
      MemoryUsage heap = mBean.getHeapMemoryUsage();

      JSONObject map = new JSONObject(true);
      buildMemoryJSon(heap, "heap", map);
      buildMemoryJSon(nonHeap, "nonheap", map);

      JSONObject heapChild = new JSONObject();
      JSONObject nonheapChild = new JSONObject();

      JSONObject heapUsed = new JSONObject();
      JSONObject heapMax = new JSONObject();
      heapUsed.put("used", heap.getUsed());
      heapMax.put("used", heap.getCommitted());
      heapChild.put("HeapUsed", heapUsed);
      heapChild.put("HeapCommit", heapMax);

      JSONObject nonheapUsed = new JSONObject();
      JSONObject noheapMax = new JSONObject();
      nonheapUsed.put("used", nonHeap.getUsed());
      noheapMax.put("used", nonHeap.getCommitted());

      nonheapChild.put("NonheapUsed", nonheapUsed);
      nonheapChild.put("NonheapCommit", noheapMax);

      ObjectName obj = new ObjectName("java.lang:type=MemoryPool,*");
      MBeanServerConnection conn = JMConnManager.getConn(app);
      Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null);
      for (ObjectInstance objx : MBeanset) {
        String name = objx.getObjectName().getCanonicalName();
        String keyName = objx.getObjectName().getKeyProperty("name");
        MemoryPoolMXBean bean = JMConnManager.getServer(app, name, MemoryPoolMXBean.class);
        JSONObject item = toJson(bean.getUsage());
        if (JMConnManager.HEAP_ITEM.contains(keyName)) {
          heapChild.put(keyName, item);
        } else {
          nonheapChild.put(keyName, item);
        }
      }
      map.getJSONObject("heap").put("childs", heapChild);
      map.getJSONObject("nonheap").put("childs", nonheapChild);

      return map;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 5
0
  public String getInodeLimitText() {
    long inodes = fsn.dir.totalInodes();
    long blocks = fsn.getBlocksTotal();
    long maxobjects = fsn.getMaxObjects();

    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = mem.getHeapMemoryUsage();
    long totalMemory = heap.getUsed();
    long maxMemory = heap.getMax();

    long used = (totalMemory * 100) / maxMemory;

    String str =
        inodes + " files and directories, " + blocks + " blocks = " + (inodes + blocks) + " total";
    if (maxobjects != 0) {
      long pct = ((inodes + blocks) * 100) / maxobjects;
      str += " / " + maxobjects + " (" + pct + "%)";
    }
    str +=
        ".  Heap Size is "
            + StringUtils.byteDesc(totalMemory)
            + " / "
            + StringUtils.byteDesc(maxMemory)
            + " ("
            + used
            + "%) <br>";
    return str;
  }
  /**
   * Prints the verbose GC log to System.out to list the memory usage of all memory pools as well as
   * the GC statistics.
   */
  @Deprecated
  public String[] getVerboseGc() {
    String gcs = "";

    StringBuilder sb = new StringBuilder();
    sb.append("Uptime: " + StringFormatter.formatMillis(rmbean.getUptime()));

    for (GarbageCollectorMXBean gc : gcmbeans) {
      sb.append(" [" + gc.getName() + ": ");
      sb.append("Count=" + gc.getCollectionCount());
      sb.append(" GCTime=" + StringFormatter.formatMillis(gc.getCollectionTime()));
      sb.append("]");
      gcs +=
          StringFormatter.formatMillisShort(gc.getCollectionTime())
              + ":("
              + gc.getCollectionCount()
              + ");";
    }
    sb.append("\n");
    for (MemoryPoolMXBean p : pools) {
      sb.append("  [" + p.getName() + ":");
      MemoryUsage u = p.getUsage();
      sb.append(" Used=" + StringFormatter.formatBytes(u.getUsed()));
      sb.append(" Committed=" + StringFormatter.formatBytes(u.getCommitted()));
      sb.append("]\n");
    }

    return new String[] {sb.toString(), gcs};
  }
Ejemplo n.º 7
0
  public static void main(String args[]) {

    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();

    long init = heapMemoryUsage.getInit();
    long used = heapMemoryUsage.getUsed();
    long max = heapMemoryUsage.getMax();
    long committed = heapMemoryUsage.getCommitted();
    long free = max - used;
    int usedPercent = (int) (used / max);
    int freePercent = (int) (usedPercent / max);

    MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();

    List<GarbageCollectorMXBean> garbageCollectorMXBeans =
        ManagementFactory.getGarbageCollectorMXBeans();

    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();

    com.sun.management.OperatingSystemMXBean operatingSystemMXBean =
        (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    long commitVirtual = operatingSystemMXBean.getCommittedVirtualMemorySize();

    println(init, used, max, committed);
    println(commitVirtual);
  }
Ejemplo n.º 8
0
  public static Struct getMemoryUsageAsStruct(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    long used = 0, max = 0, init = 0;
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if ((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP)
          || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
        used += usage.getUsed();
        max += usage.getMax();
        init += usage.getInit();
      }
    }
    Struct sct = new StructImpl();
    sct.setEL(KeyConstants._used, Caster.toDouble(used));
    sct.setEL(KeyConstants._max, Caster.toDouble(max));
    sct.setEL(KeyConstants._init, Caster.toDouble(init));
    sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
    return sct;
  }
Ejemplo n.º 9
0
 /** Add JVM heap metrics. */
 protected void addHeapMetrics(Collection<Metric<?>> result) {
   MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
   result.add(new Metric<Long>("heap.committed", memoryUsage.getCommitted() / 1024));
   result.add(new Metric<Long>("heap.init", memoryUsage.getInit() / 1024));
   result.add(new Metric<Long>("heap.used", memoryUsage.getUsed() / 1024));
   result.add(new Metric<Long>("heap", memoryUsage.getMax() / 1024));
 }
Ejemplo n.º 10
0
  public Map<String, String> getProperties() {
    Map<String, String> map = new TreeMap<String, String>();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

    List<String> aList = runtimeMXBean.getInputArguments();
    String parameters = "";
    for (int i = 0; i < aList.size(); i++) {
      parameters = parameters + " " + aList.get(i);
    }
    map.put("params", parameters);

    map.put("name", runtimeMXBean.getVmName());
    map.put("vendor", runtimeMXBean.getVmVendor());
    map.put("version", runtimeMXBean.getVmVersion());
    map.put("specification", runtimeMXBean.getSpecVersion());
    map.put("uptime", DurationFormatUtils.formatDurationHMS(runtimeMXBean.getUptime()));

    Date date = new Date(runtimeMXBean.getStartTime());
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    map.put("start time", sdf.format(date));

    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();

    MemoryUsage heap = memory.getHeapMemoryUsage();
    map.put(
        "memory. (heap)",
        readableFileSize(heap.getUsed())
            + "/"
            + readableFileSize(heap.getCommitted())
            + " min:"
            + readableFileSize(heap.getInit())
            + " max:"
            + readableFileSize(heap.getMax()));
    MemoryUsage nonheap = memory.getNonHeapMemoryUsage();
    map.put(
        "memory (non heap)",
        readableFileSize(nonheap.getUsed())
            + "/"
            + readableFileSize(nonheap.getCommitted())
            + " min:"
            + readableFileSize(nonheap.getInit())
            + " max:"
            + readableFileSize(nonheap.getMax()));

    return map;
  }
Ejemplo n.º 11
0
 private static JSONObject toJson(MemoryUsage useage) {
   JSONObject item = new JSONObject();
   item.put("commit", useage.getCommitted());
   item.put("used", useage.getUsed());
   item.put("init", useage.getInit());
   item.put("max", useage.getMax());
   return item;
 }
Ejemplo n.º 12
0
  public static int getFreePermGenSpacePromille() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null) return -1;

    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0) return -1;
    return (int) (1000L - (1000L * used / max));
  }
Ejemplo n.º 13
0
  public static long getFreePermGenSpaceSize() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null) return -1;

    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0) return -1;
    return max - used;
  }
Ejemplo n.º 14
0
  /**
   * Grid-enables method only if heap utilized over 80%. Otherwise, method method will proceed with
   * local execution without calling grid at all.
   *
   * @param gridify {@inheritDoc}
   * @param arg {@inheritDoc}
   * @return {@inheritDoc}
   * @throws GridException {@inheritDoc}
   */
  @Override
  public boolean isGridify(Annotation gridify, GridifyArgument arg) throws GridException {
    MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    // If heap memory for the local node is above 80% of maximum heap
    // memory available, return true which means that method will
    // be grid-enabled. Otherwise, return false, which means that
    // method will execute locally without grid.
    return heap.getUsed() > 0.8 * heap.getMax();
  }
Ejemplo n.º 15
0
 /**
  * Format contents of a MemoryUsage object.
  *
  * @param name a text prefix used in formatting
  * @param usage the MemoryUsage object to format
  * @return the formatted contents
  */
 private static String formatMemoryUsage(String name, MemoryUsage usage) {
   if (usage != null) {
     StringBuilder sb = new StringBuilder();
     sb.append(INDENT1 + name + " init: " + usage.getInit() + CRLF);
     sb.append(INDENT1 + name + " used: " + usage.getUsed() + CRLF);
     sb.append(INDENT1 + name + " committed: " + usage.getCommitted() + CRLF);
     sb.append(INDENT1 + name + " max: " + usage.getMax() + CRLF);
     return sb.toString();
   }
   return "";
 }
Ejemplo n.º 16
0
  public static int getPermGenFreeSpaceAsAPercentageOfAvailable() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null) return -1;

    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0) return -1;

    // return a value that equates to a percentage of available free memory
    return 100 - ((int) (100 * (((double) used) / ((double) max))));
  }
Ejemplo n.º 17
0
 public void dumpMemory(String title) {
   System.err.println("----------" + title + "----------");
   double total = 0;
   for (MemoryPoolMXBean m : memoryBeans) {
     MemoryUsage u = m.getUsage();
     double used = u.getUsed();
     total += used;
     System.err.println(m.getName() + " " + toMemoryString(used));
   }
   System.err.println("Total " + toMemoryString(total));
   System.err.println("---------------------------------");
 }
Ejemplo n.º 18
0
  protected void updateMemory() {
    // Determining current memory usage state
    MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    usedMemory = mu.getUsed();
    allocatedMemory = mu.getCommitted();

    // Updating bar text
    setText(getMemoryBarText());

    // Updating view
    repaint();
  }
Ejemplo n.º 19
0
  private String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
    MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
    MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

    int mb = 1 << 20;

    int heapUsed = (int) (heap.getUsed() / mb);
    int heapCommitted = (int) (heap.getCommitted() / mb);
    int heapMax = (int) (heap.getMax() / mb);

    int nonHeapUsed = (int) (nonHeap.getUsed() / mb);
    int nonHeapCommitted = (int) (nonHeap.getCommitted() / mb);
    int nonHeapMax = (int) (nonHeap.getMax() / mb);

    String msg =
        String.format(
            "Memory usage stats: [HEAP: %d/%d/%d MB, NON HEAP: %d/%d/%d MB (used/comitted/max)]",
            heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax);

    return msg;
  }
Ejemplo n.º 20
0
 public static synchronized State release() {
   long now = System.currentTimeMillis();
   if (marks.empty())
     throw new RuntimeException(
         "TimeStiatistics: Called release() without a matching call to mark()");
   State m = marks.pop();
   m.garbageCounterDelta = garbageCounter.get() - m.garbageCounterMark;
   m.end = now;
   MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
   m.memoryUsedEnd = memoryUsage.getUsed();
   System.out.println(m.toString());
   return m;
 }
Ejemplo n.º 21
0
  /**
   * Puts a marker in the marker stack. Every call to this method should have a corresponding call
   * to {@link #release()}. Calls to this method may be nested.
   *
   * @param markName the name of the marker
   */
  public static synchronized void mark(String markName) {
    State marker = new State();
    marker.id = markName;
    marker.start = System.currentTimeMillis();
    MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    marker.memoryUsedStart = memoryUsage.getUsed();
    marker.garbageCounterMark = garbageCounter.get();

    marks.push(marker);
    System.out.println(
        "Set block marker \""
            + markName
            + "\", memory used "
            + Util.getFormatBytes(marker.memoryUsedStart));
  }
Ejemplo n.º 22
0
 public static String formatHeapMemoryUsage(MemoryUsage beforHeap, MemoryUsage afterHeap) {
   return afterHeap != null
       ? CapString.concat(
           "Heap Usage: Committed=",
           bytesToMegabytes(beforHeap.getCommitted()),
           "->",
           bytesToMegabytes(afterHeap.getCommitted()),
           " MB, Init=",
           bytesToMegabytes(beforHeap.getInit()),
           "->",
           bytesToMegabytes(afterHeap.getInit()),
           " MB, Max=",
           bytesToMegabytes(beforHeap.getMax()),
           "->",
           bytesToMegabytes(afterHeap.getMax()),
           " MB, Used=",
           bytesToMegabytes(beforHeap.getUsed()),
           "->",
           bytesToMegabytes(afterHeap.getUsed()),
           "=",
           (bytesToMegabytes(afterHeap.getUsed() - beforHeap.getUsed())),
           " MB ")
       : "";
 }
Ejemplo n.º 23
0
  @Override
  public Iterable<Measurement> measure() {
    final long timestamp = clock.wallTime();
    final MemoryPoolMXBean mbean = ref.get();
    final List<Measurement> ms = new ArrayList<>();
    if (mbean != null) {
      final String typeKey = "memtype";
      final String type = mbean.getName();

      final MemoryUsage usage = mbean.getUsage();
      ms.add(new Measurement(usedId.withTag(typeKey, type), timestamp, usage.getUsed()));
      ms.add(new Measurement(committedId.withTag(typeKey, type), timestamp, usage.getCommitted()));
      ms.add(new Measurement(maxId.withTag(typeKey, type), timestamp, usage.getMax()));
    }
    return ms;
  }
Ejemplo n.º 24
0
 @SuppressWarnings("unchecked")
 public JSONObject info() throws JSONException {
   JSONObject object = new JSONObject();
   object.put("gossip_active", isInitialized());
   object.put("thrift_active", isThriftServerRunning());
   object.put("token", getTokens().toString());
   object.put("load", getLoadString());
   object.put("generation_no", getCurrentGenerationNumber());
   object.put("uptime", getUptime() / 1000);
   MemoryUsage heapUsage = getHeapMemoryUsage();
   double memUsed = (double) heapUsage.getUsed() / (1024 * 1024);
   double memMax = (double) heapUsage.getMax() / (1024 * 1024);
   object.put("heap_memory_mb", memUsed + "/" + memMax);
   object.put("data_center", getDataCenter());
   object.put("rack", getRack());
   return object;
 }
  public String getMemoryState() {
    try {
      StringBuilder sb = new StringBuilder();
      sb.append("Uptime: " + StringFormatter.formatMillis(rmbean.getUptime()));

      sb.append("\n");
      for (MemoryPoolMXBean p : pools) {
        sb.append("  [" + p.getName() + ":");
        MemoryUsage u = p.getUsage();
        sb.append(" Used=" + StringFormatter.formatBytes(u.getUsed()));
        sb.append(" Committed=" + StringFormatter.formatBytes(u.getCommitted()));
        sb.append("]\n");
      }

      return sb.toString();
    } catch (Throwable e) {
      return e.getMessage();
    }
  }
Ejemplo n.º 26
0
 /**
  * Prints the verbose GC log to System.out to list the memory usage of all memory pools as well as
  * the GC statistics.
  */
 public void printVerboseGc() {
   System.out.println("Uptime: " + formatMillis(rmbean.getUptime()));
   System.out.println("Heap usage: " + mmbean.getHeapMemoryUsage());
   System.out.println("Non-Heap memory usage: " + mmbean.getNonHeapMemoryUsage());
   for (GarbageCollectorMXBean gc : gcmbeans) {
     System.out.print(" [" + gc.getName() + ": ");
     System.out.print("Count=" + gc.getCollectionCount());
     System.out.print(" GCTime=" + formatMillis(gc.getCollectionTime()));
     System.out.print("]");
   }
   System.out.println();
   for (MemoryPoolMXBean p : pools) {
     System.out.print("  [" + p.getName() + ":");
     MemoryUsage u = p.getUsage();
     System.out.print(" Used=" + formatBytes(u.getUsed()));
     System.out.print(" Committed=" + formatBytes(u.getCommitted()));
     System.out.println("]");
   }
 }
 @Override
 public long[] getSystemStatus() {
   long[] systemData = new long[4];
   MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
   systemData[0] = memoryMXBean.getHeapMemoryUsage().getUsed();
   systemData[1] = memoryMXBean.getNonHeapMemoryUsage().getUsed();
   List<MemoryPoolMXBean> mbeans = ManagementFactory.getMemoryPoolMXBeans();
   if (mbeans != null) {
     for (MemoryPoolMXBean mbean : mbeans) {
       MemoryUsage memUsage = mbean.getUsage();
       if (mbean.getName().equals(PERMGEN_MEMORY_POOL_NAME)) {
         systemData[2] = memUsage.getUsed();
       }
     }
   }
   ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
   systemData[3] = threadMXBean.getThreadCount();
   return systemData;
 }
Ejemplo n.º 28
0
  public static Struct getMemoryUsageCompact(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    Struct sct = new StructImpl();
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP) continue;
      if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP) continue;

      double d = ((int) (100D / usage.getMax() * usage.getUsed())) / 100D;
      sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
    }
    return sct;
  }
Ejemplo n.º 29
0
  public static void memUsage(PrintWriter out) {

    // Overall
    MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = memBean.getHeapMemoryUsage();
    MemoryUsage nonHeap = memBean.getNonHeapMemoryUsage();
    out.println("Heap: " + heap);
    out.println("Non-heap: " + nonHeap);

    // Generations details
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean mbean : memoryPoolMXBeans) {
      println(out, "Memory Group", mbean.getName());
      MemoryUsage memUsage = mbean.getUsage();
      println(out, "Used", memUsage.getUsed());
      println(out, "Committed", memUsage.getCommitted());
      println(out, "High water", memUsage.getMax());
      out.println();
    }
  }
Ejemplo n.º 30
0
  public void handleNotification(Notification notification, Object handback) {

    log.warn("================================================================================");

    String message = notification.getMessage();
    log.warn("Message: " + message);

    String type = notification.getType();
    log.warn("Type: " + type);

    if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
        || type.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {

      CompositeData cd = (CompositeData) notification.getUserData();
      MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);

      String poolName = info.getPoolName();
      log.warn("Pool Name: " + poolName);

      long count = info.getCount();
      log.warn("Count: " + count);

      MemoryUsage usage = info.getUsage();

      long maxMemory = usage.getMax();
      long maxMB = maxMemory / (1024 * 1024);

      long usedMemory = usage.getUsed();
      long usedMB = usedMemory / (1024 * 1024);

      double percentUsed = (double) usedMemory / maxMemory;
      log.debug(
          "Used Memory : "
              + usedMB
              + "/"
              + maxMB
              + " MB ("
              + percentFormat.format(percentUsed)
              + ")");
    }
  }