Question : La sortie Vmstat n'affiche pas la date et l'heure, ce qui est pénible lorsque vous essayez de stocker la sortie vmstat pour effectuer une analyse des performances.
Alors, comment ajouter un horodatage à la sortie Linux vmstat ?
Réponse : Vous pouvez afficher l'horodatage sur chaque ligne de la sortie de la commande vmstat en utilisant un simple script perl comme indiqué ci-dessous.
Sortie Vmstat par défaut (sans horodatage)
$ vmstat 1 5 procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 33308 450080 59020 6757044 1 1 551 148 1 6 26 9 60 5 0 0 33308 449960 59020 6757044 0 0 0 0 1068 1576 1 1 98 0 1 0 33308 453928 59020 6757044 0 0 0 48 1049 1628 2 1 97 0 0 0 33308 454120 59020 6757044 0 0 0 0 1034 1663 2 1 96 0 0 0 33308 454112 59020 6757044 0 0 0 0 1025 1535 1 1 98 0
Sortie Vmstat avec horodatage
Créez le fichier timestamp.pl simple suivant
$ vi timestamp.pl #!/usr/bin/perl while (<>) { print localtime() . ": $_"; }
Dirigez maintenant la sortie de la commande vmstat vers ce timestamp.pl pour afficher l'horodatage comme indiqué ci-dessous.
$ vmstat 1 5 | timestamp.pl Sat Aug 22 20:50:36 2009: procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- Sat Aug 22 20:50:36 2009: r b swpd free buff cache si so bi bo in cs us sy id wa Sat Aug 22 20:50:36 2009: 2 0 33308 452080 59084 6761140 1 1 551 148 1 6 26 9 60 5 Sat Aug 22 20:50:37 2009: 0 0 33308 454368 59084 6761140 0 0 0 0 1028 1713 2 1 96 0 Sat Aug 22 20:50:38 2009: 0 0 33308 454368 59084 6761140 0 0 0 0 1010 1432 0 0 100 0 Sat Aug 22 20:50:39 2009: 0 0 33308 454368 59084 6761140 0 0 0 12 1021 1481 1 0 99 0 Sat Aug 22 20:50:40 2009: 0 0 33308 457184 59084 6761140 0 0 0 0 1029 1549 1 1 98 0