forked from marksteele/collectd-amqp-opentsdb-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamqp_consumer_graphite.pl
40 lines (35 loc) · 987 Bytes
/
amqp_consumer_graphite.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
use strict;
use Data::Dumper;
use Net::RabbitMQ;
use IO::Socket;
my $rabbit_host = '127.0.0.1';
my $rabbit_port = 5672;
my $graphite_host = '127.0.0.1';
my $graphite_port = 2003;
my $user = 'amqpuser';
my $password = 'amqppass';
my $vhost = '/';
my $exchange = 'stats';
my $queue = 'consumerqueue' . $$;
my $mq = Net::RabbitMQ->new();
$mq->connect($rabbit_host , { port => $rabbit_port, user => $user, password => $password, vhost => $vhost });
$mq->channel_open(1);
$mq->queue_declare(1, $queue);
$mq->queue_bind(1, $queue, $exchange, '');
$mq->consume(1,$queue);
while(1) {
my $msg = $mq->recv();
if ($msg) {
my $sock = IO::Socket::INET->new(PeerAddr => $graphite_host,
PeerPort => $graphite_port,
Proto => 'tcp',
Timeout => 10);
if ($sock) {
print $sock $msg->{'body'};
close($sock);
}
} else {
sleep(1);
}
}