从 SAR 中获取月度数据并显示干净的结果

Grabbing monthly data from SAR and showing clean results

我正在尝试在 bash 中写一些东西来显示 sar 本月记录的数据。到目前为止我所拥有的是

for file in /var/log/sa/sa??; do sar -q -f "$file" | grep "^.\{35\}1[1-9][0-9]"; done

这显示了我想要的数据,它显示了负载超过 110 的任何时间,问题是它只显示了发生这种情况的时间,而不是日期。这是一些示例输出:

# for file in /var/log/sa/sa??; do sar -q -f "$file" | grep "^.\{35\}1[1-9][0-9]"; done
02:57:01 AM        72      1318    142.61     54.60     29.89
02:58:19 AM       137      1366    135.52     71.45     37.77
01:20:10 AM       205      1246    112.29     55.22     38.40
01:22:02 AM       109      1260    195.54    102.06     57.06
01:23:01 AM        63      1219    128.44    100.63     59.44
01:26:02 AM       113      1380    120.67     99.85     65.70
01:27:02 AM       133      1371    133.72    107.76     70.58
01:28:12 AM       178      1280    120.40    108.98     73.71
03:50:02 AM       121      1443    189.25    168.81     82.88
05:56:17 AM       208      1231    113.36     41.01     20.65
05:57:06 AM       145      1227    128.45     56.78     27.11
05:58:06 AM       160      1265    149.87     74.99     35.18
05:59:01 AM       136      1370    179.49     95.48     44.45
06:00:01 AM        93      1404    156.11    105.23     51.06
06:01:01 AM        34      1310    119.41    105.12     54.48
10:07:04 AM       169      1524    110.05     82.17     55.00
10:08:01 AM       105      1466    122.00     91.18     59.82
02:26:10 AM       181      1276    149.12     62.34     34.25
02:27:05 AM       137      1327    169.27     81.70     42.43
12:02:01 AM        49      1326    110.65     57.31     39.68
07:29:02 PM       136      1279    116.35     47.18     23.75
07:30:01 PM       124      1378    116.51     58.86     29.10
07:31:03 PM        93      1200    123.80     71.66     35.50
07:32:01 PM       113      1324    138.65     84.84     42.10
07:33:01 PM        76      1411    119.29     89.63     46.45
08:55:08 PM       126      1362    112.14     64.36     42.02
08:56:01 PM        84      1571    166.07     87.82     51.24
09:04:01 PM        91      1404    146.57     97.72     65.50
09:19:07 PM        87      1250    112.83     48.03     46.85
09:40:01 PM        87      1290    118.10     72.67     57.32
09:46:03 PM       113      1215    110.39     71.43     59.69
11:53:03 PM       101      1341    116.01     52.90     37.79
02:04:10 AM       257      1382    139.37     61.42     43.58
08:52:01 AM        84      1541    112.46     59.07     39.06
09:44:01 AM       111      1579    161.68     77.07     45.34
09:46:01 PM       105      1348    111.06     65.09     45.65
10:31:01 PM       120      1410    124.08     61.14     44.57
10:35:01 PM        83      1515    115.66     79.33     54.93
01:06:01 AM       137      1379    114.34     57.90     41.89
01:56:08 AM       216      1290    113.14     59.06     40.92
02:06:01 AM       135      1474    126.60     79.41     55.15
02:28:35 AM       267      1225    151.81     69.58     59.47
02:29:01 AM        97      1360    144.64     76.03     61.96
02:41:02 AM       144      1279    133.04     60.48     52.53
10:06:07 AM       304      1415    128.59     72.30     51.68
12:27:01 AM       121      1399    112.99     54.63     40.77
03:20:01 AM       149      1450    120.17     58.10     36.52
10:11:01 PM       136      1449    120.49     70.64     48.13
10:12:02 PM       121      1468    143.77     87.26     55.30
10:29:01 PM        64      1362    116.96     60.23     49.71
04:07:37 AM       170      1307    110.13     46.58     35.07
03:29:01 AM        97      1217    120.40     57.09     33.87
03:30:04 AM       139      1347    165.79     81.46     43.68
03:31:05 AM       105      1379    159.32     96.09     51.29
03:32:01 AM       194      1294    153.11    105.79     57.25

我需要做的是要么在每组时间上面写上文件名,要么想办法从 sar 中获取完整的日期(从阅读 man 看来这是不可能的。) 任何帮助,将不胜感激。

所需输出的示例类似于

/var/log/sa/sa15
2:57:01 AM        72      1318    142.61     54.60     29.89
02:58:19 AM       137      1366    135.52     71.45     37.77
01:20:10 AM       205      1246    112.29     55.22     38.40
01:22:02 AM       109      1260    195.54    102.06     57.06
01:23:01 AM        63      1219    128.44    100.63     59.44
01:26:02 AM       113      1380    120.67     99.85     65.70
01:27:02 AM       133      1371    133.72    107.76     70.58
01:28:12 AM       178      1280    120.40    108.98     73.71
03:50:02 AM       121      1443    189.25    168.81     82.88
05:56:17 AM       208      1231    113.36     41.01     20.65
05:57:06 AM       145      1227    128.45     56.78     27.11
05:58:06 AM       160      1265    149.87     74.99     35.18
05:59:01 AM       136      1370    179.49     95.48     44.45
06:00:01 AM        93      1404    156.11    105.23     51.06
/var/log/sa/sa17
06:01:01 AM        34      1310    119.41    105.12     54.48
10:07:04 AM       169      1524    110.05     82.17     55.00
10:08:01 AM       105      1466    122.00     91.18     59.82
02:26:10 AM       181      1276    149.12     62.34     34.25
02:27:05 AM       137      1327    169.27     81.70     42.43
12:02:01 AM        49      1326    110.65     57.31     39.68
07:29:02 PM       136      1279    116.35     47.18     23.75
07:30:01 PM       124      1378    116.51     58.86     29.10
07:31:03 PM        93      1200    123.80     71.66     35.50
07:32:01 PM       113      1324    138.65     84.84     42.10
07:33:01 PM        76      1411    119.29     89.63     46.45
08:55:08 PM       126      1362    112.14     64.36     42.02
08:56:01 PM        84      1571    166.07     87.82     51.24
09:04:01 PM        91      1404    146.57     97.72     65.50
09:19:07 PM        87      1250    112.83     48.03     46.85
09:40:01 PM        87      1290    118.10     72.67     57.32
09:46:03 PM       113      1215    110.39     71.43     59.69
11:53:03 PM       101      1341    116.01     52.90     37.79
02:04:10 AM       257      1382    139.37     61.42     43.58
08:52:01 AM        84      1541    112.46     59.07     39.06
09:44:01 AM       111      1579    161.68     77.07     45.34
/var/log/sa/sa19
09:46:01 PM       105      1348    111.06     65.09     45.65
10:31:01 PM       120      1410    124.08     61.14     44.57
10:35:01 PM        83      1515    115.66     79.33     54.93
01:06:01 AM       137      1379    114.34     57.90     41.89
01:56:08 AM       216      1290    113.14     59.06     40.92
02:06:01 AM       135      1474    126.60     79.41     55.15
02:28:35 AM       267      1225    151.81     69.58     59.47
02:29:01 AM        97      1360    144.64     76.03     61.96
02:41:02 AM       144      1279    133.04     60.48     52.53
10:06:07 AM       304      1415    128.59     72.30     51.68
12:27:01 AM       121      1399    112.99     54.63     40.77
03:20:01 AM       149      1450    120.17     58.10     36.52
/var/log/sa/sa20
10:11:01 PM       136      1449    120.49     70.64     48.13
10:12:02 PM       121      1468    143.77     87.26     55.30
10:29:01 PM        64      1362    116.96     60.23     49.71
04:07:37 AM       170      1307    110.13     46.58     35.07
03:29:01 AM        97      1217    120.40     57.09     33.87
03:30:04 AM       139      1347    165.79     81.46     43.68
03:31:05 AM       105      1379    159.32     96.09     51.29
03:32:01 AM       194      1294    153.11    105.79     57.25

请注意,理想情况下,它会列出从中提取数据的文件名,以便于跟踪。

替换

do sar

来自

do echo "$file"; sar

在 sar 输出之前打印文件名“$file”。