-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example perl pickle metric sender to contrib
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
#!/usr/bin/perl | |||
|
|||
use IO::Socket::INET; | |||
use Python::Serialise::Pickle qw(); | |||
|
|||
my($carbon_server) = '127.0.0.1'; | |||
my($carbon_port) = 2004; | |||
|
|||
my($data) = [ | |||
["path.mytest", [1332444075,27893687]], | |||
["path.mytest", [1332444076,938.435]], | |||
]; | |||
|
|||
my($message) = pack("N/a*", pickle_dumps($data)); | |||
|
|||
my($sock) = IO::Socket::INET->new ( | |||
PeerAddr => $carbon_server, | |||
PeerPort => $carbon_port, | |||
Proto => 'tcp' | |||
); | |||
die "Unable to connect: $!\n" unless ($sock->connected); | |||
|
|||
$sock->send($message); | |||
$sock->shutdown(2); | |||
|
|||
# Work around P::S::Pickle 0.01's extremely limiting interface. | |||
sub pickle_dumps { | |||
open(my $fh, '>', \my $s) or die $!; | |||
my $pickle = bless({ _fh => $fh }, 'Python::Serialise::Pickle'); | |||
$pickle->dump($_[0]); | |||
$pickle->close(); | |||
return $s; | |||
} |