Advertisement
Guest User

jhopkins

a guest
Sep 2nd, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. # Usage: run this script against the CSV output of the VMware ESXi vscsiStats
  6. # command-line utility.
  7. # $ perl collapse-vscsiStats-csv.pl inputfile.csv > outputfile.csv
  8. # Will produce output similar to:
  9.  
  10. # worldid,min,max,mean,count,value,comparator,metric
  11. # 26602,512,65536,9980,3222,92,<=,512
  12. # 26602,512,65536,9980,3222,23,<=,1024
  13. # 26602,512,65536,9980,3222,10,<=,2048
  14.  
  15. # Input that output into a spreadsheet program and process as needed.
  16.  
  17. # License: public domain
  18.  
  19.  
  20. my ($state, $desc, $worldid, $disk_handle, $min, $max, $mean, $count, $details);
  21.  
  22. my $DEBUG = 0;
  23.  
  24. sub reset_vars {
  25. $state = "OUTSIDE";
  26. $desc = "?";
  27. $worldid = "?";
  28. $disk_handle = "?";
  29. $min = "?";
  30. $max = "?";
  31. $mean = "?";
  32. $count = "?";
  33. $details = [];
  34. };
  35.  
  36. sub emit_header {
  37. print "worldid,min,max,mean,count,value,comparator,metric\n";
  38. }
  39.  
  40. sub emit_details {
  41. for my $detail (@$details) {
  42. my ($value, $comparator, $metric) = ($detail->[0], $detail->[1], $detail->[2]);
  43. print "$worldid,$min,$max,$mean,$count,$value,$comparator,$metric\n";
  44. }
  45. }
  46.  
  47. sub debug_state {
  48. print "DEBUG: state = '$state', input = '$_'\n" if ($DEBUG);
  49. }
  50.  
  51. reset_vars();
  52. emit_header();
  53.  
  54. while (<>) {
  55. chomp;
  56. if ($state eq "OUTSIDE") {
  57. debug_state();
  58. if (m/Histogram: (.+) worldGroupID : (\d+), virtual disk handleID : (\d+) {/) {
  59. ($desc, $worldid, $disk_handle) = ($1, $2, $3);
  60. $state = "AGGREGATES";
  61. }
  62. else {
  63. die "Unrecognized input, state='$state', input='$_'";
  64. }
  65. }
  66. elsif ($state eq "AGGREGATES") {
  67. debug_state();
  68. if (m/min : (-?\d+)/) {
  69. $min = $1;
  70. }
  71. elsif (m/max : (-?\d+)/) {
  72. $max = $1;
  73. }
  74. elsif (m/mean : (-?\d+)/) {
  75. $mean = $1;
  76. }
  77. elsif (m/count : (-?\d+)/) {
  78. $count = $1;
  79. }
  80. elsif (m/\s+{$/) {
  81. $state = "DETAILS";
  82. }
  83. else {
  84. die "Unrecognized input, state='$state', input='$_'";
  85. }
  86. }
  87. elsif ($state eq "DETAILS") {
  88. debug_state();
  89. if (m/^\s+(-?\d+)\s+\(([<=>]{1,3})\s+(-?\d+)\)$/) {
  90. push(@{$details}, [$1, $2, $3]);
  91. }
  92. elsif (m/\s*}$/) {
  93. $state = "END_DETAILS";
  94. }
  95. else {
  96. die "Unrecognized input, state='$state', input='$_'";
  97. }
  98. }
  99. elsif ($state eq "END_DETAILS") {
  100. debug_state();
  101. if (m/^}$/) {
  102. emit_details();
  103. reset_vars();
  104. }
  105. else {
  106. die "Unrecognized input, state='$state', input='$_'";
  107. }
  108. }
  109. else {
  110. die "Unrecognized input, state='$state', input='$_'";
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement