| 1 | package TheEye::Plugin::Store::Graphite; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use Mouse::Role; | ||
| 5 | use Net::Graphite; | ||
| 6 | use Carp; | ||
| 7 | |||
| 8 | # ABSTRACT: Graphite plugin for TheEye | ||
| 9 | # | ||
| 10 | our $VERSION = '0.1'; # VERSION | ||
| 11 | |||
| 12 | has 'graphite_host' => ( | ||
| 13 | is => 'rw', | ||
| 14 | isa => 'Str', | ||
| 15 | lazy => 1, | ||
| 16 | default => sub { 'localhost' }, | ||
| 17 | ); | ||
| 18 | |||
| 19 | has 'graphite_port' => ( | ||
| 20 | is => 'rw', | ||
| 21 | isa => 'Int', | ||
| 22 | lazy => 1, | ||
| 23 | default => sub { 2003 }, | ||
| 24 | ); | ||
| 25 | |||
| 26 | has 'graphite_proto' => ( | ||
| 27 | is => 'rw', | ||
| 28 | isa => 'Str', | ||
| 29 | lazy => 1, | ||
| 30 | default => sub { 'tcp' }, | ||
| 31 | ); | ||
| 32 | |||
| 33 | around 'save' => sub { | ||
| 34 | my $orig = shift; | ||
| 35 | my ($self, $tests) = @_; | ||
| 36 | |||
| 37 | my $graphite = Net::Graphite->new( | ||
| 38 | host => $self->graphite_host, | ||
| 39 | port => $self->graphite_port, | ||
| 40 | proto => $self->graphite_proto, | ||
| 41 | fire_and_forget => 1, | ||
| 42 | ); | ||
| 43 | |||
| 44 | foreach my $result (@{$tests}) { | ||
| 45 | |||
| 46 | my @path = split(/\//, $result->{file}); | ||
| 47 | my ($file) = split(/\./, pop(@path)); | ||
| 48 | |||
| 49 | my $service = 'tests.' . $self->hostname . '.' . $file; | ||
| 50 | eval { | ||
| 51 | $graphite->send( | ||
| 52 | path => "$service.ok", | ||
| 53 | value => $result->{passed}); | ||
| 54 | }; | ||
| 55 | carp "sending metric failed: $@" if $@; | ||
| 56 | eval { | ||
| 57 | $graphite->send( | ||
| 58 | path => "$service.nok", | ||
| 59 | value => $result->{failed}); | ||
| 60 | }; | ||
| 61 | carp "sending metric failed: $@" if $@; | ||
| 62 | eval { | ||
| 63 | $graphite->send( | ||
| 64 | path => "$service.delta", | ||
| 65 | value => $result->{delta}); | ||
| 66 | }; | ||
| 67 | carp "sending metric failed: $@" if $@; | ||
| 68 | |||
| 69 | } | ||
| 70 | return; | ||
| 71 | }; | ||
| 72 | |||
| 73 | 1; | ||
| 74 | |||
| 75 | __END__ |