输出乱了?

比如vmstat命令, 输出歪歪扭扭的, 强迫症简直不能忍啊, 而且看个指标还得先对齐下.

1
2
3
4
5
6
7
8
➜  ~  vmstat 1 
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 4577556 281532 3674532 0 0 64 36 192 784 5 1 93 1 0
0 0 0 4577992 281532 3674552 0 0 0 0 417 1089 1 1 98 0 0
0 0 0 4577960 281540 3674532 0 0 0 44 401 1105 1 0 98 1 0
2 0 0 4577960 281540 3674548 0 0 0 0 307 834 1 0 99 0 0
0 0 0 4577960 281548 3674548 0 0 0 48 318 773 1 0 99 1 0

解决方案

其实, 加个column就好了

1
2
3
4
5
6
7
8
➜  ~  vmstat 1 5 | column -t
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
5 0 0 4565016 281996 3675732 0 0 63 36 192 784 5 1 93 1 0
0 0 0 4564836 281996 3675756 0 0 0 0 345 805 1 0 99 1 0
0 0 0 4564744 282004 3675736 0 0 0 88 489 1305 1 0 98 0 0
2 0 0 4565456 282004 3675736 0 0 0 0 401 1042 1 0 99 0 0
0 0 0 4566400 282016 3675736 0 0 0 132 823 2357 1 1 98 1 0

整整齐齐啊, 神清气爽, 不过如果使用vmstat 1 | column -t就会没有任何输出, vmstat 1相当于每一秒输出一行, column -t会一直傻傻地等着, 所以什么都看不到.

看下manual:

1
2
-t      Determine the number of columns the input contains and create a table.  Columns are delimited with whitespace, by default, or
with the characters supplied using the -s option. Useful for pretty-printing displays.

为了形式上的好看, 还是忍一忍吧.

行太长了?

有的时候会遇到另外一种情况, 就是一行太长了, 这时候满屏都是花的, 比如下面这个:

终端中显示的是杂乱的, 但是整个复制出来就神奇的变好了(注意, 不要打开text wrapping)

1
2
3
4
5
6
7
8
9
10
11
12
[qisheng.li@l-hpbreezep20.h.cn2 ~]$ cat /proc/softirqs 
CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 CPU8 CPU9 CPU10 CPU11 CPU12 CPU13 CPU14 CPU15 CPU16 CPU17 CPU18 CPU19 CPU20 CPU21 CPU22 CPU23 CPU24 CPU25 CPU26 CPU27 CPU28 CPU29 CPU30 CPU31
HI: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
TIMER: 43050851 44411905 43919992 42442914 43015809 42846597 42569992 41861589 48809346 43382044 43304198 43899929 46604992 49141675 43598221 44605969 36416696 40245419 43755210 38241174 40310482 36846535 40234221 36373316 37261964 40299828 40815229 48124964 38746814 40687667 39654342 44596933
NET_TX: 159131 57649 987 947 1124 960 887 897 53415 44445 907 982 5556 31456 921 928 604 665 58417 565 4375 615 16263 532 658 573 15546 23825 560 3679 537 11125
NET_RX: 54739232 104971608 175092 144098 287613 181637 274003 105699 137866529 37821843 114651 5258 31830654 74227300 149144 41791 32428 12501 136630455 80495 49754625 158541 30734583 3512 2284 2796 35459431 131330367 78501 89945954 50223 117038378
BLOCK: 81587 139726 179707 144663 159758 190601 132768 276230 72676 287984 130253 323938 152578 206060 141233 141074 193578 251093 448 131136 62687 150827 194672 388017 81603 163935 175096 166935 330730 47293 161579 54246
BLOCK_IOPOLL: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TASKLET: 1675397 3309130 9569 4022 2764 5093 4897 10826 4444030 1454707 1496 286 1048531 2576975 811 2119 442 417 4300523 260 1552321 418 1015839 10748 510 218 1121876 4256900 115 3020283 287 3986726
SCHED: 15007043 12859515 11501051 11259112 10939612 10774900 10462556 10131094 14234569 10072702 9984370 10190600 11242845 12149746 9940021 10177032 6683735 7652871 10904532 7456442 9226435 7306446 8605291 6707082 6480350 7086698 8286905 11682767 7195542 8529887 7447246 10396247
HRTIMER: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RCU: 17206657 17427121 18015842 17756453 17731002 17874141 17772044 17467329 18480130 17666877 17975799 18291442 18971854 19696035 18311040 18486331 14653377 16665048 16695739 15810275 15832142 14999192 15912229 14669770 14782425 16825467 16554916 18592285 15670613 15416856 16010390 16910501

wtf!!!

这时候就需要结合cut来发挥作用了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[qisheng.li@l-hpbreezep20.h.cn2 ~]$ cat /proc/softirqs | column -t  | cut -c -160
CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 CPU8 CPU9 CPU10 CPU11 CPU12 CPU13 CPU14 CPU
HI: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6
TIMER: 42897374 44265424 43773013 42294893 42872190 42703730 42422299 41715918 48651925 43219235 43155865 43751531 46455390 48993651 434
NET_TX: 158851 57164 981 939 1119 956 882 894 53297 43884 904 980 5551 31451 917
NET_RX: 54266774 104535675 175086 144094 287558 181540 273997 105609 137397792 37471099 114548 5252 31830477 74227296 149
BLOCK: 81585 139726 179707 144265 159758 190245 132562 275983 72656 287710 130180 323916 152544 205625 140
BLOCK_IOPOLL: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TASKLET: 1661705 3295175 9569 4022 2764 5093 4897 10826 4429925 1442145 1496 286 1048531 2576975 811
SCHED: 14954535 12813884 11459036 11217505 10901019 10736479 10424577 10093709 14202602 10037804 9955899 10162495 11215015 12123529 991
HRTIMER: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RCU: 17145747 17366996 17952484 17693839 17671645 17814624 17709279 17405994 18416537 17600989 17910864 18226002 18906471 19629970 182


[qisheng.li@l-hpbreezep20.h.cn2 ~]$ cat /proc/softirqs | column -t | cut -c 150-300
U14 CPU15 CPU16 CPU17 CPU18 CPU19 CPU20 CPU21 CPU22 CPU23 CPU24 CPU25 CPU26 CPU27 CPU28 C
6 0 0 0 0 0 0 0 0 0 0 0 0 0 0
030995 43485667 44493659 36326549 40157402 43631283 38151873 40219806 36756938 40144515 36283732 37161284 40199408 40717545 48006972 3
451 917 925 601 662 58258 560 4373 614 16262 532 656 572 15544 23806 5
227296 149142 41791 32391 12499 136276000 80492 49754624 158467 30734581 3506 2281 2795 35459426 131010842 7
5644 140738 141074 192744 251010 448 130632 62646 150826 193938 387975 81598 163807 174560 166894 3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
76975 811 2119 442 417 4290461 260 1552321 418 1015839 10748 510 218 1121876 4247160 1
130763 9918727 10155044 6665114 7634478 10872508 7435459 9208357 7287842 8584087 6687254 6464581 7069601 8268941 11657561 7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
645462 18260707 18436150 14614558 16626358 16648198 15772191 15794569 14960694 15874249 14631009 14737925 16781205 16511913 18544088 1

[qisheng.li@l-hpbreezep20.h.cn2 ~]$ cat /proc/softirqs | column -t | cut -c 290-
PU28 CPU29 CPU30 CPU31
0 0 1 0
8025761 38667794 40583340 39575602 44506422
3810 555 3672 535 11121
31059150 78501 89665808 50166 116771524
66900 330730 47290 161396 54232
0 0 0 0
248714 115 3012042 287 3978676
1661902 7180114 8511025 7432308 10374288
0 0 0 0
8550398 15634808 15373695 15974460 16871666

整整齐齐才好看啊!
唉, cpu太多也是麻烦啊