Javasimon Rest API for counters

61 views
Skip to first unread message

Isaac Hazan

unread,
Jan 14, 2015, 5:39:06 AM1/14/15
to java...@googlegroups.com
I followed the instructions at: https://code.google.com/p/javasimon/wiki/WebConsole
It worked fine for the console but what I need is a rest API for the Ops team.
The same page says that i can use the following URL to get via REST stats about my simons:

In the above:
  - What is "context"? Is it the web app context folder?
  - what is "path"?
  - what is "data"?

I tried the following but non of them worked although i can run the web console fine:

P.S: the reason there is no context in the above is because my application is in the root context.

Thx in advance

Richard Richter

unread,
Jan 14, 2015, 6:08:14 AM1/14/15
to java...@googlegroups.com
Hi Isaac

I don't know about other's experience with this REST API, primary goal
was to serve the console web application, but it probably is usable
for your goal as well.

Anyway:
- best way is to test it on something that works (with console) and
then use F12 in Firefox/Chrome (or other way to debug requests)
- from what I can see, running demo application, list generates these
requests: http://localhost:8080/console-filter/data/table.json?pattern=&type=STOPWATCH&type=COUNTER&timeFormat=MILLISECOND
- so first difference is - it is not list.json, but table.json (this
is bug in the documentation so it seems)
- demo app also has no "context" part, then "console-filter" is what
is configured url-prefix for SimonConsoleFilter
- data/table.json is fixed (or data/tree.json, not sure which is
better for your case)

BTW what version of Simon do you use?

Virgo
> --
> You received this message because you are subscribed to the Google Groups
> "javasimon" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to javasimon+...@googlegroups.com.
> To post to this group, send email to java...@googlegroups.com.
> Visit this group at http://groups.google.com/group/javasimon.
> For more options, visit https://groups.google.com/d/optout.

Isaac Hazan

unread,
Jan 14, 2015, 6:46:22 AM1/14/15
to java...@googlegroups.com
Thx for the prompt reply.
I am using javasimon 4.0.0.
When using the URL you are providing, i am not getting the relevant information but the following:

[1] 27387
[2] 27388
[3] 27389
[ec2-user@ip-172-31-14-176 bin]$ <!DOCTYPE html><html><head><title>Apache Tomcat/8.0.15 - Error report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 404 - </h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource is not available.</u></p><hr class="line"><h3>Apache Tomcat/8.0.15</h3></body></html>
[1]   Done                    curl -XGET http://localhost:8080/console-filter/data/table.json?pattern=
[2]-  Done                    type=STOPWATCH
[3]+  Done                    type=COUNTER

Are you getting a JSON result?

Richard Richter

unread,
Jan 14, 2015, 7:14:49 AM1/14/15
to java...@googlegroups.com
I definitely do get results, because that URL is taken from demo
application F12 network debug tab.

What is your web.xml configuration? Can you debug your application
(Tomcat should allow remote debug)? If so, put some breakpoints to
org.javasimon.console.SimonConsoleFilter#doFilter method, or better
yet into org.javasimon.console.SimonConsoleRequestProcessor#processRequest
(this is common code for both console filter or servlet, whatever you
use). That way you can determine whether your code at least gets there
(although 404 indicates it does not).

Also, don't forget to quote the URL on command line because of those &
(see [1] Done, [2] done... you ran some processes on the background
accidentally), although this probably doesn't cause 404 either.

Virgo

Isaac Hazan

unread,
Jan 14, 2015, 8:41:32 AM1/14/15
to java...@googlegroups.com
Thx.
You're right about the double quotes but that didn't help when i put them.
My web.xml:
<servlet>
<servlet-name>SimonConsoleServlet</servlet-name>
<servlet-class>org.javasimon.console.SimonConsoleServlet</servlet-class>
<init-param>
<param-name>url-prefix</param-name>
<param-value>/javasimon-console</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SimonConsoleServlet</servlet-name>
<url-pattern>/javasimon-console/*</url-pattern>
</servlet-mapping>

Debugging is a bit more difficult in my case because the application is on amazon with restricting firewall rules.

Thx

Richard Richter

unread,
Jan 14, 2015, 8:52:00 AM1/14/15
to java...@googlegroups.com
Did you try "javasimon-console" instead of "console-filter" in the
URL? That seems to be the difference in your configuration and our
demo application:
https://github.com/virgo47/javasimon/blob/master/demoapp/src/main/webapp/WEB-INF/web.xml

If this doesn't help I'm afraid you will have to try it locally so you
can debug, but javasimon-console string (what is configured as
url-prefix and also url-pattern for servlet) must appear somewhere in
the URL.

Virgo

Gérald Quintana

unread,
Jan 14, 2015, 8:56:26 AM1/14/15
to java...@googlegroups.com
Hi Isaac,

In the URL "http://host:port/context/simon/path/data/list.json" the "data/list.json" is the only fixed/hardcoded part of the URL.
The "context" depends on your web server configuration. Usually it matches the War file name, if you deploy the console as simon-console.war, the context is "simon-console" by default. For Tomcat, the "context" can be configured in a "context.xml" file (read http://tomcat.apache.org/tomcat-8.0-doc/config/context.html).
The "simon/path" part depends on where the Simon Console Servlet or Filter has been plugged, it should be described in your web.xml

Gérald

Isaac Hazan

unread,
Jan 14, 2015, 9:26:32 AM1/14/15
to java...@googlegroups.com
Great!! That works!!! Thx for your patience.
Now i can ask the real questions :-)
Is there a rest API for a single counter so that Ops can put nagios and poll for counters until threshold is hit?
Since now the JSON i am getting is not very pretty it is not even newlines for each counter(although i could give it to a bash script easily.

Thx

Isaac Hazan

unread,
Jan 14, 2015, 9:35:16 AM1/14/15
to java...@googlegroups.com
Ok, i found how to do that by debugging with f12 on chrome as you suggested. Thx for all the help provided.


Reply all
Reply to author
Forward
0 new messages