- import org.jolokia.client.*;
- import org.jolokia.client.request.*;
- import java.util.Map;
- public class JolokiaDemo {
- public static void main(String[] args) throws Exception {
- J4pClient j4pClient = new J4pClient("<a href="http://localhost:8080/jolokia">http://localhost:8080/jolokia");
- J4pReadRequest req = new J4pReadRequest("java.lang:type=Memory",
- "HeapMemoryUsage");
- J4pReadResponse resp = j4pClient.execute(req);
- Map<String,String> vals = resp.getValue();
- int used = Integer.parseInt(vals.get("used"));
- int max = Integer.parseInt(vals.get("max"));
- int usage = (int) (used * 100 / max);
- System.out.println("Memory usage: used: " + used +
- " / max: " + max + " = " + usage + "%");
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/171220121032.html
来源: http://www.codesnippet.cn/detail/171220121032.html