3 Replies Latest reply: Jun 5, 2013 12:10 PM by jtahlborn RSS

    Script to get JVM Usage

    821469
      I am able to get System memory usage using Runtime class but I need to know how to get memory usage for specific java process on the server
      and mail to be sent. Appreciate if anybody help on this.
      System.out.println("Total Memory:" + runtime.totalMemory());
      System.out.println("Max Memory:" + runtime.maxMemory());
        • 1. Re: Script to get JVM Usage
          gimbal2
          You can get a snapshot of the runtime's memory state yes. But to get the usage of a specific process is something you'd ask the operating system, this question has little to nothing to do with Java.
          • 2. Re: Script to get JVM Usage
            821469
            But still can't we grab the JVM usage using Java.
            • 3. Re: Script to get JVM Usage
              jtahlborn
              Maybe i'm not understanding your question, but if you are looking for how much memory the java process is using, you have the answer already (those lines of code in your original question). Those values are not the system memory size and usage, they are the jvm process memory allowance and usage.

              if you want the system values, you can use this JMX mbean:

              http://docs.oracle.com/javase/6/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html