LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 03-24-2011, 06:35 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Rep: Reputation: 36
Output formatting .


below is a CPU utilization Log for ABC server.
However for every 15 minutes it generates 3 CPU values(with interval of 2 sec).
Code:
Host  CPU CPUtotal CPU% time
ABC 101.1 2 50.55 14 : 15
ABC 100.5 2 50.25 14 : 15
ABC 100.2 2 50.1 14 : 15
ABC 100.9 2 50.45 14 : 30
ABC 100.5 2 50.25 14 : 30
ABC 100.4 2 50.2 14 : 30
ABC 101.0 2 50.5 14 : 45
ABC 100.9 2 50.45 14 : 45
ABC 100.4 2 50.2 14 : 45
ABC 101.1 2 50.55 15 : 00
ABC 100.7 2 50.35 15 : 00
ABC 100.5 2 50.25 15 : 00
ABC 101.1 2 50.55 15 : 15
ABC 101.0 2 50.5 15 : 15
ABC 100.5 2 50.25 15 : 15
ABC 101.1 2 50.55 15 : 30
ABC 100.9 2 50.45 15 : 30
ABC 100.4 2 50.2 15 : 30
ABC 102.2 2 51.1 15 : 45
ABC 101.4 2 50.7 15 : 45
ABC 100.7 2 50.35 15 : 45
How would i list average value of cpu % at after every 15 minuates.
Say.
Code:
ABC 101.1 2 50 14 : 15
ABC 101.1 2 50 15 : 00
ABC 101.1 2 50 15 : 15
ABC 100.4 2 50 15 : 30
ABC 102.2 2 50 15 : 45
Please suggest .
 
Old 03-24-2011, 07:19 AM   #2
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 194

Rep: Reputation: 50
Here is what I did...

Made a file with all the values called cpu.txt

Here is an example of the file I used:

$ cat cpu.txt
ABC 101.1 2 50.55 14 : 15
ABC 100.5 2 50.25 14 : 15
ABC 100.2 2 50.1 14 : 15
ABC 100.9 2 50.45 14 : 30
ABC 100.5 2 50.25 14 : 30
ABC 100.4 2 50.2 14 : 30
ABC 101.0 2 50.5 14 : 45
ABC 100.9 2 50.45 14 : 45
ABC 100.4 2 50.2 14 : 45
ABC 101.1 2 50.55 15 : 00
ABC 100.7 2 50.35 15 : 00
ABC 100.5 2 50.25 15 : 00
ABC 101.1 2 50.55 15 : 15
ABC 101.0 2 50.5 15 : 15
ABC 100.5 2 50.25 15 : 15
ABC 101.1 2 50.55 15 : 30
ABC 100.9 2 50.45 15 : 30
ABC 100.4 2 50.2 15 : 30
ABC 102.2 2 51.1 15 : 45
ABC 101.4 2 50.7 15 : 45
ABC 100.7 2 50.35 15 : 45



Then run the following awk statement against it:

awk '{sum+=$5; ++n; print $5 }; END { print "------"; print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n} ' cpu.txt

and here is the output:


$ awk '{sum+=$5; ++n; print $5 }; END { print "------"; print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n} ' cpu.txt
14
14
14
14
14
14
14
14
14
15
15
15
15
15
15
15
15
15
15
15
15
------
Tot=306(21)
Avg=306/21=14.5714
 
Old 03-24-2011, 07:21 AM   #3
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 194

Rep: Reputation: 50
oops... silly me, used the wrong column... Just change the 5 to a 4 in the awk statement...


$ awk '{sum+=$4; ++n; print $4 }; END { print "------"; print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n} ' cpu.txt
50.55
50.25
50.1
50.45
50.25
50.2
50.5
50.45
50.2
50.55
50.35
50.25
50.55
50.5
50.25
50.55
50.45
50.2
51.1
50.7
50.35
------
Tot=1058.75(21)
Avg=1058.75/21=50.4167
 
Old 03-24-2011, 07:39 AM   #4
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by savona View Post
oops... silly me, used the wrong column... Just change the 5 to a 4 in the awk statement...


$ awk '{sum+=$4; ++n; print $4 }; END { print "------"; print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n} ' cpu.txt
50.55
50.25
50.1
50.45
50.25
50.2
50.5
50.45
50.2
50.55
50.35
50.25
50.55
50.5
50.25
50.55
50.45
50.2
51.1
50.7
50.35
------
Tot=1058.75(21)
Avg=1058.75/21=50.4167
appreciate your help but i m expecting output in following format.

Quote:
ABC 101.1 2 50 14 : 15
ABC 101.1 2 50 15 : 00
ABC 101.1 2 50 15 : 15
ABC 100.4 2 50 15 : 30
ABC 102.2 2 50 15 : 45
 
Old 03-24-2011, 09:15 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,631

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Well it is the same story for identifying anything you want displayed, what are the unique factors / identifiers that allow you to group together the data you are looking for?

Based on what you have shown as input it appears this data does not have enough unique points to give you what you would like.
So now you need to find more data that you can cross-reference with what you already have so you can.
 
Old 03-25-2011, 12:43 AM   #6
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
ok i will make it more clear.
Quote:
Host CPU CPUtotal CPU% time
ABC 101.1 2 50.55 14 : 15
ABC 100.5 2 50.25 14 : 15
ABC 100.2 2 50.1 14 : 15
ABC 100.9 2 50.45 14 : 30
ABC 100.5 2 50.25 14 : 30

I would like to take above file as input .
Notice that for every 15 minuate interval there are some entries generated.
for example : for 14:15 there are 3 entries .
for 14:30 there are 2 entries.

I would like to get average of cpu% considering time.
say.
Quote:
ABC 100.6 2 50.3 14 : 15
ABC 100.7 2 50.33 14 : 30

Last edited by pinga123; 03-25-2011 at 01:56 AM.
 
Old 03-25-2011, 04:04 AM   #7
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,631

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Cool ... in that case (untested):
Code:
 awk '{sum_cpu[$(NF-2),$NF]+=$2;sum_per[$(NF-2),$NF]+=$4;count[$(NF-2),$NF]++}END{for(x in sum_per)print $1,sum_cpu[x]/count[x],$3,sum_per[x]/count[x],x}' file
You may need to play with last entry if you want time shown with a colon, but you get the idea.
 
  


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
output formatting with awk. pinga123 Programming 4 11-26-2010 08:56 AM
formatting ls or get one column from ls output culin Linux - Newbie 10 10-19-2010 08:07 PM
[SHELL] Output formatting Adrnalnrsh Programming 3 09-22-2008 11:29 AM
Formatting output krock923 Programming 2 06-07-2006 08:26 AM
Formatting output of ls doodar Linux - Newbie 29 07-29-2004 02:25 PM


All times are GMT -5. The time now is 05:53 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration