$vmstat -n [delay [count]] | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'>{file path}
Example: vmstat -n 1 10 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'>/tmp/vmstat.csv
The given command line combines the output of the vmstat command with awk to create a log file that records the current timestamp along with the system statistics. Here's how it works:
vmstat -n [delay [count]]: Thevmstatcommand is used to monitor virtual memory statistics and system performance. The-nflag disables the header output, providing only data. The command accepts optional arguments:delay: The time interval, in seconds, between data samples.count: The number of data samples to collect.
awk '{now=strftime("%Y-%m-%d %T "); print now $0}': This part of the command processes each line of thevmstatoutput:now=strftime("%Y-%m-%d %T "): Thisawkcode creates a timestamp in the formatYear-Month-Day Hour:Minute:Second.print now $0: This prints the current timestamp followed by the original line from thevmstatoutput.
>{file path}: The output of the command, which is the timestampedvmstatdata, is redirected to the specified file path. For example,/tmp/vmstat.txt.
No comments:
Post a Comment