LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-30-2004, 08:52 AM   #1
gurkburk
LQ Newbie
 
Registered: Sep 2003
Location: Sweden
Distribution: Slackware
Posts: 7

Rep: Reputation: 0
grabing info and putting it in a file


I am working on a way of monitoring if my machine´s preformance since I am afraid the cpu wont be sufficient for the work its supposed to do..

What I basically wanto do is make some form of script/program/crontab job that:
1) gets current CPU-load (total all users), mem-usage and swap-usage
2) opens a file, puts this at last line, saves the file..

Then i can show this very nicely on some webpage using php or the like.

So I pretty much need help with what commands to use or how, then throwing it in a file for easier handling.
 
Old 04-30-2004, 10:09 AM   #2
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Think there's a command(s) that give that info. Perhaps do:
apropos load
or the like to find it.

Then write a script, something like:

#! /bin/sh
# say 'loadstat' is the name of the command.

loadstat >> my_load_statistics_file.txt

Then make it executable and put it on your PATH.

No expert but should work.
 
Old 04-30-2004, 11:19 AM   #3
gurkburk
LQ Newbie
 
Registered: Sep 2003
Location: Sweden
Distribution: Slackware
Posts: 7

Original Poster
Rep: Reputation: 0
Aha there you go, putting the info into a file seemed a bit easier then I expected, all that is left is the nifty command that gives me all the info I need.. the search continues

note: ive found that uptime seems to give 3 values after "load average", but havent had time to read more about this, could be the golden command if its cpu and mem-usage, then that could be enough for me

Thanks lugoteehalt !

Edit: seems uptime only gives you cpu-usage, no mem or swap stats.

Last edited by gurkburk; 04-30-2004 at 11:31 AM.
 
Old 04-30-2004, 12:28 PM   #4
bruno buys
Senior Member
 
Registered: Sep 2003
Location: Rio
Distribution: Debian
Posts: 1,511

Rep: Reputation: 46
Did you try "top"? Top shows a lot of info.
But with top you will need some special arguments in order to make it behave correctly. Top won't exit until you tell him to exit. So, you have to issue the number of iterations top will perform.
Try:
top -n 1 >> topinfo.txt

Using two > chars, the command will append the new text into the file, whitout erasing the current content. Using only one, top will erase all prior content and paste new, each time you run the script. (like this: top -n 1 > topinfo.txt)

Hope it helps!

Last edited by bruno buys; 04-30-2004 at 12:36 PM.
 
Old 04-30-2004, 01:23 PM   #5
gurkburk
LQ Newbie
 
Registered: Sep 2003
Location: Sweden
Distribution: Slackware
Posts: 7

Original Poster
Rep: Reputation: 0
I think top takes a bit to much out of the cpu, if I "run" it, without the -n 1, it takes about 0.1-20% cpu, I dont want something going off every 5th minute causing any form of preformance-decrease...

Maybe if I can get it to show without the actual PID-info and just the interesting info at the "top" () it will be very nice, from that I can just extract anything I want/need since its all there!

man top here I come
 
Old 04-30-2004, 03:44 PM   #6
bruno buys
Senior Member
 
Registered: Sep 2003
Location: Rio
Distribution: Debian
Posts: 1,511

Rep: Reputation: 46
If you run top without the -n 1 option, top won't exit. It's of no use to a text file.
 
Old 05-14-2004, 08:19 AM   #7
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
The following command produces top suitable for a text file and pulls off the top five lines:

top -b n 1|egrep 'average|zombie|nice|shrd|Swap'

There is a ??bug in my version of top so that the cpu usuage line's while usefull doesn't really make sence. Subsequent itterations, n 2, are allright.

 
Old 05-14-2004, 10:36 AM   #8
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
If you have sysstat installed you could use sar
blink@insanity ~--> sar -u 10 5
Linux 2.4.20-30.9 (insanity) 05/14/2004

09:33:39 AM CPU %user %nice %system %idle
09:33:49 AM all 9.70 0.10 1.20 89.00
09:33:59 AM all 7.40 0.10 0.50 92.00
09:34:09 AM all 8.30 0.40 1.20 90.10
09:34:19 AM all 6.60 0.20 0.70 92.50
09:34:29 AM all 18.50 0.00 0.90 80.60
Average: all 10.10 0.16 0.90 88.84
blink@insanity ~-->

sar -u (delay) (times to report)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Convert an info file(bash.info.gz) to a single html file Darwish Linux - Software 2 09-24-2005 06:51 AM
C: Best way to read an entire text file and putting it in a *char. Claus Programming 8 03-15-2004 01:22 PM
what is module-info file? tuxfood Linux - Newbie 1 10-25-2003 05:55 PM
Putting together high performance file server - suggestions? BrianK General 3 09-17-2003 04:06 PM
Putting error messages on the screen into a file... tarballed Linux - Newbie 3 07-01-2003 02:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:58 AM.

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