------ art_70473_25001572.1153242155890 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/15/06, Ben Johnson <bjohnson / contuitive.com> wrote: > > [SNIP] > > Running the "top" command tells me all kinds of information about the > computer, could something similar to this be used in a ruby application? Well if top information is all you want ruby can certainly call top as a system call I wrote a little class that might be useful, be careful about synchronization though, I have 0 experience with that in ruby! I immagine one might implement consumer and producer threads with classical CondVar design anyway it seems to work well ;) Cheers Robert ----------------------------- 8< ------------------------------------- #!/usr/bin/ruby -w require 'thread' class TopData def initialize sleepy` @sleepy leepy @new alse @m utex.new @top hread.new { loop { @m.synchronize { @data O.popen( '/usr/bin/top -bn 1' ).readlines @new rue } sleep @sleepy } } end def new_data?; @new; end def get_data @m.synchronize { @new alse @data } end end t opData.new 2 100.times do puts t.get_data sleep 2 end > Thank You, > Ben Johnson > E: bjohnson / contuitive.com > > > > On Jul 15, 2006, at 3:41 PM, Jeremy Tregunna wrote: > > > > > On 15-Jul-06, at 4:31 PM, Ben Johnson wrote: > > > >> On my program I want to display the load the server is currently > >> under. The application I'm writing can get pretty intense and it > >> based on a number of factors. I want the user to be able to tell > >> when they are using the program beyond the server's limits. Is > >> this possible? Maybe show the percent of the CPU being used, how > >> much ram is being used, etc. > > > > Not really... If you limit CPU usage to a certain percentage, > > percentage of CPU usage isn't going to be helpful. If you don't, > > other factors could (and will) almost always taint that result. The > > same caveat applies to testing memory usage. > > > > Also, the load displayed by the unix 'w' program (uptime is usually > > a hard link to this) will display differently based on different > > factors on different unix operating systems. FreeBSD for example > > uses the total number of waiting processes to gauge system load, > > which may not be the most accurate. Calculating load is a difficult > > beast. If perhaps you could tell us what exactly your program does, > > we may be able to offer you better solutions. > > > >> Ben Johnson > > > > -- > > Jeremy Tregunna > > jtregunna / blurgle.ca > > > > > > "One serious obstacle to the adoption of good programming languages > > is the notion that everything has to be sacrificed for speed. In > > computer languages as in life, speed kills." -- Mike Vanier > > > > > > Great signature ;) > ------ art_70473_25001572.1153242155890--