前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Groovy-14.JMX

Groovy-14.JMX

作者头像
悠扬前奏
发布2019-05-28 12:50:49
发布2019-05-28 12:50:49
37100
代码可运行
举报
运行总次数:0
代码可运行

作:

监视JVM

通过java.lang.management提供的标准类可以对JVM进行监视:

代码语言:javascript
代码运行次数:0
运行
复制
import java.lang.management.*

def os = ManagementFactory.operatingSystemMXBean 
println """OPERATING SYSTEM: 
    OS architecture = $os.arch 
    OS name = $os.name 
    OS version = $os.version 
    OS processors = $os.availableProcessors 
""" 
 
def rt = ManagementFactory.runtimeMXBean 
println """RUNTIME: 
    Runtime name = $rt.name 
    Runtime spec name = $rt.specName 
    Runtime vendor = $rt.specVendor 
    Runtime spec version = $rt.specVersion 
    Runtime management spec version = $rt.managementSpecVersion 
   """ 

def mem = ManagementFactory.memoryMXBean 
def heapUsage = mem.heapMemoryUsage 
def nonHeapUsage = mem.nonHeapMemoryUsage 

println """MEMORY: 
   HEAP STORAGE: 
        Memory committed = $heapUsage.committed 
        Memory init = $heapUsage.init 
        Memory max = $heapUsage.max 
        Memory used = $heapUsage.used NON-HEAP STORAGE: 
        Non-heap memory committed = $nonHeapUsage.committed 
        Non-heap memory init = $nonHeapUsage.init 
        Non-heap memory max = $nonHeapUsage.max 
        Non-heap memory used = $nonHeapUsage.used 
   """
  
println "GARBAGE COLLECTION:" 
ManagementFactory.garbageCollectorMXBeans.each { gc ->
   println "    name = $gc.name"
   println "        collection count = $gc.collectionCount"
   println "        collection time = $gc.collectionTime"
   String[] mpoolNames =   gc.memoryPoolNames
    
   mpoolNames.each { 
      mpoolName -> println "        mpool name = $mpoolName"
   } 
}

代码执行的时候回根据运行时的系统而变化:

代码语言:javascript
代码运行次数:0
运行
复制
OPERATING SYSTEM: 
   OS architecture = x86 
   OS name = Windows 7 
   OS version = 6.1 
   OS processors = 4
   
RUNTIME: 
   Runtime name = 5144@Babuli-PC 
   Runtime spec name = Java Virtual Machine Specification 
   Runtime vendor = Oracle Corporation 
   Runtime spec version = 1.7 
   Runtime management spec version = 1.2
   
MEMORY: 
   HEAP STORAGE: 
      Memory committed = 16252928 
      Memory init = 16777216 
      Memory max = 259522560 
      Memory used = 7355840
   
NON-HEAP STORAGE: 
   Non-heap memory committed = 37715968 
   Non-heap memory init = 35815424 
   Non-heap memory max = 123731968 
   Non-heap memory used = 18532232 
   
GARBAGE COLLECTION: 
   name = Copy 
   collection count = 15 
   collection time = 47 
   mpool name = Eden Space 
   mpool name = Survivor Space
        
   name = MarkSweepCompact 
      collection count = 0 
      collection time = 0 
        
      mpool name = Eden Space 
      mpool name = Survivor Space 
      mpool name = Tenured Gen 
      mpool name = Perm Gen 
      mpool name = Perm Gen [shared-ro] 
      mpool name = Perm Gen [shared-rw]

监控Tomcat

为了监控Tomcat,在启动Tomcat的时候设置以下参数:

代码语言:javascript
代码运行次数:0
运行
复制
set JAVA_OPTS = -Dcom.sun.management.jmxremote 
Dcom.sun.management.jmxremote.port = 9004
 
-Dcom.sun.management.jmxremote.authenticate=false 
Dcom.sun.management.jmxremote.ssl = false
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.04.13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 监视JVM
  • 监控Tomcat
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档