Changes for page JMX Access

Last modified by Michael Hamann on 2023/08/02 11:19

<
From version < 15.2 >
edited by Vincent Massol
on 2014/11/04 17:01
To version < 24.1
edited by Michael Hamann
on 2023/08/02 11:19
Change comment: Fix the List cache statistics code by ignoring errors

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.VincentMassol
1 +xwiki:XWiki.MichaelHamann
ExtensionCode.ExtensionClass[0]
Show installed count
... ... @@ -1,0 +1,1 @@
1 +Yes
Description
... ... @@ -132,7 +132,7 @@
132 132  
133 133  Results in:
134 134  
135 -{{image reference=jmx.png/}}
135 +{{image reference="jmx.png"/}}
136 136  
137 137  = Example 4: Set Log Level for any XWiki category =
138 138  
... ... @@ -155,6 +155,7 @@
155 155  {{/code}}
156 156  
157 157  = Example 5: Getting a full thread-dump =
158 +
158 158  The below code delivers a thread-dump similar to when the QUIT signal is sent on Unix boxes.
159 159  
160 160  {{code}}
... ... @@ -192,6 +192,7 @@
192 192  
193 193  = Example 6: List cache statistics =
194 194  
196 +{{code}}
195 195  {{groovy}}
196 196  import java.lang.management.ManagementFactory;
197 197  import javax.management.MBeanServer;
... ... @@ -202,9 +202,31 @@
202 202  def names = server.queryNames(query, null)
203 203  names.each {
204 204   println "== Cache: ${it.getKeyProperty('name')} =="
205 - def mbean = new GroovyMBean(server, it)
207 + def mbean = new GroovyMBean(server, it, true)
206 206   for(attr in mbean.listAttributeNames()) {
207 207   println "* ${attr}: ${mbean.getProperty(attr)}"
208 208   }
209 209  }
210 210  {{/groovy}}
213 +{{/code}}
214 +
215 += Example 7: Switch statistics collection states (enabled/disabled) on a cache =
216 +
217 +Example to switch the current state of statistics collection for the page cache ("xwiki.store.pagecache(local)"):
218 +
219 +{{code}}
220 +{{groovy}}
221 +import java.lang.management.ManagementFactory;
222 +import javax.management.MBeanServer;
223 +import javax.management.ObjectName;
224 +import javax.management.Attribute;
225 +
226 +MBeanServer server = ManagementFactory.getPlatformMBeanServer();
227 +def objectName = new ObjectName('org.xwiki.infinispan:type=Cache,name="xwiki.store.pagecache(local)",manager="xwiki",component=Statistics')
228 +def statsState = server.getAttribute(objectName,'statisticsEnabled')
229 +println "Statistics were ${statsState ? 'enabled' : 'disabled'}";
230 +def enableStats = new Attribute("statisticsEnabled", !statsState);
231 +server.setAttribute(objectName,enableStats);
232 +println "Statistics are now ${server.getAttribute(objectName,'statisticsEnabled') ? 'enabled' : 'disabled'}";
233 +{{/groovy}}
234 +{{/code}}

Get Connected