influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.19k stars 5.52k forks source link

Adding option to invoke operations in jolokia2 agent #5278

Open aimtsou opened 5 years ago

aimtsou commented 5 years ago

Feature Request

Besides reading attributes the jolokia2 agent should be able to invoke operations from custom Mbeans through the JMX.

Proposal:

We would like to see operations to be captured from invoked actions

Current behavior:

Current behaviour supports only read requests and attributes ie: curl http://localhost:10012/jolokia/read/java.lang:type=Memory | python -m json.tool

Desired behavior:

I would like to have also operations supported for custom Mbeans(for our applications) created in Spring.boot. An example is: http://localhost:10162/jolokia/exec/org.springframework.boot:type=Endpoint,name=Health/health/ | python -m json.tool While I can see the result in command line I cannot capture it with telegraf

lurodrig commented 5 years ago

:+1:

danielnelson commented 5 years ago

Related link for implementing https://jolokia.org/reference/html/protocol.html#exec

sspaink commented 2 years ago

@aimtsou sorry this hasn't been implemented yet, are you still interested in this feature?

aimtsou commented 2 years ago

Hi @sspaink,

Thank you for coming back, yes I am still interested to have it if possible.

srebhan commented 4 months ago

@aimtsou what is the format of the response? Is this something that follows a general layout or is this different for each individual operation?

aimtsou commented 3 months ago

Good afternoon,

Although I do not have access anymore to the apps since I have changed job for this feature I would say we follow a general layout.

srebhan commented 3 months ago

@aimtsou thanks for reaching out! I'm not sure how that "general layout" looks like! For the current queries, the responses follow a known pattern and thus we can easily parse the response into a metric. Do the operations also follow the same pattern/structure in their response?

aimtsou commented 3 months ago

Hi @srebhan, I knew you would ask that :D

So my idea is to have something custom but well defined. For example, we will have a custom endpoint and the metric from the MBean it should have a format:

ie: http://localhost:10162/jolokia/exec/org.springframework.boot:type=Endpoint,name=Health/health/ | python -m json.tool For that custom MBean I would expect either:

Consequently, you will run the MBean over all the custom layouts, which should most probably be a boolean, one numeric we could output long and maybe one as a string, if someone wants to display something as a table. Extra would be all of them to have an extra description field.

If you have any examples of the pattern we can elaborate more.

srebhan commented 1 month ago

Can you please provide one or two (redacted) examples of responses?

piotrp commented 1 month ago

API docs: https://jolokia.org/reference/html/manual/protocol/exec.html

Response headers when using curl:

< HTTP/1.1 200 OK
< Pragma: no-cache
< Date: Mon, 17 Jun 2024 20:04:15 GMT
< Transfer-encoding: chunked
< Content-type: text/plain; charset=utf-8
< Expires: Mon, 17 Jun 2024 19:04:15 GMT
< Cache-control: no-cache

(JSON response but with "text/plain" Content-Type)

Empty (null) response:

{
  "request": {
    "mbean": "my.org.name:name=inbound",
    "type": "exec",
    "operation": "healthCheck"
  },
  "value": null,
  "timestamp": 1718654655,
  "status": 200
}

Simple response (http://localhost:8989/jolokia/exec/java.lang:type=Threading/getThreadCpuTime(long)/2):

{
  "request": {
    "mbean": "java.lang:type=Threading",
    "arguments": [
      "2"
    ],
    "type": "exec",
    "operation": "getThreadCpuTime(long)"
  },
  "value": 88297297,
  "timestamp": 1718655650,
  "status": 200
}

Complex response (http://localhost:8989/jolokia/exec/java.lang:type=Threading/getThreadInfo(long)/2):

{
  "request": {
    "mbean": "java.lang:type=Threading",
    "arguments": [
      "2"
    ],
    "type": "exec",
    "operation": "getThreadInfo(long)"
  },
  "value": {
    "waitedCount": 0,
    "lockOwnerId": -1,
    "lockedMonitors": [],
    "waitedTime": -1,
    "blockedCount": 2,
    "threadState": "RUNNABLE",
    "inNative": false,
    "priority": 10,
    "suspended": false,
    "threadName": "Reference Handler",
    "daemon": true,
    "lockInfo": null,
    "threadId": 2,
    "stackTrace": [],
    "blockedTime": -1,
    "lockName": null,
    "lockOwnerName": null,
    "lockedSynchronizers": []
  },
  "timestamp": 1718655489,
  "status": 200
}

It can also return arrays, e.g. "value": [1,2,3].

Error (http://localhost:8989/jolokia/exec/java.lang:type=Threading/getThreadUserTime), returned as "HTTP/1.1 200 OK":

{
  "request": {
    "mbean": "java.lang:type=Threading",
    "type": "exec",
    "operation": "getThreadUserTime"
  },
  "stacktrace": "java.lang.IllegalArgumentException: Operation getThreadUserTime on MBean java.lang:type=Threading is overloaded. Signatures found: ([J),(long). Use a signature when specifying the operation.\n\tat org.jolokia.handler.ExecHandler.extractOperationTypes(ExecHandler.java:139)\n\tat org.jolokia.handler.ExecHandler.doHandleRequest(ExecHandler.java:84)\n\tat org.jolokia.handler.ExecHandler.doHandleRequest(ExecHandler.java:40)\n\tat org.jolokia.handler.JsonRequestHandler.handleRequest(JsonRequestHandler.java:89)\n\tat org.jolokia.backend.MBeanServerExecutorLocal.handleRequest(MBeanServerExecutorLocal.java:109)\n\tat org.jolokia.backend.MBeanServerHandler.dispatchRequest(MBeanServerHandler.java:161)\n\tat org.jolokia.backend.LocalRequestDispatcher.dispatchRequest(LocalRequestDispatcher.java:99)\n\tat org.jolokia.backend.BackendManager.callRequestDispatcher(BackendManager.java:429)\n\tat org.jolokia.backend.BackendManager.handleRequest(BackendManager.java:158)\n\tat org.jolokia.http.HttpRequestHandler.executeRequest(HttpRequestHandler.java:197)\n\tat org.jolokia.http.HttpRequestHandler.handleGetRequest(HttpRequestHandler.java:86)\n\tat org.jolokia.jvmagent.handler.JolokiaHttpHandler.executeGetRequest(JolokiaHttpHandler.java:278)\n\tat org.jolokia.jvmagent.handler.JolokiaHttpHandler.doHandle(JolokiaHttpHandler.java:235)\n\tat org.jolokia.jvmagent.handler.JolokiaHttpHandler.handle(JolokiaHttpHandler.java:180)\n\tat jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)\n\tat jdk.httpserver/sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:82)\n\tat jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)\n\tat jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:692)\n\tat jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)\n\tat jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:664)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\n",
  "error_type": "java.lang.IllegalArgumentException",
  "error": "java.lang.IllegalArgumentException : Operation getThreadUserTime on MBean java.lang:type=Threading is overloaded. Signatures found: ([J),(long). Use a signature when specifying the operation.",
  "status": 400
}