Linux: getting the "load" values without using "top"

I would like to get some of the information provided by the "top"
command into my ruby program, in particular the "load" values. The only
way I can think of is to use popen3 to run "top -n 1" and parse the
output, but I would like to not have to call an external command and do
it using pure ruby.

···

--
Posted via http://www.ruby-forum.com/.

I would like to get some of the information provided by the "top"
command into my ruby program, in particular the "load" values. The only
way I can think of is to use popen3 to run "top -n 1" and parse the
output, but I would like to not have to call an external command and do
it using pure ruby.

look at the contents of /proc/loadavg

···

On Tue, Apr 1, 2008 at 8:49 AM, James Dinkel <jdinkel@gmail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

--
thanks,
-pate
-------------------------
Duty makes us do things, Love make us do things well.
http://on-ruby.blogspot.com http://on-erlang.blogspot.com
http://on-soccer.blogspot.com

The uptime command will report it, if for whatever reason you don't have
or can't use the /proc option.

Ben

···

On Tue, Apr 01, 2008, James Dinkel wrote:

I would like to get some of the information provided by the "top"
command into my ruby program, in particular the "load" values. The only
way I can think of is to use popen3 to run "top -n 1" and parse the
output, but I would like to not have to call an external command and do
it using pure ruby.

pat eyler wrote:

···

On Tue, Apr 1, 2008 at 8:49 AM, James Dinkel <jdinkel@gmail.com> wrote:

I would like to get some of the information provided by the "top"
command into my ruby program, in particular the "load" values. The only
way I can think of is to use popen3 to run "top -n 1" and parse the
output, but I would like to not have to call an external command and do
it using pure ruby.

look at the contents of /proc/loadavg

--
Posted via http://www.ruby-forum.com/\.

Yeah ... that will work. But I'm curious why the OP's application cares about the load averages. My experience has been that there isn't a lot to be gained from it. "Real" load balancing is a bit more complicated, if that's what he's trying to do.

* pat eyler <pat.eyler@gmail.com> [080401 07:58]:

···

On Tue, Apr 1, 2008 at 8:49 AM, James Dinkel <jdinkel@gmail.com> wrote:
> I would like to get some of the information provided by the "top"
> command into my ruby program, in particular the "load" values. The only
> way I can think of is to use popen3 to run "top -n 1" and parse the
> output, but I would like to not have to call an external command and do
> it using pure ruby.

look at the contents of /proc/loadavg

Ruby Geek! :wink:

--Stafford (Very very newbie wanna-be Ruby Geek)

Oh, thanks, I did not realize it was kept in a file.

I'm wanting this because this script currently blows up the server if
run when the load is too high. I'll just have the script sleep for 5
minutes until the load is under a certain threshold.

···

--
Posted via http://www.ruby-forum.com/.

Oh, thanks, I did not realize it was kept in a file.

I'm wanting this because this script currently blows up the server if
run when the load is too high. I'll just have the script sleep for 5
minutes until the load is under a certain threshold.

Sorry for being negative, but what will happen if the load goes up
again while your script is running?
Maybe you just cannot run this script safely on that server.
Just curious what that script does, maybe you can run it on a nice
level that will allow the server to survive, seems
much a saver approach to me.
Cheers
Robert

···

On Tue, Apr 1, 2008 at 5:08 PM, James Dinkel <jdinkel@gmail.com> wrote:

--

Posted via http://www.ruby-forum.com/\.

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Oh, thanks, I did not realize it was kept in a file.

It's not exactly a file. But it is mounted in a special file system
and can be read like a file or device.

I'm wanting this because this script currently blows up the server if
run when the load is too high. I'll just have the script sleep for 5
minutes until the load is under a certain threshold.

That's what process priorities are for. You can find out via "man
nice". Maybe there's even a Ruby library method that allows to lower
the priority of the current process.

Kind regards

robert

···

2008/4/1, James Dinkel <jdinkel@gmail.com>:

--
use.inject do |as, often| as.you_can - without end

Robert Dober wrote:

Sorry for being negative, but what will happen if the load goes up
again while your script is running?

I'm pretty sure the server will blow up.

Maybe you just cannot run this script safely on that server.
Just curious what that script does, maybe you can run it on a nice
level that will allow the server to survive, seems
much a saver approach to me.

I don't know what "a nice level" is, but I will look into it.

Thanks,
James

···

--
Posted via http://www.ruby-forum.com/\.

Robert Dober wrote:

Oh, thanks, I did not realize it was kept in a file.

I'm wanting this because this script currently blows up the server if
run when the load is too high. I'll just have the script sleep for 5
minutes until the load is under a certain threshold.

Sorry for being negative, but what will happen if the load goes up
again while your script is running?
Maybe you just cannot run this script safely on that server.
Just curious what that script does, maybe you can run it on a nice
level that will allow the server to survive, seems
much a saver approach to me.
Cheers
Robert

--

Posted via http://www.ruby-forum.com/\.

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

A secure aproach can be SNMP*
You can use it from the localhost or somewhere else

http://snmplib.rubyforge.org/

* What is SNMP?

SNMP is the Simple Network Management Protocol. This protocol provides
the capability to monitor and manage switches, routers, printers,
desktops, and other equipment in your network.

···

On Tue, Apr 1, 2008 at 5:08 PM, James Dinkel <jdinkel@gmail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

It simply runs your program with less or more priority, but I guess
you can type "man nice" as you have
indicated above.
Good luck.
R.

···

On Tue, Apr 1, 2008 at 5:20 PM, James Dinkel <jdinkel@gmail.com> wrote:

Robert Dober wrote:

> Sorry for being negative, but what will happen if the load goes up
> again while your script is running?

I'm pretty sure the server will blow up.

> Maybe you just cannot run this script safely on that server.
> Just curious what that script does, maybe you can run it on a nice
> level that will allow the server to survive, seems
> much a saver approach to me.

I don't know what "a nice level" is, but I will look into it.

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein