Shell script for CPU usage, memory usage, disk partition space and service status
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Shell script for CPU usage, memory usage, disk partition space and service status
I was trying to write a shell script from which I can fetch CPU Usage (Min, Max, Average), Memory Usage(Min, Max, Average), Disk partition space status and service up/down status).
I want to create a script and configure it in our cron so that I can get hourly basis status. Please suggest how to do it?
Umm, here's a case of re-inventing...tap water
The command "top" does just that, and more...just stream the output to a text file...
Next, set up a Cron job for example...
And...voila...you can have this output mailed to you too...just a detail
Have fun!
And...welcome to the forum, we hope you'll like your stay
Thor
Last edited by ButterflyMelissa; 10-11-2015 at 02:40 AM.
...and if this is a one off for one server then sure, but if this is supposed to be rolled out over different servers and or ameliorated over time then I'd suggest looking at existing SAR tools (Atop) and frameworks (Monit, Nagios, etc, etc) because else you want a local log parser (Logwatch) as well for daily reporting as email isn't very efficient for aggregating data from?..
Hello All,
We have configured Nagios for server monitoring. But, this demand came from our client side. He wants us to write a script that will give them details of CPU Usage (Min, Max, Average), Memory Usage(Min, Max, Average), Disk partition space status and service up/down status on hourly basis.
I can fetch the current CPU usage or memory usages. But, I want to know how to write a script that will calculate last 1hour CPU usages(maximum, minimum and average) & Memory usages(maximum, minimum and average).
If you already have Nagios in place, I recommend that you pursue the strategy of getting this client the information that he wants, but without acceding to his demands that you "write a script to do it." Also recognize that you really can't provide a historical record of CPU usage without running some kind of monitoring daemon ... which, of course, consumes CPU.
"The presence of the experimenter should not alter the experiment."
I would recommend that (your managers ...?) probe the client's expectations to understand, first of all, "what his business concern is," and then, "how best to satisfy that concern," whether or not (and, "probably not" ...) that solution consists of "doing what the client says he wants you to do."
For example, maybe what he really wants is a "service-level agreement," because he intuitively or apparently believes that his jobs or transactions are not getting the levels that he contracted for. This usually can be translated away from "purely computer" terms (such as "CPU usage," which in fact is largely meaningless ...) to, say, "mean transactions-per-second" (and/or standard deviation). Or, better yet, "fence conditions" such as "95 of the time, every unit of work will be completed within 1.0 seconds." Which performance can now be measured using analysis of log-files that are not expensive to produce.
From the sounds of it, what you want is a monitoring system like eg Cacti that creates graphs of various measures of 'usage' over time.
This is typical if you install Nagios for alerting.
Most people like to have both.
Certainly writing your own scripts is not the smart move.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.