如何将 pidstat 输出写入 sadc 文件以供稍后分析(sar)

如何将 pidstat 输出写入 sadc 文件以供稍后分析(sar)

我如何将输出写入pidstat文件以供稍后分析?

在 中sar,您可以使用参数监视使用情况并将其写入文件以供以后分析-o。从手册页中:

       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).

我需要按名称监视特定进程的资源使用情况。等效工具是pidstat。遗憾的是,pidstat没有-o参数

[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 ~]# 

我怎样才能告诉pidstat它输出到 sadc 格式的文件,以便稍后可以使用 kSAR 之类的工具进行分析?

答案1

您可以通过管道将其输出附加到文件中,如下所示:

pidstat 3 -G nginx >> out.log

相关内容