# Metricbeat jolokia module: "Cannot unmarshal json response"

**URL:** <https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [June 16, 2017, 3:55pm UTC](https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744 "2017-06-16T15:55:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregbk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregbk/32/80289_2.png) [@gregbk](https://discuss.elastic.co/u/gregbk)\
**Post date:** [June 16, 2017, 3:55pm UTC](https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744/1 "2017-06-16T15:55:29Z")

</div>

Hello Beats team!

I am trying the Jolokia module on 2 different jmx env.

I got for both the same error message in kibana:  
`Cannot unmarshal json response: invalid character '\x00' looking for beginning of value`

I use that docker to simulate a jmx:

```auto
FROM java:8
MAINTAINER "Alexei Novikov <alexeinov@gmail.com>"
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Hammer.java
CMD ["java", \
"-Dcom.sun.management.jmxremote", \
"-Dcom.sun.management.jmxremote.port=9010", \
# Uncomment this line when running JMX console on a different host
#"-Dcom.sun.management.jmxremote.rmi.port=9010", \
"-Dcom.sun.management.jmxremote.local.only=false", \
"-Dcom.sun.management.jmxremote.authenticate=false", \
"-Dcom.sun.management.jmxremote.ssl=false", \
# Uncomment this line when running JMX console on a different host, use a name of the host where Docker is running
#"-Djava.rmi.server.hostname=192.168.0.101", \
"Hammer"]
EXPOSE 9010

```

And this minimum metricbeat conf:

```auto
metricbeat.modules:

- module: jolokia
  metricsets: ["jmx"]
  enabled: true
  period: 1s
  hosts: ["jmx:9010"]
  namespace: "metrics"
  #path: "/jolokia/?ignoreErrors=true&canonicalNaming=true"
  jmx.mappings:
    - mbean: 'java.lang:type=Runtime'
      attributes:
        - attr: Uptime
          field: uptime

```

Event is send and coming to the right index  
`fetches.jolokia-jmx.events=30 fetches.jolokia-jmx.failures=30`

but with error: `Cannot unmarshal json response: invalid character '\x00' looking for beginning of value`

I am on 5.4.1 for elk+metricbeat.  
On a totally different jmx server in another env, I got the same error. Probably my metricbeat/(es template?) is missing something...  
I tried to send to logstash and directly to es: same result.

Similar to [Metricbeat 5.4.0 Jolokia module](https://discuss.elastic.co/t/metricbeat-5-4-0-jolokia-module/86319)

Thank you for your help & good weekend!  
Greg.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [June 16, 2017, 4:31pm UTC](https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744/2 "2017-06-16T16:31:57Z")

</div>

If I understand your setup correctly, you are trying to communicate directly to the JMX endpoint in the JVM. Metricbeat needs to communicate to the [Jolokia](https://jolokia.org/reference/html/index.html) REST endpoint. Jolokia acts as a bridge between Metricbeat and JMX and exposes a HTTP/REST/JSON interface to JMX.

---

<div class="post-metadata">

**Author:** ![joshuaclark](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@joshuaclark](https://discuss.elastic.co/u/joshuaclark)\
**Post date:** [June 16, 2017, 4:39pm UTC](https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744/3 "2017-06-16T16:39:35Z")

</div>

You need to follow the steps from this document [https://jolokia.org/reference/html/agents.html#agents-jvm](https://jolokia.org/reference/html/agents.html#agents-jvm) 3.4.1.1. Installation section. then set metricbeat to connect to the JVM host and the port you set for the Jolokia agent. You then would be able to connect to [http://host:7777/jolokia/read/java.lang:name=PS%20Scavenge,type=GarbageCollector](http://host:7777/jolokia/read/java.lang:name=PS%20Scavenge,type=GarbageCollector) etc.

---

<div class="post-metadata">

**Author:** ![gregbk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregbk/32/80289_2.png) [@gregbk](https://discuss.elastic.co/u/gregbk)\
**Post date:** [June 19, 2017, 1:09pm UTC](https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744/4 "2017-06-19T13:09:42Z")

</div>

Thanks a lot both!  
Yes, I had in mind that I needed to connect to jmx only while jolokia agent only can be understood by metricbeat...

Here is the right setup:

```auto
FROM java:8
MAINTAINER "Alexei Novikov <alexeinov@gmail.com>"
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Hammer.java

ENV JOLOKIA_VERSION 1.3.1
RUN mkdir /opt/jolokia && wget http://central.maven.org/maven2/org/jolokia/jolokia-jvm/1.3.1/jolokia-jvm-1.3.1-agent.jar -O /opt/jolokia/jolokia.jar

# Print out the version
RUN java -jar /opt/jolokia/jolokia.jar --version

CMD ["java", \
"-javaagent:/opt/jolokia/jolokia.jar=port=8778,host=0.0.0.0", \
"-Dcom.sun.management.jmxremote", \
"-Dcom.sun.management.jmxremote.port=9010", \
# Uncomment this line when running JMX console on a different host
#"-Dcom.sun.management.jmxremote.rmi.port=9010", \
"-Dcom.sun.management.jmxremote.local.only=false", \
"-Dcom.sun.management.jmxremote.authenticate=false", \
"-Dcom.sun.management.jmxremote.ssl=false", \
# Uncomment this line when running JMX console on a different host, use a name of the host where Docker is running
#"-Djava.rmi.server.hostname=192.168.0.101", \
"Hammer"]
EXPOSE 9010 8778

```

```auto
- module: jolokia
  metricsets: ["jmx"]
  enabled: true
  period: 1s
  hosts: ["jmx:8778"]
  namespace: "metrics"
  path: "/jolokia/?ignoreErrors=true&canonicalNaming=true"
  jmx.mappings:
    - mbean: 'java.lang:type=ClassLoading'
      attributes:
        - attr: LoadedClassCount
          field: loaded_class_count
    - mbean: 'java.lang:name=PS Scavenge,type=GarbageCollector'
      attributes:
        - attr: CollectionTime
          field: gc.collection_time
        - attr: CollectionCount
          field: gc.collection_count
    - mbean: 'java.lang:type=Memory'
      attributes:
        - attr: HeapMemoryUsage
          field: heap_memory_usage
        - attr: NonHeapMemoryUsage
          field: non_heap_memory_usage
    - mbean: 'java.lang:type=OperatingSystem'
      attributes:
        - attr: ProcessCpuLoad
          field: process_cpu_load
    - mbean: 'java.lang:type=Runtime'
      attributes:
        - attr: Uptime
          field: uptime
    - mbean: 'java.lang:type=Threading'
      attributes:
        - attr: ThreadCount
          field: thread_count

```

Thx!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 17, 2017, 1:09pm UTC](https://discuss.elastic.co/t/metricbeat-jolokia-module-cannot-unmarshal-json-response/89744/5 "2017-07-17T13:09:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
