Discussion:
Perl script to monitor memory usage on unix box
Dave Tang
2010-02-08 12:44:14 UTC
Permalink
Hi everybody,

I want to write a script that checks memory usage of my RHEL box, and ran
as a cron job say every 10 minutes.

I could write the Perl script to run a system command like "ps aux", parse
that information and kill a job if >90% of the total system memory (and I
realise most of the times memory is sitting in cached) is being used. And
I guess if 8 jobs are already using 80%, the job that topples the
threshold will have to be stopped. But since that isn't a Perl question, I
won't ask if that is a good implementation.

Since I didn't want to reinvent the wheel and/or write an inelegant
script, I wanted to ask if there are CPAN modules, which people have used,
to help with achieving my task?

Many thanks,

Dave
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Shawn H Corey
2010-02-08 12:52:37 UTC
Permalink
Post by Dave Tang
Hi everybody,
I want to write a script that checks memory usage of my RHEL box, and
ran as a cron job say every 10 minutes.
I could write the Perl script to run a system command like "ps aux",
parse that information and kill a job if >90% of the total system memory
(and I realise most of the times memory is sitting in cached) is being
used. And I guess if 8 jobs are already using 80%, the job that topples
the threshold will have to be stopped. But since that isn't a Perl
question, I won't ask if that is a good implementation.
Since I didn't want to reinvent the wheel and/or write an inelegant
script, I wanted to ask if there are CPAN modules, which people have
used, to help with achieving my task?
I don't know if there's any CPAN modules, but you should use the /proc
directory rather than ps.
--
Just my 0.00000002 million dollars worth,
Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Dave Tang
2010-02-08 12:59:41 UTC
Permalink
Post by Shawn H Corey
Post by Dave Tang
Hi everybody,
I want to write a script that checks memory usage of my RHEL box, and
ran as a cron job say every 10 minutes.
I could write the Perl script to run a system command like "ps aux",
parse that information and kill a job if >90% of the total system memory
(and I realise most of the times memory is sitting in cached) is being
used. And I guess if 8 jobs are already using 80%, the job that topples
the threshold will have to be stopped. But since that isn't a Perl
question, I won't ask if that is a good implementation.
Since I didn't want to reinvent the wheel and/or write an inelegant
script, I wanted to ask if there are CPAN modules, which people have
used, to help with achieving my task?
I don't know if there's any CPAN modules, but you should use the /proc
directory rather than ps.
Thanks for the reply Shawn. There was a reason for using ps (don't know if
it is a good reason though).

Very recently a user wrote a script that crashed the server, by using all
the memory. So also I wanted to capture the process information too. Is
this information available in the /proc directory?

Cheers,

Dave
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Shawn H Corey
2010-02-08 13:56:53 UTC
Permalink
Post by Dave Tang
Very recently a user wrote a script that crashed the server, by using
all the memory. So also I wanted to capture the process information too.
Is this information available in the /proc directory?
Yes, google "linux proc".
--
Just my 0.00000002 million dollars worth,
Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Yue Chen
2010-02-08 15:49:15 UTC
Permalink
Hi Dave

Have you ever tried module Proc-ProcessTable? It is a wonderful tool
to collect process information such as PID, cmdline, CPU usage and Mem
usage.
Post by Dave Tang
Hi everybody,
I want to write a script that checks memory usage of my RHEL box, and ran as
a cron job say every 10 minutes.
I could write the Perl script to run a system command like "ps aux", parse
that information and kill a job if >90% of the total system memory (and I
realise most of the times memory is sitting in cached) is being used. And I
guess if 8 jobs are already using 80%, the job that topples the threshold
will have to be stopped. But since that isn't a Perl question, I won't ask
if that is a good implementation.
Since I didn't want to reinvent the wheel and/or write an inelegant script,
I wanted to ask if there are CPAN modules, which people have used, to help
with achieving my task?
Many thanks,
Dave
--
http://learn.perl.org/
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
蔡超
2010-02-09 02:56:35 UTC
Permalink
Hi Dave,

There is a tool sysusage which is a open source coded in perl. It
might be worth to have a look.
Post by Dave Tang
Hi everybody,
I want to write a script that checks memory usage of my RHEL box, and ran as
a cron job say every 10 minutes.
I could write the Perl script to run a system command like "ps aux", parse
that information and kill a job if >90% of the total system memory (and I
realise most of the times memory is sitting in cached) is being used. And I
guess if 8 jobs are already using 80%, the job that topples the threshold
will have to be stopped. But since that isn't a Perl question, I won't ask
if that is a good implementation.
Since I didn't want to reinvent the wheel and/or write an inelegant script,
I wanted to ask if there are CPAN modules, which people have used, to help
with achieving my task?
Many thanks,
Dave
--
http://learn.perl.org/
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Continue reading on narkive:
Loading...