scout_realtime icon indicating copy to clipboard operation
scout_realtime copied to clipboard

Add an option to collect statistics data only when there are connected clients

Open KonishchevDmitry opened this issue 10 years ago • 1 comments

On my low loaded server the most of time scout_realtime is in top of CPU consuming processes. I believe it makes sense to add an option to collect the statistics data only when there are connected clients to reduce CPU usage.

KonishchevDmitry avatar Mar 14 '14 11:03 KonishchevDmitry

Thanks @KonishchevDmitry. If anyone wants to tackle this:

  1. record a time stamp of the last request to /stats.json (https://github.com/scoutapp/scout_realtime/blob/master/lib/scout_realtime/web_app.rb#L55)
  2. if the last request to /stats.json is older than some threshold (say, 10 seconds), don't run the collectors (or make the collector runs null-ops)
  3. we'd probably want to keep the collectors running for a few minutes after startup, so you still see fully populated charts your first pageview after starting the agent.

One open question is what to do with the historical metrics when the collectors are paused. The collectors use a RingBuffer to store 60 trailing values from each metric (via https://github.com/scoutapp/scout_realtime/blob/master/lib/scout_realtime/lib/aggregator.rb). If you just stop collecting data, the contents of the RingBuffer will still be there when you start again, which will display old data in the charts when you revisit the page.

andre avatar Mar 14 '14 16:03 andre