Changeset 680
- Timestamp:
- 01/08/07 19:55:33 (3 years ago)
- Files:
-
- 1 modified
-
trunk/server/lib/MogileFS/IOStatWatcher.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/MogileFS/IOStatWatcher.pm
r496 r680 5 5 use IO::Socket::INET; 6 6 7 =head1 Methods 8 9 =head2 $iow = MogileFS::IOStatWatcher->new() 10 11 Returns a new IOStatWatcher object. 12 13 =cut 14 7 15 sub new { 8 16 my ($class) = @_; 9 return bless {}, $class; 17 my $self = bless {}, $class; 18 $self->on_stats; # set an empty handler. 19 return $self; 10 20 } 21 22 =head2 $iow->set_hosts( host1 [, host2 [, ...] ] ) 23 24 Sets the list of hosts to connect to for collecting IOStat information. This call can block if you 25 pass it hostnames instead of ip addresses. 26 27 Upon successfull connection, the on_stats callback will be called each time the statistics are 28 collected. Error states (failed connections, etc.) will trigger retries on 60 second intervals, and 29 disconnects will trigger an immediate reconnect. 30 31 =cut 11 32 12 33 sub set_hosts { … … 21 42 $self->{hosts} = $new_hosts; 22 43 } 44 45 =head2 $iow->on_stats( coderef ) 46 47 Sets the coderef called for the C<on_stats> callback. 48 49 =cut 50 51 sub on_stats { 52 my ($self, $cb) = @_; 53 54 unless (ref $cb eq 'CODE') { 55 $cb = sub {}; 56 } 57 58 $self->{on_stats} = $cb; 59 } 60 61 =head1 Callbacks 62 63 =head2 on_stats->( host, stats ) 64 65 Called each time device use statistics are collected. The C<host> argument is the value passed in to the 66 C<set_hosts> method. The C<stats> object is a hashref of mogile device names and utilization percentages. 67 68 =cut 69 70 # Everything beyond here is internal. 23 71 24 72 sub got_stats { … … 39 87 } 40 88 41 sub on_stats { 42 my ($self, $cb) = @_; 43 $self->{on_stats} = $cb; 44 } 45 89 # Support class that does the communication with individual hosts. 46 90 package MogileFS::IOStatWatch::Client; 47 91
