When you type a command on the Windows command line, the output from the command is displayed in the command prompt window. For some commands, the output can be several rows long and sometimes longer than the height of the command window, causing you to scroll to view all of the output.
![Vmstat loop Vmstat loop](http://rprogramming.net/wp-content/uploads/2013/03/R-HTML-Output-Example.jpg)
Linux distributions provides a lot of tools in order to monitor system performance.
vmstat
is one of the most used tool for system performance monitoring. vmstat
can collect and report information about memory, cpu, swap, io in a detailed way. In this tutorial we will examine the output of the vmstat
and different features and options of it.We will start by using
vmstat
command without any option. This will list general statistics and information about system resource usage.List System Resource Usage
We can see that there is 5 main column.
procs
display information about processes.memory
display information about memory metricsswpd
provides avaible swap sizefree
provides unused memory sizebuff
provides buffered memory sizecache
provides cached memory size
swap
provides swap related information but in these days it is not used so much.io
provides disk related informatinbi
block input shows data block count read from block devicesbo
block output shows block count sent to block devices
system
provides interrup and context switch information which is related with CPUin
number of interrupts per secondcs
number of context switches per second
cpu
provides CPU usage informationus
time spent user space operations or user timeid
time spent idlesy
time spent system operationswa
time spent waiting for IO.st
time spent from virtual machine
By default
vmstat
command is non interactive. It will print information just one time after called and then quit. If we need to it continuously and print command output at given intervals we need to provide the interval as seconds after command. We will print at 5 second interval in this example.Print Output At Specified Interval Interactively
As the output printed one or multiple times we may need to know related time. We can print given information time by printing time stamp. We need to provide
-t
option for this. Time column will be added as last column after cpu column.Print Timestamp
Active memory is part or size of the memory which is actively used currently running processes. Inactive memory is part or size of the memory where died or non existing processes. We will use
-a
option for active and inactive memory. We can see that memory
column provides inact
and active
columns.List Memory Active and Inactive
As writing disk and disk topology is a complex area related information can be printed with the
-d
option. Following information will be provided by this option. echo '
Reads
show read related informationtotal
shows successfully completed total readmerged
shows grouped readssectors
shows sector readsms
shows milliseconds spent for reads
Writes
show write related informationtotal
shows successfully completed total readmerged
shows grouped readssectors
shows sector readsms
shows milliseconds spent for reads
IO
show currently active IO operations informationcur
I/O in progresss
seconds spent for I/O
We can also print disk related I/O statistics in summary or brief mode with
-D
option.View Disk I/O Statics Summary
During usage of all options the default metric for memory is byte. This will lower readability. We can make metrics more readable or human readable with
-S M
option which will set Megabyte as metric.Usage Megabyte As Metric
We can use
-s
option in order to print event counters and memory statistics.![How To Write Vmstat Output To A File How To Write Vmstat Output To A File](/uploads/1/2/5/8/125876375/796804707.png)
List Event Counters and Memory Statics
Out-File is a cmdlet provided by Powershell core libraries. This cmdlet provides features to write created output into a file in the file system. In this tutorial we will look different ways to write output into a file with out-file cmdlet.
One of the basic usage scenario of out-file is writing the output into a file without changing it. In this example we will write the output of
Get-Process
command into a file named process.txt
by piping it. The file name can be specified as full path like C:userprocess.txt
Write Into A File
If we just want to add new lines and do not want to remove existing data we should add new data with
-Append
option like below.We can write created output into a file is CSV format. CSV format delimits the columns with comma. We will use
Export-Csv
cmdlet for this operation. This will take more time than raw write into file because row will be separated and each column will be delimited with command.Write As CSV
Another most used feature is while writing output into a file printing in the console too. This will provide verbose information about output. We will use
Tee-Object
which is inherited from Linux operating system.In this example we get
dir
command output into console and file named dirs.txt
Write Both File and Console