views:

92

answers:

3

I am writing a scheduled task which I would like to run frequently.

The problem is that I do not want this task to be run if the server is experiencing a high traffic load.

Is there any way other then getting the free/total/max memory from java to try and figure out whether this task should continue?

+4  A: 

There's an easy way to retrieve the memory usage information.

http://misterdai.wordpress.com/2009/11/25/retrieving-coldfusion-memory-usage/

For CPU load I think you can get it from getMetricData() but there are other methods too, but since this is my first stackoverflow post I'm only allowed one link :P But it's on my blog so just do a CPU search when you look at the link above.

You might find it useful to dig into getMetricData() for the performance monitoring stats. It's a good way of telling how busy your server is by the number of running and queued requests.

Hope this helps, Dave (aka Mister Dai)

Mister Dai
+5  A: 

GetMetricData() is going to give you a very good indication of how busy your server is, i.e. how many requests are running and how many are queued as well as other info.

It's the same info that you get from running cfstat from the command line (you'll find that under {cfroot}\bin\cfstat.exe).

However, knowing how busy you are at the very moment might not be very useful to you if you just call that function once. It might be better for you to log performance data to file or to a database table using Windows perfmon. You can then get the average number of running/queued requests over the past 5 minutes (or whatever) and make your decision on whether to run your task.

Ciaran Archer
This looks very promising, I cannot tell from the docs, is this only on Enterprise CF? Also, will this work the same on a *nix server? The code example specifically mentions that it gets it's data from the NT PerfMonitor is why i ask.
Tyler Clendenin
Well getMericData() will work just fine on all CF versions if that's what you mean - the same goes for cfstat. Just enable it in CF Admin! Perfmon is Windows only. If you are running on Linux then see this thread: http://stackoverflow.com/questions/345543/perfmon-like-for-linuxThe nice thing is Perfmon allows access to the CF Performance Counters provided you have them enabled in CF Admin. I'm not sure how the Linux equivalent will work. You could also write a separate task to gather the cfstat numbers yourself. Lots of options!
Ciaran Archer
+1  A: 

Use the ColdFusion AdminApi. Call http://servername/CFIDE/adminapi/servermonitor.cfc in your browser to get the cfcdocs of the component. If gives you many methods to get the health of you CF server instance.

David Collie