Using Websocket for servers monitoring application

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using Websocket for servers monitoring application

ltribolet
Hi,

Here an exemple that I would want to make : a web page html which will display e.g. CPU or/and RAM ressources of several servers.

So I thought doing my application like this : one server using Jmxtrans or something like this which will POST on an Atmoshere's server which will redirect the information to the client.

Since the design of applications in the Atmosphere samples are like this :

    1. User post some data
    2. Server receives data
    3. Server resend data
    4. users receive data

Here this would be more like this :

    1. Server sends data
    2. users receive data

That's why I thought using a daemon like jmxtrans to send data as the only user who will be able to POST. But I'm not sure if there is a prettier way to do this.

Otherwise if I want the Atmosphere server to send the data by itself how do I tell him he has to send the data , regardless the method used (websocket, long pulling, etc) like in the pubsub sample ? I have to call an overrided AtmosphereServlet class in my application and use a modified onMessage() method ?

Do you have some pieces of advice ?

Regards,

Luc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using Websocket for servers monitoring application

java.net
I'm not sure if I understand your question, but sending data to the active clients is done by using the Broadcaster.

Pierre


On Wed, Jul 20, 2011 at 3:35 PM, ltribolet <[hidden email]> wrote:
Hi,

Here an exemple that I would want to make : a web page html which will
display e.g. CPU or/and RAM ressources of several servers.

So I thought doing my application like this : one server using
http://code.google.com/p/jmxtrans/ Jmxtrans  or something like this which
will POST on an Atmoshere's server which will redirect the information to
the client.

Since the design of applications in the Atmosphere samples are like this :

   1. User post some data
   2. Server receives data
   3. Server resend data
   4. users receive data

Here this would be more like this :

   1. Server sends data
   2. users receive data

That's why I thought using a daemon like jmxtrans to send data as the only
user who will be able to POST. But I'm not sure if there is a prettier way
to do this.

Otherwise if I want the Atmosphere server to send the data by itself how do
I tell him he has to send the data , regardless the method used (websocket,
long pulling, etc) like in the pubsub sample ? I have to call an overrided
AtmosphereServlet class in my application and use a modified onMessage()
method ?

Do you have some pieces of advice ?

Regards,

Luc

--
View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Using-Websocket-for-servers-monitoring-application-tp6602680p6602680.html
Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using Websocket for servers monitoring application

Cunha
In reply to this post by ltribolet
Hi Luc,

I think I understand what you asked.. So you got two servers, one running jmxtrans and another running atmosphere. Jmstrans server will post results periodically to the atmosphere server by POST on a specific topic, following a pub/sub model where the subscribed clients will received notifications, right? Your approach definitely works... but is it a requirement to have two isolated servers? If yes.... I personally don't like two java servers communicating via HTTP Post,  you could use several technologies, like JMS, where the atmosphere server hosts a jms Queue and the jmxtrans can lookup that queue and publish your monitorization. Ofc this depends on what application server you are using, and how much complexity you are willing to accept. 

But if you can have mix the jmxtrans and atmosphere into one single server, it would be the cleanest way... since you would only have to lookup the topic broadcaster using the BroadcasterFactory (jmxtrans module classloader must have visibility to the atmosphere module).

I hope I answer your question.

Regards,
Cunha

On Wed, Jul 20, 2011 at 2:35 PM, ltribolet <[hidden email]> wrote:
Hi,

Here an exemple that I would want to make : a web page html which will
display e.g. CPU or/and RAM ressources of several servers.

So I thought doing my application like this : one server using
http://code.google.com/p/jmxtrans/ Jmxtrans  or something like this which
will POST on an Atmoshere's server which will redirect the information to
the client.

Since the design of applications in the Atmosphere samples are like this :

   1. User post some data
   2. Server receives data
   3. Server resend data
   4. users receive data

Here this would be more like this :

   1. Server sends data
   2. users receive data

That's why I thought using a daemon like jmxtrans to send data as the only
user who will be able to POST. But I'm not sure if there is a prettier way
to do this.

Otherwise if I want the Atmosphere server to send the data by itself how do
I tell him he has to send the data , regardless the method used (websocket,
long pulling, etc) like in the pubsub sample ? I have to call an overrided
AtmosphereServlet class in my application and use a modified onMessage()
method ?

Do you have some pieces of advice ?

Regards,

Luc

--
View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Using-Websocket-for-servers-monitoring-application-tp6602680p6602680.html
Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using Websocket for servers monitoring application

ltribolet
Hi,

Sorry for late reply. Thanks to the two of you for replying me.

Cunha has understood very well what I meant. However since last time I've modified a bit my method.

Now I have one server Collectd which collects data from other servers. It collects data from my JVM with JMX and MBeans.

By using the pubsub model, Collectd sends Json data over my Atmosphere application with HTTP Post and Atmosphere will send data to all users connected.

But the Post data has no form param and it's pure Json so I've modified the JQueryPubSub class like this :

wrote
@Path("/{topic}")
@Produces("text/html;charset=ISO-8859-1")
public class JQueryPubSub {

    private @PathParam("topic") Broadcaster topic;

    @GET
    public SuspendResponse<String> subscribe() {
        return new SuspendResponse.SuspendResponseBuilder<String>()
                .broadcaster(topic)
                .outputComments(true)
                .addListener(new EventsLogger())
                .build();
    }

    @POST
    @Consumes("application/json")
    public void postReception(@Context HttpServletRequest request, @Context HttpServletResponse response)
        throws IOException, ServletException {
               
                InputStream body = request.getInputStream();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                while (body.available() > 0) {
                        baos.write(body.read());
                }
               
                String texte = new String(baos.toByteArray());
                     
                publish(texte);

        }
   
   
   
    @Broadcast
    public Broadcastable publish(String message) {
        return new Broadcastable(message, "" , topic);
    }
}
And my jQuery script is like this :

wrote
$(document).ready(function() {
    var connectedEndpoint;
    var callbackAdded = false;
    var detectedTransport = null;


    function getElementById() {
        return document.getElementById(arguments[0]);
    }

    function getTransport(t) {
        transport = t.options[t.selectedIndex].value;
        if (transport == 'autodetect') {
            transport = 'websocket';
        }

        return false;
    }

    function subscribe() {
        // jquery.atmosphere.response
        function callback(response) {
            // Websocket events.
            $.atmosphere.log('info', ["response.state: " + response.state]);
            $.atmosphere.log('info', ["response.transport: " + response.transport]);
                       
            detectedTransport = response.transport;
            if (response.transport != 'polling' && response.state != 'connected' && response.state != 'closed') {
                $.atmosphere.log('info', ["response.responseBody: " + response.responseBody]);
                                $.atmosphere.log('info', ["response.responseStatus: " + response.status]);
                if (response.status == 200) {
                    var data = response.responseBody;
                                        alert(data);
                    if (data.length > 0) {
                        $('ul').prepend($('<li></li>').text(data));
                    }
                }
            }
        }

        var location = document.location.toString() + 'Collectd/test';
        $.atmosphere.subscribe(location, !callbackAdded ? callback : null,
                $.atmosphere.request = { transport: "websocket" });
        connectedEndpoint = $.atmosphere.response;
        callbackAdded = true;
    }

        subscribe();
});
I made auto connection to the server via GET method which is working good.
I can see the Json data coming when I run in debug mode but the clients in web browser receives nothing.

So here I am so far.

Regards,

Luc


Cunha wrote
Hi Luc,

I think I understand what you asked.. So you got two servers, one running
jmxtrans and another running atmosphere. Jmstrans server will post results
periodically to the atmosphere server by POST on a specific topic, following
a pub/sub model where the subscribed clients will received notifications,
right? Your approach definitely works... but is it a requirement to have two
isolated servers? If yes.... I personally don't like two java servers
communicating via HTTP Post,  you could use several technologies, like JMS,
where the atmosphere server hosts a jms Queue and the jmxtrans can lookup
that queue and publish your monitorization. Ofc this depends on what
application server you are using, and how much complexity you are willing to
accept.

But if you can have mix the jmxtrans and atmosphere into one single server,
it would be the cleanest way... since you would only have to lookup the
topic broadcaster using the BroadcasterFactory (jmxtrans module classloader
must have visibility to the atmosphere module).

I hope I answer your question.

Regards,
Cunha

On Wed, Jul 20, 2011 at 2:35 PM, ltribolet <[hidden email]> wrote:

> Hi,
>
> Here an exemple that I would want to make : a web page html which will
> display e.g. CPU or/and RAM ressources of several servers.
>
> So I thought doing my application like this : one server using
> http://code.google.com/p/jmxtrans/ Jmxtrans  or something like this which
> will POST on an Atmoshere's server which will redirect the information to
> the client.
>
> Since the design of applications in the Atmosphere samples are like this :
>
>    1. User post some data
>    2. Server receives data
>    3. Server resend data
>    4. users receive data
>
> Here this would be more like this :
>
>    1. Server sends data
>    2. users receive data
>
> That's why I thought using a daemon like jmxtrans to send data as the only
> user who will be able to POST. But I'm not sure if there is a prettier way
> to do this.
>
> Otherwise if I want the Atmosphere server to send the data by itself how do
> I tell him he has to send the data , regardless the method used (websocket,
> long pulling, etc) like in the pubsub sample ? I have to call an overrided
> AtmosphereServlet class in my application and use a modified onMessage()
> method ?
>
> Do you have some pieces of advice ?
>
> Regards,
>
> Luc
>
> --
> View this message in context:
> http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Using-Websocket-for-servers-monitoring-application-tp6602680p6602680.html
> Sent from the Atmosphere users mailling list mailing list archive at
> Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using Websocket for servers monitoring application

jfarcand
Administrator
Salut,

have you gived up or you have find a solution to your issue?

Thanks!

-- Jeanfrancois
Loading...