Can't JSON encode JMX object #1

Closed
technomancy opened this Issue Mar 28, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Contributor

technomancy commented Mar 28, 2012

I get this stack trace:

org.codehaus.jackson.JsonGenerationException: Cannot JSON encode object of class: class javax.management.ObjectName: java.lang:type=OperatingSystem
at ringmon.json$generate.invoke(json.clj:212)
at ringmon.json$generate.invoke(json.clj:179)
at ringmon.json$generate.invoke(json.clj:179)
at ringmon.json$generate.invoke(json.clj:179)
at ringmon.json$generate_string.doInvoke(json.clj:224)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at ringmon.monitor$ajax.invoke(monitor.clj:190)
at ringmon.monitor$wrap_ajax$fn__3400.invoke(monitor.clj:225)
at ringmon.monitor$wrap_gzip$fn__3377.invoke(monitor.clj:102)
at ringmon.cookies$noir_cookies$fn__2824.invoke(cookies.clj:39)
at ring.middleware.cookies$wrap_cookies$fn__2817.invoke(cookies.clj:150)
at ring.middleware.params$wrap_params$fn__2240.invoke(params.clj:76)
at ring.adapter.jetty$proxy_handler$fn__3517.invoke(jetty.clj:16)
at ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle(Unknown Source)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

Hi

Thanks for having a look at ringmon.
I have not experienced such an issue both on OS X and when deployed in a Heroku dyno.

In what context have you got this exception?
What happens if you run ringmon standalone within its project as:
lein2 :local-repl true ?

The only problem I used to have with JMX data was caused by a deficiency (in my opinion) within
the clojure/java.jmx as discussed here

That is why I excluded :AllThreadIds from "java.lang:type=Threading" mbean before
it was passed to JSON encoder. Conversion of JMX values for other JMX data that ringmon uses
always worked fine, both for clj-json and cheshire. The ringmon now has embedded cherry picked
cheshire 3.0.0 and depends on [org.codehaus.jackson/jackson-core-asl "1.5.0"]
I did it since I needed the cheshire to be able to parse project.clj, and the cheshire as packaged
(depends on much newer jackson) was then conflicting with noir 2.1 that uses clj-json that also
uses jackson 1.5.0 ...

Regards Zoka

technomancy added a commit to technomancy/ringMon that referenced this issue Mar 28, 2012

Contributor

technomancy commented Mar 29, 2012

I get this exception every few seconds when running ringmon on Debian with OpenJDK 7.

Owner

zoka commented Mar 29, 2012

Is it happening at a polling rate? ringmon has variable polling rate but it can be fixed to 2 seconds if it is run
in standalone mode as:

lein2 run :fast-poll 2000 :norm-poll 2000 :local-repl true

In REPL I get this:

(defn jmx-test
  []
  (require '[clojure.java.jmx :as jmx])
  (let [os   (jmx/mbean "java.lang:type=OperatingSystem")
        cpus (:AvailableProcessors os)]
    (println "JMX reports:" cpus "processors")
    (println "the type of 'os' is" (type os))
    (println "the type of 'AvailableProcessors' is" (type (:AvailableProcessors os)))))

(jmx-test)
ringmon.server=>#'ringmon.server/jmx-test
JMX reports: 4 processors
the type of 'os' is clojure.lang.PersistentHashMap
the type of 'AvailableProcessors' is java.lang.Integer
ringmon.server=>nil

This is the very same bean you were getting exceptions with.

Heroku environment (as you already know) is:

~ $ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.9) (6b20-1.9.9-0ubuntu1~10.04.2)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)

It is hard to imagine that OpenJDK 7 would be that incompatible.

Zoka

Contributor

technomancy commented Mar 29, 2012

Yeah, I can confirm that it happens at the polling rate.

@zoka zoka closed this in c71e46e Mar 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment