LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Shell script for CPU usage, memory usage, disk partition space and service status (https://www.linuxquestions.org/questions/linux-server-73/shell-script-for-cpu-usage-memory-usage-disk-partition-space-and-service-status-4175555833/)

reetesh.amity 10-11-2015 02:01 AM

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?


Thanks in advance.

ButterflyMelissa 10-11-2015 02:38 AM

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

unSpawn 10-11-2015 04:00 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?..

chrism01 10-11-2015 08:16 PM

You may even want to look at collectl http://collectl.sourceforge.net/ which supplies multiple capabilities in one tool.

reetesh.amity 10-12-2015 02:03 PM

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


Please suggest.

sundialsvcs 10-12-2015 02:23 PM

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.

chrism01 10-12-2015 07:51 PM

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.


All times are GMT -5. The time now is 06:31 AM.