LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-11-2015, 02:01 AM   #1
reetesh.amity
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Rep: Reputation: Disabled
Post 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.
 
Old 10-11-2015, 02:38 AM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
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.
 
Old 10-11-2015, 04:00 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...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?..
 
1 members found this post helpful.
Old 10-11-2015, 08:16 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You may even want to look at collectl http://collectl.sourceforge.net/ which supplies multiple capabilities in one tool.
 
2 members found this post helpful.
Old 10-12-2015, 02:03 PM   #5
reetesh.amity
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.
 
Old 10-12-2015, 02:23 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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.
 
1 members found this post helpful.
Old 10-12-2015, 07:51 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
partition space and disk space usage and free don't match nsic Linux - Newbie 3 02-22-2013 12:57 PM
Need Monitor the CPU, Memory and Disk Usage srikanthrao_d Linux - Software 2 12-28-2005 08:15 AM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration