Note: Lister les mbeans existants dans la JVM, afficher leurs attributs
vendredi 24 avril 2015 à 16:51@jeekajoo shaarlinks 24/04/2015
Pour la partie serveur, j'utilise jolokia dont le jar est chargé en tant qu'agent de la jvm, de cette façon:
-javaagent:/var/lib/tomcat8/lib/jolokia-jvm-agent.jar=port=7777,host=localhost,agentContext=/jolokia
Pour la partie cliente, j'utilise la lib python 'pyjolokia': https://github.com/cwood/pyjolokia . Ce client me permet de faire un monitoring de la JVM en python. Ce qui est appréciable.
Voici ma méthode pour lister les mbeans, en mode intéractif via une console python:
# initialisation
>>> from pyjolokia import Jolokia
>>> j4p = Jolokia('http://localhost:7777/jolokia/')
# lister les mbeans dans java.lang:*
>>> j4p.request(type = 'search', mbean='java.lang:*')
{u'status': 200, u'timestamp': 1429886584, u'request': {u'type': u'search', u'mbean': u'java.lang:*'}, u'value': [u'java.lang:name=Metaspace,type=MemoryPool', u'java.lang:type=Runtime', u'java.lang:type=Threading', u'java.lang:type=OperatingSystem', u'java.lang:name=Code Cache,type=MemoryPool', u'java.lang:type=Compilation', u'java.lang:name=G1 Young Generation,type=GarbageCollector', u'java.lang:name=CodeCacheManager,type=MemoryManager', u'java.lang:name=Compressed Class Space,type=MemoryPool', u'java.lang:type=Memory', u'java.lang:name=G1 Eden Space,type=MemoryPool', u'java.lang:name=G1 Old Gen,type=MemoryPool', u'java.lang:name=G1 Old Generation,type=GarbageCollector', u'java.lang:type=ClassLoading', u'java.lang:name=Metaspace Manager,type=MemoryManager', u'java.lang:name=G1 Survivor Space,type=MemoryPool']}
# lister les attributs d'un mbean en particulier, par exemple java.lang:name=G1 Old Generation,type=GarbageCollector
>>> j4p.request(type = 'list', path='java.lang/type=GarbageCollector,name=G1 Old Generation')
{u'status': 200, u'timestamp': 1429886821, u'request': {u'path': u'java.lang/type=GarbageCollector,name=G1 Old Generation', u'type': u'list'}, u'value': {u'attr': {u'CollectionTime': {u'rw': False, u'type': u'long', u'desc': u'CollectionTime'}, u'LastGcInfo': {u'rw': False, u'type': u'javax.management.openmbean.CompositeData', u'desc': u'LastGcInfo'}, u'Name': {u'rw': False, u'type': u'java.lang.String', u'desc': u'Name'}, u'ObjectName': {u'rw': False, u'type': u'javax.management.ObjectName', u'desc': u'ObjectName'}, u'Valid': {u'rw': False, u'type': u'boolean', u'desc': u'Valid'}, u'MemoryPoolNames': {u'rw': False, u'type': u'[Ljava.lang.String;', u'desc': u'MemoryPoolNames'}, u'CollectionCount': {u'rw': False, u'type': u'long', u'desc': u'CollectionCount'}}, u'desc': u'Information on the management interface of the MBean'}}
Voila voila, c'est un peu austère comme méthode mais ça marche.
(Permalink)
Pour la partie serveur, j'utilise jolokia dont le jar est chargé en tant qu'agent de la jvm, de cette façon:
-javaagent:/var/lib/tomcat8/lib/jolokia-jvm-agent.jar=port=7777,host=localhost,agentContext=/jolokia
Pour la partie cliente, j'utilise la lib python 'pyjolokia': https://github.com/cwood/pyjolokia . Ce client me permet de faire un monitoring de la JVM en python. Ce qui est appréciable.
Voici ma méthode pour lister les mbeans, en mode intéractif via une console python:
# initialisation
>>> from pyjolokia import Jolokia
>>> j4p = Jolokia('http://localhost:7777/jolokia/')
# lister les mbeans dans java.lang:*
>>> j4p.request(type = 'search', mbean='java.lang:*')
{u'status': 200, u'timestamp': 1429886584, u'request': {u'type': u'search', u'mbean': u'java.lang:*'}, u'value': [u'java.lang:name=Metaspace,type=MemoryPool', u'java.lang:type=Runtime', u'java.lang:type=Threading', u'java.lang:type=OperatingSystem', u'java.lang:name=Code Cache,type=MemoryPool', u'java.lang:type=Compilation', u'java.lang:name=G1 Young Generation,type=GarbageCollector', u'java.lang:name=CodeCacheManager,type=MemoryManager', u'java.lang:name=Compressed Class Space,type=MemoryPool', u'java.lang:type=Memory', u'java.lang:name=G1 Eden Space,type=MemoryPool', u'java.lang:name=G1 Old Gen,type=MemoryPool', u'java.lang:name=G1 Old Generation,type=GarbageCollector', u'java.lang:type=ClassLoading', u'java.lang:name=Metaspace Manager,type=MemoryManager', u'java.lang:name=G1 Survivor Space,type=MemoryPool']}
# lister les attributs d'un mbean en particulier, par exemple java.lang:name=G1 Old Generation,type=GarbageCollector
>>> j4p.request(type = 'list', path='java.lang/type=GarbageCollector,name=G1 Old Generation')
{u'status': 200, u'timestamp': 1429886821, u'request': {u'path': u'java.lang/type=GarbageCollector,name=G1 Old Generation', u'type': u'list'}, u'value': {u'attr': {u'CollectionTime': {u'rw': False, u'type': u'long', u'desc': u'CollectionTime'}, u'LastGcInfo': {u'rw': False, u'type': u'javax.management.openmbean.CompositeData', u'desc': u'LastGcInfo'}, u'Name': {u'rw': False, u'type': u'java.lang.String', u'desc': u'Name'}, u'ObjectName': {u'rw': False, u'type': u'javax.management.ObjectName', u'desc': u'ObjectName'}, u'Valid': {u'rw': False, u'type': u'boolean', u'desc': u'Valid'}, u'MemoryPoolNames': {u'rw': False, u'type': u'[Ljava.lang.String;', u'desc': u'MemoryPoolNames'}, u'CollectionCount': {u'rw': False, u'type': u'long', u'desc': u'CollectionCount'}}, u'desc': u'Information on the management interface of the MBean'}}
Voila voila, c'est un peu austère comme méthode mais ça marche.
(Permalink)