X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fmigrate-3-4.px;h=31abae4b38f52c41c62f918972768a4e30a884c4;hb=c48289c6d14aadd1aca41a1c93122b5ba399bf0b;hp=b656f7fa7aada664f3fd2eb064479e7dd248959d;hpb=967ca89616bf9ccf246eeacf53fc84eb70743386;p=collectd.git diff --git a/contrib/migrate-3-4.px b/contrib/migrate-3-4.px index b656f7fa..31abae4b 100755 --- a/contrib/migrate-3-4.px +++ b/contrib/migrate-3-4.px @@ -107,6 +107,7 @@ our %TypeTranslate = our %TypeSplit = ( cpu => { from => [qw(user nice syst idle wait)], to => 'value', type_instance => [qw(user nice system idle wait)] }, + memory => { from => [qw(used free buffers cached)], to => 'value', type_instance => [qw(used free buffered cached)] }, nfs3_procedures => { from => [qw(null getattr lookup access readlink read write create mkdir symlink mknod remove rmdir rename link readdir readdirplus fsstat fsinfo pathconf commit)], to => 'value' }, @@ -124,14 +125,9 @@ our %TypeRename = 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 = (); @@ -152,7 +148,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'}; @@ -310,11 +310,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; - $file_dest{'plugin_instance'} = $file_dest{'type_instance'} + 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); + } + + 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 "./extractDS.px -i '$InDir/$orig_filename' -s 'rmerged' -s 'wmerged' -o '$OutDir/$dest_filename' -d 'read' -d 'write'\n"; + + $dest->{'type'} = 'disk_octets'; + $dest_filename = get_filename ($dest); + print "./extractDS.px -i '$InDir/$orig_filename' -s 'rbytes' -s 'wbytes' -o '$OutDir/$dest_filename' -d 'read' -d 'write'\n"; + + $dest->{'type'} = 'disk_ops'; + $dest_filename = get_filename ($dest); + print "./extractDS.px -i '$InDir/$orig_filename' -s 'rcount' -s 'wcount' -o '$OutDir/$dest_filename' -d 'read' -d 'write'\n"; + + $dest->{'type'} = 'disk_time'; + $dest_filename = get_filename ($dest); + print "./extractDS.px -i '$InDir/$orig_filename' -s 'rtime' -s 'wtime' -o '$OutDir/$dest_filename' -d 'read' -d 'write'\n"; +} + +sub exit_usage +{ + print <