How can I write the output of pidstat
to a file for analysis later?
In sar
, you can monitor usage and write-out to a file for later analysis using the -o
argument. From the man page:
If multiple samples and multiple reports are desired, it is convenient to specify an output file for the sar command. Run the sar command as a
background process. The syntax for this is:
sar -o datafile interval count >/dev/null 2>&1 &
All data are captured in binary form and saved to a file (datafile). The data can then be selectively displayed with the sar command using the
-f option. Set the interval and count parameters to select count records at interval second intervals. If the count parameter is not set, all
the records saved in the file will be selected. Collection of data in this manner is useful to characterize system usage over a period of time
and determine peak usage hours.
...
-o [ filename ]
Save the readings in the file in binary form. Each reading is in a separate record. The default value of the filename parameter is the
current daily data file, the /var/log/sa/sadd file. The -o option is exclusive of the -f option. All the data available from the kernel
are saved in the file (in fact, sar calls its data collector sadc with the option "-S ALL". See sadc(8) manual page).
I need to monitor the resource usage of a specific process by name. The equivalent tool for this is pidstat
. Sadly, pidstat
has no -o
argument
[root@host ~]# pidstat -o pidstat.sadc -C "nginx" 1
Usage: pidstat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U [ <username> ] ] [ -u ]
[ -V ] [ -w ] [ -C <command> ] [ -p { <pid> [,...] | SELF | ALL } ]
[ -T { TASK | CHILD | ALL } ]
[root@host ~]#
How can I tell pidstat
to output to a file in sadc format so that it can be analyzed later with tools like kSAR?