Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --syncstats option #760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion syncoid
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use strict;
use warnings;
use Data::Dumper;
use Getopt::Long qw(:config auto_version auto_help);
use JSON::PP;
use Pod::Usage;
use Time::HiRes;
use Time::Local;
use Sys::Hostname;
use Capture::Tiny ':all';
Expand All @@ -22,7 +24,7 @@ my $pvoptions = "-p -t -e -r -b";
# TODO: Merge into a single "sshflags" option?
my %args = ('sshkey' => '', 'sshport' => '', 'sshcipher' => '', 'sshoption' => [], 'target-bwlimit' => '', 'source-bwlimit' => '');
GetOptions(\%args, "no-command-checks", "monitor-version", "compress=s", "dumpsnaps", "recursive|r", "sendoptions=s", "recvoptions=s",
"source-bwlimit=s", "target-bwlimit=s", "sshkey=s", "sshport=i", "sshcipher|c=s", "sshoption|o=s@",
"source-bwlimit=s", "target-bwlimit=s", "sshkey=s", "sshport=i", "sshcipher|c=s", "sshoption|o=s@", "syncstats=s",
"debug", "quiet", "no-stream", "no-sync-snap", "no-resume", "exclude=s@", "skip-parent", "identifier=s",
"no-clone-handling", "no-privilege-elevation", "force-delete", "create-bookmark",
"pv-options=s" => \$pvoptions, "keep-sync-snap", "preserve-recordsize", "mbuffer-size=s" => \$mbuffer_size)
Expand Down Expand Up @@ -85,6 +87,7 @@ my $rawtargetfs = $args{'target'};
my $debug = $args{'debug'};
my $quiet = $args{'quiet'};
my $resume = !$args{'no-resume'};
my $syncstats = {};

# for compatibility reasons, older versions used hardcoded command paths
$ENV{'PATH'} = $ENV{'PATH'} . ":/bin:/usr/bin:/sbin";
Expand Down Expand Up @@ -208,6 +211,14 @@ if (!defined $args{'recursive'}) {
}
}

# print syncstats to file if requested
if (length $args{'syncstats'}) {
my $j = JSON::PP->new->utf8->pretty->allow_nonref;
open my $fp, ">", $args{'syncstats'};
print $fp $j->encode($syncstats);
close $fp;
}

# close SSH sockets for master connections as applicable
if ($sourcehost ne '') {
open FH, "$sshcmd $sourcehost -O exit 2>&1 |";
Expand Down Expand Up @@ -282,6 +293,9 @@ sub syncdataset {

my ($sourcehost, $sourcefs, $targethost, $targetfs, $origin, $skipsnapshot) = @_;

my $start_time_s = Time::HiRes::time();
$syncstats->{$sourcefs}->{"sync_duration_s"} = 0; # will be overwritten if we actually do anything

my $stdout;
my $exit;

Expand Down Expand Up @@ -848,6 +862,11 @@ sub syncdataset {
}
}

# stash some syncstats
my $sync_duration_s = Time::HiRes::time() - $start_time_s;
if ($debug) { print "DEBUG: sync_duration_s = $sync_duration_s\n"; }
$syncstats->{$sourcefs}->{"sync_duration_s"} = $sync_duration_s;

} # end syncdataset()

sub compressargset {
Expand Down Expand Up @@ -1963,6 +1982,7 @@ Options:
--sshport=PORT Connects to remote on a particular port
--sshcipher|c=CIPHER Passes CIPHER to ssh to use a particular cipher set
--sshoption|o=OPTION Passes OPTION to ssh for remote usage. Can be specified multiple times
--syncstats=STATSFILE Specify a file to print per-dataset syncstats to (in json format)

--help Prints this helptext
--version Prints the version number
Expand Down