Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- # Usage: run this script against the CSV output of the VMware ESXi vscsiStats
- # command-line utility.
- # $ perl collapse-vscsiStats-csv.pl inputfile.csv > outputfile.csv
- # Will produce output similar to:
- # worldid,min,max,mean,count,value,comparator,metric
- # 26602,512,65536,9980,3222,92,<=,512
- # 26602,512,65536,9980,3222,23,<=,1024
- # 26602,512,65536,9980,3222,10,<=,2048
- # Input that output into a spreadsheet program and process as needed.
- # License: public domain
- my ($state, $desc, $worldid, $disk_handle, $min, $max, $mean, $count, $details);
- my $DEBUG = 0;
- sub reset_vars {
- $state = "OUTSIDE";
- $desc = "?";
- $worldid = "?";
- $disk_handle = "?";
- $min = "?";
- $max = "?";
- $mean = "?";
- $count = "?";
- $details = [];
- };
- sub emit_header {
- print "worldid,min,max,mean,count,value,comparator,metric\n";
- }
- sub emit_details {
- for my $detail (@$details) {
- my ($value, $comparator, $metric) = ($detail->[0], $detail->[1], $detail->[2]);
- print "$worldid,$min,$max,$mean,$count,$value,$comparator,$metric\n";
- }
- }
- sub debug_state {
- print "DEBUG: state = '$state', input = '$_'\n" if ($DEBUG);
- }
- reset_vars();
- emit_header();
- while (<>) {
- chomp;
- if ($state eq "OUTSIDE") {
- debug_state();
- if (m/Histogram: (.+) worldGroupID : (\d+), virtual disk handleID : (\d+) {/) {
- ($desc, $worldid, $disk_handle) = ($1, $2, $3);
- $state = "AGGREGATES";
- }
- else {
- die "Unrecognized input, state='$state', input='$_'";
- }
- }
- elsif ($state eq "AGGREGATES") {
- debug_state();
- if (m/min : (-?\d+)/) {
- $min = $1;
- }
- elsif (m/max : (-?\d+)/) {
- $max = $1;
- }
- elsif (m/mean : (-?\d+)/) {
- $mean = $1;
- }
- elsif (m/count : (-?\d+)/) {
- $count = $1;
- }
- elsif (m/\s+{$/) {
- $state = "DETAILS";
- }
- else {
- die "Unrecognized input, state='$state', input='$_'";
- }
- }
- elsif ($state eq "DETAILS") {
- debug_state();
- if (m/^\s+(-?\d+)\s+\(([<=>]{1,3})\s+(-?\d+)\)$/) {
- push(@{$details}, [$1, $2, $3]);
- }
- elsif (m/\s*}$/) {
- $state = "END_DETAILS";
- }
- else {
- die "Unrecognized input, state='$state', input='$_'";
- }
- }
- elsif ($state eq "END_DETAILS") {
- debug_state();
- if (m/^}$/) {
- emit_details();
- reset_vars();
- }
- else {
- die "Unrecognized input, state='$state', input='$_'";
- }
- }
- else {
- die "Unrecognized input, state='$state', input='$_'";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement