Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jolokia plugin: POST requests need configuration documentation #1834

Closed
winstonsimon opened this issue Oct 1, 2016 · 8 comments
Closed

Jolokia plugin: POST requests need configuration documentation #1834

winstonsimon opened this issue Oct 1, 2016 · 8 comments
Labels
help wanted Request for community participation, code, contribution

Comments

@winstonsimon
Copy link

Bug report

Relevant telegraf.conf:

# Global tags can be specified here in key="value" format.
[global_tags]


# Configuration for telegraf agent
[agent]
  ## Default data collection interval for all inputs
  interval = "10s"
  ## Rounds collection interval to 'interval'
  ## ie, if interval="10s" then always collect on :00, :10, :20, etc.
  round_interval = true

  ## Telegraf will send metrics to outputs in batches of at
  ## most metric_batch_size metrics.
  metric_batch_size = 1000
  ## For failed writes, telegraf will cache metric_buffer_limit metrics for each
  ## output, and will flush this buffer on a successful write. Oldest metrics
  ## are dropped first when this buffer fills.
  metric_buffer_limit = 10000

  collection_jitter = "0s"

  flush_interval = "10s"
  flush_jitter = "0s"

  ## Valid values are "ns", "us" (or "µs"), "ms", "s".
  precision = ""
  ## Run telegraf in debug mode
  debug = true
  ## Run telegraf in quiet mode
  quiet = false
  ## Override default hostname, if empty use os.Hostname()
  hostname = ""
  ## If set to true, do no set the "host" tag in the telegraf agent.
  omit_hostname = false

# # Read JMX metrics through Jolokia
 [[inputs.jolokia]]
#   ## This is the context root used to compose the jolokia url
   context = "/jolokia"
#
#   ## This specifies the mode used
#   # mode = "proxy"
#   #
#   ## When in proxy mode this section is used to specify further
#   ## proxy address configurations.
#   ## Remember to change host address to fit your environment.
#    [inputs.jolokia.proxy]
#      host = "127.0.0.1"
#      port = "8778"
#
#
#   ## List of servers exposing jolokia read service
   [[inputs.jolokia.servers]]
     name = "as-server-01"
     host = "localhost"
     port = "8778"
#     # username = "myuser"
#     # password = "mypassword"
#
#   ## List of metrics collected on above servers
#   ## Each metric consists in a name, a jmx path and either
#   ## a pass or drop slice attribute.
#   ## This collect all heap memory usage metrics.
   [[inputs.jolokia.metrics]]
     name = "heap_memory_usage"
     mbean  = "java.lang:type=Memory"
     attribute = "HeapMemoryUsage"
#
#   ## This collect thread counts metrics.
#   [[inputs.jolokia.metrics]]
#     name = "thread_count"
#     mbean  = "java.lang:type=Threading"
#     attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
#
#   ## This collect number of class loaded/unloaded counts metrics.
#   [[inputs.jolokia.metrics]]
#     name = "class_count"
#     mbean  = "java.lang:type=ClassLoading"
#     attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"

System info:

Red Hat Enterprise Linux Server release 6.8 (Santiago)
Telegraf - version 1.0.0
Jolokia - version 1.3.4

Steps to reproduce:

  1. Attach jolokia to java process
java -jar  jolokia-1.3.4/agents/jolokia-jvm.jar start 12905
Started Jolokia for PID 12905
http://127.0.0.1:8778/jolokia/
  1. curl http://localhost:8778/jolokia/read/java.lang:type=Memory/HeapMemoryUsage
{"request":{"mbean":"java.lang:type=Memory","attribute":"HeapMemoryUsage","type":"read"},"value":{"init":4294967296,"committed":4294967296,"max":4294967296,"used":144469880},"timestamp":1475288111,"status":200}

Expected behavior:

As per doc, I should see 200 response from the telegraf while calling jolokia endpoint.

Actual behavior:

Error handling response: Response from url "" has status code 404 (Not Found), expected 200 (OK)

Appreciate if you could help us to address this issue.

@winstonsimon winstonsimon changed the title telegraf jolokia plugin returing 404 Telegraf Jolokia plugin returning 404 status code Oct 1, 2016
@sparrc
Copy link
Contributor

sparrc commented Oct 2, 2016

could you try setting context = /jolokia/read?

@sparrc
Copy link
Contributor

sparrc commented Oct 2, 2016

Also the telegraf plugin sends a POST request to jolokia, so try

curl -XPOST http://localhost:8778/jolokia/read/java.lang:type=Memory/HeapMemoryUsage

or you may need to send the read request as data in the POST:

curl -H "Content-Type: application/json" -X POST -d '{"type": "read", "mbean": "java.lang:type=Memory"}' http://localhost:8778/jolokia

@winstonsimon
Copy link
Author

I'm getting following error while posting:

-bash-4.1$ curl -H "Content-Type: application/json" -X POST -d '{"type": "read", "mbean": "java.lang:type=Memory"}' http://localhost:8778/jolokia
<h1>404 Not Found</h1>No context found for request-bash-4.1$ 
-bash-4.1$ 
-bash-4.1$ 
-bash-4.1$ curl -XPOST http://localhost:8778/jolokia/read/java.lang:type=Memory/HeapMemoryUsage
{"stacktrace":"java.lang.IllegalArgumentException: Invalid JSON request java.io.InputStreamReader@23040e0b\n\tat org.jolokia.http.HttpRequestHandler.extractJsonRequest(HttpRequestHandler.java:181)\n\tat org.jolokia.http.HttpRequestHandler.handlePostRequest(HttpRequestHandler.java:121)\n\tat org.jolokia.jvmagent.handler.JolokiaHttpHandler.executePostRequest(JolokiaHttpHandler.java:270)\n\tat org.jolokia.jvmagent.handler.JolokiaHttpHandler.doHandle(JolokiaHttpHandler.java:224)\n\tat org.jolokia.jvmagent.handler.JolokiaHttpHandler.handle(JolokiaHttpHandler.java:169)\n\tat com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)\n\tat sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)\n\tat com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)\n\tat sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)\n\tat com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)\n\tat sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\nCaused by: Unexpected token END OF FILE at position 0.\n\tat org.json.simple.parser.JSONParser.parse(JSONParser.java:257)\n\tat org.json.simple.parser.JSONParser.parse(JSONParser.java:92)\n\tat org.jolokia.http.HttpRequestHandler.extractJsonRequest(HttpRequestHandler.java:179)\n\t... 13 more\n","error_type":"java.lang.IllegalArgumentException","error":"java.lang.IllegalArgumentException : Invalid JSON request java.io.InputStreamReader@23040e0b","status":400}
-bash-4.1$

Is this jolokia configuration issue? Do you have any latest example that I can use to configure jolokia or to get Jvm stats?

@sparrc
Copy link
Contributor

sparrc commented Oct 3, 2016

your Jolokia instance needs to support POST requests. I'm not very familiar with Jolokia configuration but the best I can do is point you towards this: https://jolokia.org/reference/html/protocol.html#request-response

I'm going to change this to a documentation issue because this has been a source of confusion for other users as well.

@sparrc sparrc changed the title Telegraf Jolokia plugin returning 404 status code Jolokia plugin: POST requests need configuration documentation Oct 3, 2016
@sparrc
Copy link
Contributor

sparrc commented Oct 3, 2016

The Jolokia plugin documentation needs to be updated to inform users that their Jolokia endpoint must support POST requests.

This should be both in the sample configuration and in the README. The README should also give a few curl examples to test connectivity and debug.

@saiello Since you made this change to use POST requests, and know more about Jolokia configuration than I do, I'd appreciate it a lot if you could update the documentation.

@sparrc sparrc added the help wanted Request for community participation, code, contribution label Oct 3, 2016
@saiello
Copy link
Contributor

saiello commented Oct 4, 2016

@sparrc using POST requests allow to switch to 'proxy' mode in a easier way ( code is the same). Maybe along with the documentation improvement it would be better(nicer) specify whether to work in GET or POST. I'll check

@sparrc
Copy link
Contributor

sparrc commented Oct 6, 2016

@saiello I would prefer if we did POST requests only. The problem is just that we don't have it documented so it can be quite confusing to new users.

@dgnorton dgnorton added this to the Future Milestone milestone Oct 6, 2016
@sparrc
Copy link
Contributor

sparrc commented Feb 3, 2017

I'm not really sure what the issue is here so I'm going to close this. If someone wants to submit a PR to improve the documentation they're welcome to do it.

@sparrc sparrc closed this as completed Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Request for community participation, code, contribution
Projects
None yet
Development

No branches or pull requests

4 participants