turbostat: Fix parsing warnings
[collectd.git] / contrib / migrate-3-4.px
index 467c46b..ed19a7b 100755 (executable)
@@ -95,6 +95,7 @@ our %Subdirs =
 our %TypeTranslate =
 (
        cpu => sub { $_ = shift; $_->{'plugin_instance'} = $_->{'type_instance'}; $_->{'type_instance'} = undef; $_; },
+       hddtemp => sub { $_ = shift; $_->{'plugin'} = 'hddtemp'; $_->{'type'} = 'temperature'; $_->{'type_instance'} = $_->{'type_instance'}; $_; },
        if_errors => sub { $_ = shift; $_->{'type_instance'} = $_->{'plugin_instance'}; $_->{'plugin_instance'} = undef; $_; },
        if_packets => sub { $_ = shift; $_->{'type_instance'} = $_->{'plugin_instance'}; $_->{'plugin_instance'} = undef; $_; },
        nfs2_procedures => sub { $_ = shift; @$_{qw(plugin plugin_instance type type_instance)} = ('nfs', 'v2' . $_->{'type_instance'}, 'nfs_procedure', undef); $_; },
@@ -120,19 +121,15 @@ our %TypeSplit =
 
 our %TypeRename =
 (
-       traffic => { from => [qw(incoming outgoing)], to => [qw(rx tx)] }
+       traffic => { from => [qw(incoming outgoing)], to => [qw(rx tx)] },
+       vs_processes => { from => [qw(total)], to => [qw(value)] },
 );
 
 GetOptions ("indir|i=s" => \$InDir,
        "outdir|o=s" => \$OutDir,
-       "hostname=s" => \$Hostname) or exit (1);
+       "hostname=s" => \$Hostname) or exit_usage ();
 
 die "No such directory: $InDir" if (!-d $InDir);
-if (!-e $OutDir)
-{
-       mkdir ($OutDir) or die ("mkdir ($OutDir): $!");
-}
-die "Not a directory: $OutDir" if (!-d $OutDir);
 
 our @Files = ();
 our %OutDirs = ();
@@ -153,7 +150,11 @@ for (@Files)
                $OutDirs{$dest_directory} = 1;
        }
 
-       if (exists ($TypeSplit{$orig->{'type'}}))
+       if (($orig->{'type'} eq 'disk') || ($orig->{'type'} eq 'partition'))
+       {
+               special_disk ($orig_filename, $orig, $dest_filename, $dest);
+       }
+       elsif (exists ($TypeSplit{$orig->{'type'}}))
        {
                my $src_dses = $TypeSplit{$orig->{'type'}}->{'from'};
                my $dst_ds = $TypeSplit{$orig->{'type'}}->{'to'};
@@ -166,25 +167,26 @@ for (@Files)
                        my $src_ds = $src_dses->[$i];
                        $dest->{'type_instance'} = $type_instances->[$i];
                        $dest_filename = get_filename ($dest);
-                       print "./extractDS.px -i '$InDir/$orig_filename' -s '$src_ds' -o '$OutDir/$dest_filename' -d '$dst_ds'\n";
+                       print "./rrd_filter.px -i '$InDir/$orig_filename' -m '${src_ds}:${dst_ds}' -o '$OutDir/$dest_filename'\n";
                }
        }
-       elsif (exists ($TypeRename{$orig->{'type'}}))
+       else
+       {
+               print "cp '$InDir/$orig_filename' '$OutDir/$dest_filename'\n";
+       }
+
+       if (exists ($TypeRename{$orig->{'type'}}))
        {
                my $src_dses = $TypeRename{$orig->{'type'}}->{'from'};
                my $dst_dses = $TypeRename{$orig->{'type'}}->{'to'};
-               my @sed_prog = ();
 
+               print "rrdtool tune '$OutDir/$dest_filename'";
                for (my $i = 0; $i < @$src_dses; $i++)
                {
-                       push (@sed_prog, 's/^' . $src_dses->[$i] . '$/' . $dst_dses->[$i] . '/g;');
+                       print " --data-source-rename "
+                               . $src_dses->[$i] . ':' . $dst_dses->[$i];
                }
-
-               print "rrdtool dump '$InDir/$orig_filename' | sed -e '" . join (' ', @sed_prog) . "' | rrdtool restore - '$OutDir/$dest_filename'\n";
-       }
-       else
-       {
-               print "cp '$InDir/$orig_filename' '$OutDir/$dest_filename'\n";
+               print "\n";
        }
 }
 
@@ -311,11 +313,75 @@ sub find_files
        return (@files);
 } # find_files
 
-sub special_cpu
+{my $cache;
+sub _special_disk_instance
 {
-       my %file_orig = @_;
-       my %file_dest = %file_orig;
+       my $orig_instance = shift;
+
+       if (!defined ($cache))
+       {
+               my $fh;
+               open ($fh, "< /proc/diskstats") or die ("open (/proc/diststats): $!");
+
+               $cache = {};
+               while (my $line = <$fh>)
+               {
+                       chomp ($line);
+                       my @fields = split (' ', $line);
+                       $cache->{$fields[0] . '-' . $fields[1]} = $fields[2];
+               }
+               close ($fh);
+       }
 
-       $file_dest{'plugin_instance'} = $file_dest{'type_instance'}
+       return (defined ($cache->{$orig_instance})
+               ? $cache->{$orig_instance}
+               : $orig_instance);
+}}
 
+sub special_disk
+{
+       my $orig_filename = shift;
+       my $orig = shift;
+       my $dest_filename = shift;
+       my $dest = shift;
+       my $dest_directory;
+
+       $dest->{'type_instance'} = undef;
+       $dest->{'plugin_instance'} = _special_disk_instance ($orig->{'type_instance'});
+       if ($dest->{'plugin_instance'} eq $orig->{'type_instance'})
+       {
+               print qq(echo "You may need to rename these files" >&2\n);
+       }
+
+       $dest->{'type'} = 'disk_merged';
+       $dest_filename = get_filename ($dest);
+
+       $dest_directory = dirname ($dest_filename);
+       if (!exists ($OutDirs{$dest_directory}))
+       {
+               print "[ -d '$OutDir/$dest_directory' ] || mkdir -p '$OutDir/$dest_directory'\n";
+               $OutDirs{$dest_directory} = 1;
+       }
+
+       print "./rrd_filter.px -i '$InDir/$orig_filename' -m 'rmerged:read' -m 'wmerged:write' -o '$OutDir/$dest_filename'\n";
+
+       $dest->{'type'} = 'disk_octets';
+       $dest_filename = get_filename ($dest);
+       print "./rrd_filter.px -i '$InDir/$orig_filename' -m 'rbytes:read' -m 'wbytes:write' -o '$OutDir/$dest_filename'\n";
+
+       $dest->{'type'} = 'disk_ops';
+       $dest_filename = get_filename ($dest);
+       print "./rrd_filter.px -i '$InDir/$orig_filename' -m 'rcount:read' -m 'wcount:write' -o '$OutDir/$dest_filename'\n";
+
+       $dest->{'type'} = 'disk_time';
+       $dest_filename = get_filename ($dest);
+       print "./rrd_filter.px -i '$InDir/$orig_filename' -m 'rtime:read' -m 'wtime:write' -o '$OutDir/$dest_filename'\n";
+}
+
+sub exit_usage
+{
+       print <<EOF;
+Usage: $0 [-i indir] [-o outdir] [--hostname myhostname]
+EOF
+       exit (1);
 }