package Smokeping::probes::FilePing;

=head1 301 Moved Permanently

This is a Smokeping probe module. Please use the command 

C<smokeping -man Smokeping::probes::FilePing>

to view the documentation or the command

C<smokeping -makepod Smokeping::probes::FilePing>

to generate the POD document.

=cut

use strict;
use base qw(Smokeping::probes::basefork);
use IO::File;
use Time::HiRes qw(gettimeofday tv_interval);
use Carp;

sub pod_hash {
      return {
              name => <<DOC,
Smokeping::probes::FilePing - FilePing Probe for SmokePing
DOC
              description => <<DOC,
Times how long it takes to create a temporary file, write 4096 bytes of data, and call fsync
DOC
              authors => <<'DOC',
Daniel Drown <dan-fileping AT drown.org>
DOC
	}
}

sub new($$$)
{
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = $class->SUPER::new(@_);

    return $self;
}

sub ProbeDesc($){
    my $self = shift;
    return "File create/write/sync operation";
}

sub pingone ($){
    my $self = shift;
    my $target = shift;

    my $writestring = "x" x 4096;

    my(@times);
    for(my $i = 0; $i < $self->pings($target); $i++) {
      my $start = [gettimeofday];
      my $fh = IO::File->new_tmpfile();
      $fh->autoflush(1);
      print $fh $writestring;
      $fh->sync();
      push(@times,tv_interval($start));
      sleep(1);
    }

    return sort {$a <=> $b} @times;
}

sub probevars {
	my $class = shift;
	return $class->_makevars($class->SUPER::probevars, {
		_mandatory => [ ],
	});
}

1;
