Using curl

We can of course use any HTTP client to access Jolokia agent. One of the most popular and powerful tools is the curl command.

We can access the agent with simple GET requests:

$ curl -s -u \
jolokia:jolokia http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage | jq .
{
  "request": {
    "mbean": "java.lang:type=Memory",
    "attribute": "HeapMemoryUsage",
    "type": "read"
  },
  "value": {
    "init": 524288000,
    "committed": 532676608,
    "max": 8334082048,
    "used": 53842272
  },
  "status": 200,
  "timestamp": 1701866205
}

but it’s also easy to send POST requests for example:

$ curl -s -u jolokia:jolokia \
-H'Content-Type: application/json' \
-XPOST -d '{"mbean":"java.lang:type=Memory","attribute":"HeapMemoryUsage","type":"read"}' \
http://localhost:8080/jolokia | jq .
{
  "request": {
    "mbean": "java.lang:type=Memory",
    "attribute": "HeapMemoryUsage",
    "type": "read"
  },
  "value": {
    "init": 524288000,
    "committed": 532676608,
    "max": 8334082048,
    "used": 53842272
  },
  "status": 200,
  "timestamp": 1701866282
}