Net::Async::Statsd::Client - asynchronous API for Etsy's statsd protocol
version 0.004
use Future; use IO::Async::Loop; use Net::Async::Statsd::Client; my $loop = IO::Async::Loop->new; $loop->add(my $statsd = Net::Async::Statsd::Client->new( host => 'localhost', port => 3001, )); # Wait until the stats are written before proceeding Future->needs_all( $statsd->timing( 'some.task' => 133, ), $statsd->gauge( 'some.value' => 80, ) )->get; # Fire-and-forget stat, record 25% of the time: $statsd->increment('startup', 0.25);
Provides an asynchronous API for statsd.
All public methods return a Future indicating when the write has completed. Since writes are UDP packets, there is no guarantee that the remote will receive the value, so this is mostly intended as a way to detect when statsd writes are slow.
Records timing information in milliseconds. Takes up to three parameters:
$k - the statsd key
$v - the elapsed time in milliseconds
$rate - optional sampling rate
Only the integer part of the elapsed time will be sent.
Example usage:
$statsd->timing('some.key' => $ms, 0.1); # record this 10% of the time
Returns a Future which will be resolved when the write completes.
Records a current value. Takes up to three parameters:
$v - the new value
Only the integer value will be sent.
$statsd->timing('some.key' => 123);
Records changed value. Takes up to three parameters:
$v - the change (positive or negative)
Values are truncated to integers.
$statsd->timing('some.key' => -12);
Alias for "delta".
Shortcut for "delta" with a value of +1.
Shortcut for "delta" with a value of -1.
Standard IO::Async::Notifier configuration - called on construction or manually when values need updating.
Accepts the following named parameters:
host - the host we'll connect to
port - the UDP port to send messages to
default_rate - default sampling rate when none is provided for a given call
prefix - string to prepend to any stats we record
These methods are used internally, and are documented for completeness. They may be of use when subclassing this module.
Queues a statistic for write.
Applies sampling based on the given rate - returns true if we should record this, false otherwise.
Default sampling rate. Currently 1 if not overidden in constructor or "configure".
Statsd UDP port.
Statsd host to connect to.
Establishes the underlying UDP socket.
Called when the socket is established.
Called if we receive data.
Called if we had an error while receiving.
Net::Statsd - synchronous implementation
add_child, adopt_future, can_event, children, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent
Tom Molesworth <TEAM@cpan.org>
Copyright Tom Molesworth 2014-2016. Licensed under the same terms as Perl itself.
To install Net::Async::Statsd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::Statsd
CPAN shell
perl -MCPAN -e shell install Net::Async::Statsd
For more information on module installation, please visit the detailed CPAN module installation guide.