-1

I'm attempting to create a Sinatra server that will return statistics about an EventMachine server. That is, I'm running:

EventMachine.run do
    server = EventMachine.start_server 'localhost', 3333, MyApp

    dispatch = Rack::Builder.app do
        map '/' do
            run MySinatraApp
        end
    end

    Rack::Server.start({
        app: dispatch,
        server: 'thin',
        Host: '0.0.0.0',
        Port: '1111'
    })
end

My goal is to figure out information on that running server started by start_server, such as connection_count. Is there any way to do this?

josh
  • 9,656
  • 4
  • 34
  • 51

2 Answers2

1

As far as I know there is no in-built way to do this (hopefully someone disproves me),

you can keep a counter in MyApp and +1 on connect and -1 on unbind for same effect.

bbozo
  • 7,075
  • 3
  • 30
  • 56
  • Do you know if there's a way to access `MyApp` information from that server instance? Obviously I can't use `MyApp.new` but I don't know of a way to pull info from `MyApp` that's started using `start_server`. – josh Jan 08 '14 at 18:38
  • Sorry :/ completely forgot of this question, hopefully you managed, it's not complicated – bbozo Jan 21 '14 at 12:52
  • I did, thanks! I just made class variables to hold the information rather than instance variables, and use those in the Sinatra server. – josh Jan 21 '14 at 21:28
0

Why? Why not just have the EM server provide a /info endpoint or something that returns a dump of the information you need? Why do you need the second server? If you really want a second server then it could just be a simple sinatra app that makes a HTTP request to /info and returns the results.

For connection_count it looks like there is a EM.connection_count you can call. You can see it here.

dj2
  • 9,534
  • 4
  • 29
  • 52