- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Adding time stamp to vmstat output
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 04:22 AM
тАО03-15-2011 04:22 AM
I am trying to add time stamp on vmstat output, but it is not working at all. Here is what I do:
vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
but it returns the following:
%Y-%m-%d %T kthr memory page disk faults cpu
%Y-%m-%d %T r b w swap free re mf pi po fr de sr m1 m1 m1 m2 in sy cs us sy id
%Y-%m-%d %T 1 3 0 27153136 1215512 1558 16803 82 158 163 0 152 0 0 0 5 6852 93219 21292 38 26 36
Please can you help
F.R.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 05:29 AM
тАО03-15-2011 05:29 AM
Re: Adding time stamp to vmstat output
You need to use GNU's 'awk' to avail yourself of 'strftime' in 'awk'.
However, you can do the same thing with Perl:
# perl -MPOSIX -nle 'print join " ",strftime("%Y-%m-%d %T",localtime),$_'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 08:41 AM
тАО03-15-2011 08:41 AM
Re: Adding time stamp to vmstat output
vmstat 1 | awk '{system("echo $(date +\"%x %r %Z\")");print $0;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 10:33 PM
тАО03-15-2011 10:33 PM
Re: Adding time stamp to vmstat output
Kenan
Your command does work fine, but it does not put th date on the same line of the data.
Would it be possible to make like this:
03/16/11 08:24:42 r b w avm free re at pi po fr de sr in sy cs us sy id
03/16/11 08:24:42 1 1 0 58501 1423937 0 0 0 0 0 0 0 957 2988 36 0 0 100
03/16/11 08:24:43 1 1 0 58501 1424018 0 0 9 0 0 0 0 1002 6107 73 0 1 99
The other query is, if I want to use awk to select/show only values of r, b, sr, us and sy how would I do?
Another point. that command it does not work in solaris 10.
F.R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 12:34 AM - last edited on тАО08-04-2011 10:49 AM by Kevin_Paul
тАО03-16-2011 12:34 AM - last edited on тАО08-04-2011 10:49 AM by Kevin_Paul
Re: Adding time stamp to vmstat output
>it does not put the date on the same line of the data.
Any reason you use echo within system?
system("date +\"%x %r %Z\"")
If this doesn't work, you may have to use that echo \c trick I used in this thread:
http://h30499.www3.hp.com/t5/Languages-and-Scripting/AWK-script/m-p/5271240#M41496
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 12:37 AM
тАО03-16-2011 12:37 AM
Re: Adding time stamp to vmstat output
Instead of printing $0, print the specific columns:
...; print $1, $2, $12, $16, $17
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 01:07 AM
тАО03-16-2011 01:07 AM
Re: Adding time stamp to vmstat output
Dennis!
No particul├Г┬зar reason to use echo, but I have modified to suit your suggestion, and it came up with:
prep03[151]/ #vmstat 1 | awk '{system("date +\"%x %r %Z\"");print $0;}'
03/16/11 11:07:17 AM SAST
procs memory page faults cpu
03/16/11 11:07:17 AM SAST
r b w avm free re at pi po fr de sr in sy cs us sy id
03/16/11 11:07:17 AM SAST
1 0 0 47263 1437359 0 0 0 0 0 0 0 957 2991 36 0 0 100
03/16/11 11:07:18 AM SAST
But I want the date on the same line as the data, and I dont need the (AM SAST) string.
I know I can use print $1 for selected columns, but how to put it toghether in one line or statement.
I want to use this as an input to gnuplot to produce a graph.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 02:13 AM
тАО03-16-2011 02:13 AM
Re: Adding time stamp to vmstat output
how about the date at the end :)
vmstat 1 | awk '{system("echo $(date +\"%x %r \")");printf("%s ",$0);}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 04:59 AM
тАО03-16-2011 04:59 AM
Re: Adding time stamp to vmstat output
myprocess |awk 'BEGIN {"date +%Y%m%d_%H:%M" | getline now} {printf "%s %s\n", now, $0}' >> $logfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 12:01 PM
тАО03-16-2011 12:01 PM
Re: Adding time stamp to vmstat output
Then you need to use that alternate solution in the URL I gave.
system("X=$(date +\"%x %r %Z\"); echo $X\\\c")
To change the date format, you need to look at the options under date(1). I.e. remove %Z, etc.
>how to put it together in one line or statement?
Jim's getline trick may work except you need to get it once per line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2011 12:08 AM
тАО03-17-2011 12:08 AM
Re: Adding time stamp to vmstat output
Then you may want this format: system("date +\"%x %T\"")
03/17/11 00:49:02
So:
vmstat 1 | awk '{system("X=$(date +\"%x %T\"); echo $X\\\c");print $0}'
Or you can just give up on handling the two lines in awk and then use sed(1) to join the two lines:
vmstat 1 | awk '{system("date +\"%x %T\"");print $0;}' | sed -n -e 'N; s/\^J/ /; p'
Where you enter that control-J by control-V then control-J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2011 02:36 AM
тАО03-17-2011 02:36 AM
Re: Adding time stamp to vmstat output
Dennis!
Your suggestion:vmstat 1 | awk '{system("X=$(date +\"%x %T\"); echo $X\\\c");print $0}' work perfectely.
But, now I just want the vmstat to shown only $1, $2, $12, $20 and $21, your suggestion, i.e.
vmstat 1 | awk '{system("X=$(date +\"%x %T\"); echo $X\\\c");print $0}'
F.R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2011 04:51 AM
тАО03-17-2011 04:51 AM
Re: Adding time stamp to vmstat output
> But, now I just want the vmstat to shown only $1, $2, $12, $20 and $21
This is AWK-101.
Change '$0' (which is the whole line buffer) to:
$1,$2,$12,$20,$21
The comma (',') will be substitute by the the output field separator, which by default is a space.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2011 07:45 PM - last edited on тАО08-04-2011 10:48 AM by Kevin_Paul
тАО03-17-2011 07:45 PM - last edited on тАО08-04-2011 10:48 AM by Kevin_Paul
Re: Adding time stamp to vmstat output
>Your suggestion: vmstat 1 | awk '{system("X=$(date +\"%x %T\"); echo $X\\\c");print $0}' work perfectly.
If you are happy with the answers you were given, please read the following about assigning points:
http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/kudos#kudos
>now I just want the vmstat to shown only $1, $2, $12, $20 and $21, your suggestion, i.e.
vmstat 1 | awk '{system("X=$(date +\"%x %T\"); echo $X\\\c");print $0}'
As JRF said, just replace that $0 by: $1, $2, $12, $20, $21
>JRF: $1,$2,$12,$20,$21
(I use a space above for readability.)
>ME: awk '{system("date +\"%x %T\"");print $0;}' | sed -n -e 'N; s/\^J/ /; p'
>Where you enter that control-J by ...
I spent a long time figuring this out and today I also needed to join pairs of lines.
I couldn't type ^J in vi, only the shell.
Then I just tried using "\n" and it magically worked. Too much overthinking. :-(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2011 11:42 PM
тАО03-17-2011 11:42 PM
Re: Adding time stamp to vmstat output
Dennis
I always assign points to you guys, the $1,... $21 did not work, but I am fine with $0, I can always extract the colums that I want to create a graph.
Thanks
F.R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2011 04:53 AM
тАО03-18-2011 04:53 AM
Re: Adding time stamp to vmstat output
> the $1,... $21 did not work
Exactly what did you do and exactly what was the result?
Simply saying "it didn't work" provides no useful information from which to help you further.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2011 07:06 AM
тАО03-18-2011 07:06 AM
Re: Adding time stamp to vmstat output
Hi
James:
This is the result:
prep03[140]/ #vmstat 1 | awk '{system("X=$(date +\"%x %T\"); echo $X\\\c");print $1,$2,$12,$20,$21}'
03/18/11 17:09:34procs memory
03/18/11 17:09:34r b sr
03/18/11 17:09:341 1 0
03/18/11 17:09:351 0 0
03/18/11 17:09:361 0 0
03/18/11 17:09:371 0 0
03/18/11 17:09:381 0 0
03/18/11 17:09:391 0 0
03/18/11 17:09:401 0 0
03/18/11 17:09:411 0 0
prep03[141]/ #
There is no space between seconds and r column, and also does not show the last 2 columns that are "us" and "sy"
F.R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2011 11:32 AM
тАО03-18-2011 11:32 AM
SolutionOops, add a space at the end of the date(1) format or one in the echo or one in print:
vmstat 1 | awk '{system("X=$(date +\"%x %T \"); echo $X\\\c");print $1,$2,$12,$20,$21}'
>does not show the last 2 columns that are "us" and "sy"
You need to use the original values I gave:
..; print $1, $2, $12, $16, $17
It seems your first reply and the second have different columns?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2011 06:51 AM
тАО03-21-2011 06:51 AM
Re: Adding time stamp to vmstat output
Dennis:
Your suggestion worked perfectely, I have already assign points.
F.R.