| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!-- |
| 3 |
~ Copyright 2009-2013 Roland Huss |
| 4 |
~ |
| 5 |
~ Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
~ you may not use this file except in compliance with the License. |
| 7 |
~ You may obtain a copy of the License at |
| 8 |
~ |
| 9 |
~ http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
~ |
| 11 |
~ Unless required by applicable law or agreed to in writing, software |
| 12 |
~ distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
~ See the License for the specific language governing permissions and |
| 15 |
~ limitations under the License. |
| 16 |
--> |
| 17 |
|
| 18 |
<section id="read"> |
| 19 |
<title>Reading attributes (read)</title> |
| 20 |
<para> |
| 21 |
Reading MBean attributes is probably the most used JMX method, |
| 22 |
especially when it comes to monitoring. Concerning Jolokia, it is |
| 23 |
also the most powerful one with the richest semantics. Obviously |
| 24 |
the value of a single attribute can be fetched, but Jolokia |
| 25 |
supports also fetching of a list of given attributes on a single |
| 26 |
MBean or even on multiple MBeans matching a certain pattern. |
| 27 |
</para> |
| 28 |
<para> |
| 29 |
Reading attributes are supported by both kinds of requests, |
| 30 |
<literal>GET</literal> and <literal>POST</literal>. |
| 31 |
</para> |
| 32 |
<note> |
| 33 |
Don't confuse fetching multiple attributes on possibly multiple |
| 34 |
MBeans with bulk requests. A single read request will always |
| 35 |
result in a single read response, even when multiple attribute |
| 36 |
values are fetched. Only the single response's structure of the |
| 37 |
<literal>value</literal> will differ depending on what kind of |
| 38 |
read request was performed. |
| 39 |
</note> |
| 40 |
<para> |
| 41 |
A read request for multiple attributes on the same MBean is |
| 42 |
initiated by giving a list of attributes to the request. For a |
| 43 |
POST request this is an JSON array, for a GET request it is a |
| 44 |
comma separated list of attribute names (where slashes and |
| 45 |
exclamation marks must be escaped as described in <xref |
| 46 |
linkend="escape-rules"/>). If no attribute is provided, then all |
| 47 |
attributes are fetched. The MBean name can be given as a pattern |
| 48 |
in which case the attributes are read on all matching MBeans. If a |
| 49 |
MBean pattern and multiple attributes are requested, then only the |
| 50 |
value of attributes which matches both are returned, the others |
| 51 |
are ignored. |
| 52 |
</para> |
| 53 |
<para> |
| 54 |
Paths can be used with pattern and multiple attribute read as well. In order to |
| 55 |
skip the extra value levels introduced by a pattern read, the wildcard |
| 56 |
<constant>*</constant> can be used. For example, a read request for the MBean Pattern |
| 57 |
<literal>java.lang:type=GarbageCollector,*</literal> for the Attribute <literal>LastGcInfo</literal> |
| 58 |
returns a complex structure holding information about the last garbage collection. If one is |
| 59 |
interested only for the duration of the garbage collection, a path <literal>used</literal> could be used if |
| 60 |
this request wouldn't be a pattern request (i.e. refers a specific, single MBean). But in this case since a |
| 61 |
nested map with MBean and Attribute names is returned, the path <literal>*/*/used</literal> has to be used |
| 62 |
in order to skip the two extra levels for applying the path. The two levels are returned nevertheless, though. |
| 63 |
Note that in the following example the final value is <emphasis>not</emphasis> the full GC-Info but only the |
| 64 |
value of its <literal>used</literal> entry: |
| 65 |
</para> |
| 66 |
<programlisting><![CDATA[ |
| 67 |
value: { |
| 68 |
"java.lang:name=PS MarkSweep,type=GarbageCollector": { |
| 69 |
LastGcInfo: null |
| 70 |
}, |
| 71 |
"java.lang:name=PS Scavenge,type=GarbageCollector": { |
| 72 |
LastGcInfo: 7 |
| 73 |
} |
| 74 |
}]]></programlisting> |
| 75 |
<para> |
| 76 |
The following rule of thumb applies: |
| 77 |
</para> |
| 78 |
<itemizedlist> |
| 79 |
<listitem> |
| 80 |
If a wildcard is used, everything at that point in the path is |
| 81 |
matched. The next path parts are used to match from there |
| 82 |
on. All the values on this level are included. |
| 83 |
</listitem> |
| 84 |
<listitem> |
| 85 |
Every other path part is literally compared against the values |
| 86 |
on that level. If there is a match, this value is |
| 87 |
<emphasis>removed</emphasis> in the answer so that at the end |
| 88 |
you get back a structure with the values on the wildcard levels |
| 89 |
and the leaves of the matched parts. |
| 90 |
</listitem> |
| 91 |
<listitem> |
| 92 |
If used with wildcards, paths behave also like |
| 93 |
filters. E.g. you can use a path <literal>*/*/used</literal> on |
| 94 |
the MBean pattern <literal>java.lang:*</literal> and get back |
| 95 |
only that portions which contains "used" as key, all others are |
| 96 |
ignored. |
| 97 |
</listitem> |
| 98 |
</itemizedlist> |
| 99 |
<section id="get-read"> |
| 100 |
<title>GET read request</title> |
| 101 |
<para> |
| 102 |
The GET URL for a read request has the following format: |
| 103 |
</para> |
| 104 |
<synopsis><![CDATA[<base-url>/read/<mbean name>/<attribute name>/<inner path>]]></synopsis> |
| 105 |
<table> |
| 106 |
<title>GET Read Request</title> |
| 107 |
<thead> |
| 108 |
<tr> |
| 109 |
<td>Part</td> |
| 110 |
<td>Description</td> |
| 111 |
<td>Example</td> |
| 112 |
</tr> |
| 113 |
</thead> |
| 114 |
<tr> |
| 115 |
<td><literal><mbean name></literal></td> |
| 116 |
<td> |
| 117 |
The <ulink |
| 118 |
url="http://download.oracle.com/javase/6/docs/api/javax/management/ObjectName.html">ObjectName</ulink> |
| 119 |
of the MBean for which the attribute should be fetched. It |
| 120 |
contains two parts: A domain part and a list of properties |
| 121 |
which are separated by <literal>:</literal>. Properties |
| 122 |
themselves are combined in a comma separated list of |
| 123 |
key-value pairs. This name can be a pattern in which case |
| 124 |
multiple MBeans are queried for the attribute value. |
| 125 |
</td> |
| 126 |
<td><literal>java.lang:type=Memory</literal></td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
<td><literal><attribute name></literal></td> |
| 130 |
<td>Name of attribute to read. This can be a list of Attribute |
| 131 |
names separated by comma. Slashes and exclamations marks need |
| 132 |
to be escaped as described in <xref |
| 133 |
linkend="escape-rules"/>. If no attribute is given, all |
| 134 |
attributes are read.</td> |
| 135 |
<td><literal>HeapMemoryUsage</literal></td> |
| 136 |
</tr> |
| 137 |
<tr> |
| 138 |
<td><literal><inner path></literal></td> |
| 139 |
<td> |
| 140 |
This optional part describes an <emphasis>inner |
| 141 |
path</emphasis> as described in <xref linkend="paths"/> |
| 142 |
</td> |
| 143 |
<td><literal>used</literal></td> |
| 144 |
</tr> |
| 145 |
</table> |
| 146 |
|
| 147 |
<para> |
| 148 |
With this URL the used heap memory can be obtained: |
| 149 |
<informalexample> |
| 150 |
<literallayout class="monospaced">http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage/used</literallayout> |
| 151 |
</informalexample> |
| 152 |
</para> |
| 153 |
</section> |
| 154 |
<section id="post-read"> |
| 155 |
<title>POST read request</title> |
| 156 |
<para> |
| 157 |
A the keys available for read POST requests are shown in the |
| 158 |
following table. |
| 159 |
</para> |
| 160 |
<table> |
| 161 |
<title>POST Read Request</title> |
| 162 |
<thead> |
| 163 |
<tr> |
| 164 |
<td>Key</td> |
| 165 |
<td>Description</td> |
| 166 |
<td>Example</td> |
| 167 |
</tr> |
| 168 |
</thead> |
| 169 |
<tr> |
| 170 |
<td><constant>type</constant></td> |
| 171 |
<td><emphasis role="bold">read</emphasis></td> |
| 172 |
<td/> |
| 173 |
</tr> |
| 174 |
<tr> |
| 175 |
<td><constant>mbean</constant></td> |
| 176 |
<td>MBean's ObjectName which can be a pattern</td> |
| 177 |
<td><literal>java.lang:type=Memory</literal></td> |
| 178 |
</tr> |
| 179 |
<tr> |
| 180 |
<td><constant>attribute</constant></td> |
| 181 |
<td>Attribute name to read or a JSON array containing a list |
| 182 |
of attributes to read. No attribute is given, then all attributes |
| 183 |
are read.</td> |
| 184 |
<td><literal>HeapMemoryUsage</literal>, <literal>[ |
| 185 |
"HeapMemoryUsage", "NonHeapMemoryUsage" ]</literal></td> |
| 186 |
</tr> |
| 187 |
<tr> |
| 188 |
<td><constant>path</constant></td> |
| 189 |
<td>Inner path for accessing the value of a complex value |
| 190 |
(<xref linkend="paths"/>)</td> |
| 191 |
<td><constant>used</constant></td> |
| 192 |
</tr> |
| 193 |
</table> |
| 194 |
<para> |
| 195 |
The following request fetches the number of active threads: |
| 196 |
</para> |
| 197 |
<programlisting><![CDATA[ |
| 198 |
{ |
| 199 |
"type":"read", |
| 200 |
"mbean":"java.lang:type=Threading", |
| 201 |
"attribute":"ThreadCount" |
| 202 |
}]]></programlisting> |
| 203 |
</section> |
| 204 |
<section id="response-read"> |
| 205 |
<title>Read response</title> |
| 206 |
<para> |
| 207 |
The general format of the JSON response is described in <xref |
| 208 |
linkend="responses"/> in detail. A typical response for an |
| 209 |
attribute read operation for an URL like |
| 210 |
<informalexample> |
| 211 |
<literallayout class="monospaced">http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage/</literallayout> |
| 212 |
</informalexample> |
| 213 |
looks like |
| 214 |
</para> |
| 215 |
<programlisting><![CDATA[ |
| 216 |
{ |
| 217 |
"value":{ |
| 218 |
"init":134217728, |
| 219 |
"max":532742144, |
| 220 |
"committed":133365760, |
| 221 |
"used":19046472 |
| 222 |
}, |
| 223 |
"status":200, |
| 224 |
"timestamp":1244839118, |
| 225 |
"request":{ |
| 226 |
"mbean":"java.lang:type=Memory", |
| 227 |
"type":"read", |
| 228 |
"attribute":"HeapMemoryUsage" |
| 229 |
}, |
| 230 |
"history":[{"value":{ |
| 231 |
"init":134217728, |
| 232 |
"max":532742144, |
| 233 |
"committed":133365760, |
| 234 |
"used":18958208 |
| 235 |
}, |
| 236 |
"timestamp":1244839045 |
| 237 |
}, .... |
| 238 |
] |
| 239 |
}]]></programlisting> |
| 240 |
<para> |
| 241 |
The <constant>value</constant> contains the response's |
| 242 |
value. For simple data types it is a scalar value, more complex |
| 243 |
types are serialized into a JSON object. See <xref |
| 244 |
linkend="serialization"/> for detail on object serialization. |
| 245 |
</para> |
| 246 |
<para> |
| 247 |
For a read request to a single MBean with multiple attributes, the |
| 248 |
returned value is a JSON object with the attribute names as keys |
| 249 |
and their values as values. For example a request to |
| 250 |
<literal>http://localhost:8080/jolokia/read/java.lang:type=Memory</literal> |
| 251 |
leads to |
| 252 |
</para> |
| 253 |
<informalexample> |
| 254 |
<programlisting><![CDATA[ |
| 255 |
{ |
| 256 |
"timestamp": 1317151518, |
| 257 |
"status": 200, |
| 258 |
"request": {"mbean":"java.lang:type=Memory","type":"read"}, |
| 259 |
"value":{ |
| 260 |
"Verbose": false, |
| 261 |
"ObjectPendingFinalizationCount": 0, |
| 262 |
"NonHeapMemoryUsage": {"max":136314880,"committed":26771456,"init":24317952,"used":15211720}, |
| 263 |
"HeapMemoryUsage": {"max":129957888,"committed":129957888,"init":0,"used":2880008} |
| 264 |
} |
| 265 |
}]]></programlisting> |
| 266 |
</informalexample> |
| 267 |
<para> |
| 268 |
A request to a MBean pattern returns as value a JSON object, |
| 269 |
with the MBean names as keys and as value another JSON object |
| 270 |
with the attribute name as keys and the attribute values as |
| 271 |
values. For example a request |
| 272 |
<literal>http://localhost:8080/jolokia/read/java.lang:type=*/HeapMemoryUsage</literal> |
| 273 |
returns something like |
| 274 |
</para> |
| 275 |
<informalexample> |
| 276 |
<programlisting><![CDATA[ |
| 277 |
{ |
| 278 |
"timestamp": 1317151980, |
| 279 |
"status": 200, |
| 280 |
"request": {"mbean":"java.lang:type=*","attribute":"HeapMemoryUsage","type":"read"}, |
| 281 |
"value": { |
| 282 |
"java.lang:type=Memory": { |
| 283 |
"HeapMemoryUsage": {"max":129957888,"committed":129957888,"init":0,"used":3080912} |
| 284 |
} |
| 285 |
} |
| 286 |
}]]> |
| 287 |
</programlisting> |
| 288 |
</informalexample> |
| 289 |
</section> |
| 290 |
</section> |