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

J

James Dinkel

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.
 
P

pat eyler

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


 
T

ts

James said:
I would like to get some of the information provided by the "top"
command into my ruby program, in particular the "load" values.

Well, it's in /proc/loadavg no ? Juste read this file.


Guy Decoux
 
M

M. Edward (Ed) Borasky

pat said:
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



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.
 
J

James Dinkel

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.
 
R

Robert Dober

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
 
J

James Dinkel

Robert said:
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
 
R

Robert Dober

I'm pretty sure the server will blow up.



I don't know what "a nice level" is, but I will look into it.
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.
 
R

Robert Klemme

2008/4/1 said:
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
 
B

Ben Bleything

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.

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

Ben
 
R

Rodrigo Bermejo

Robert said:
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top