如何將 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

相關內容