Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Cromulent

macrumors 604
Original poster
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
I'm trying to add a little feature that takes the current load on a computer and then sends it back to a central server (same computer or different computer it does not really matter) and then the server routes network requests based on the load of the registered servers with it.

What is the best way of getting current load on a Mac for a system such as this? It is a C only application I am afraid so no Cocoa / Objective-C.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
Use the stdlib function "getloadavg()" like this:

Code:
double   loads[3];

getloadavg(loads, 3);

That gives the three load values like you see in:

Code:
TwinTurboG5:~ nerfle$ uptime
 9:44  up 23:22, 2 users, load averages: 1.45 1.31 1.12
 

Cromulent

macrumors 604
Original poster
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
Use the stdlib function "getloadavg()" like this:

Code:
double   loads[3];

getloadavg(loads, 3);

That gives the three load values like you see in:

Code:
TwinTurboG5:~ nerfle$ uptime
 9:44  up 23:22, 2 users, load averages: 1.45 1.31 1.12

The problem with that is it is not accurate enough. The servers performance will be quite variable and as such I think the load average might not offer the kind of information I need.

I mean obviously it does give you an idea, but it is still reasonably general.

Edit : I guess it might actually do the job if I just call it more than once a minute and take the moving average of the average load over a one minute period.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.