| 1 | package TheEye::Plugin::Graph::RRD; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use Mouse::Role; | ||
| 5 | use RRD::Simple; | ||
| 6 | |||
| 7 | # ABSTRACT: RRD plugin for TheEye | ||
| 8 | # | ||
| 9 | our $VERSION = '0.1'; # VERSION | ||
| 10 | |||
| 11 | has 'rrd_dir' => ( | ||
| 12 | is => 'rw', | ||
| 13 | isa => 'Str', | ||
| 14 | required => 1, | ||
| 15 | lazy => 1, | ||
| 16 | default => '/tmp/rrds/' | ||
| 17 | ); | ||
| 18 | |||
| 19 | has 'rrd_bin' => ( | ||
| 20 | is => 'rw', | ||
| 21 | isa => 'Str', | ||
| 22 | required => 1, | ||
| 23 | lazy => 1, | ||
| 24 | default => qx/which rrdtool/ | ||
| 25 | ); | ||
| 26 | |||
| 27 | has 'rrd_tmp' => ( | ||
| 28 | is => 'rw', | ||
| 29 | isa => 'Str', | ||
| 30 | required => 1, | ||
| 31 | lazy => 1, | ||
| 32 | default => '/tmp' | ||
| 33 | ); | ||
| 34 | |||
| 35 | has 'img_dir' => ( | ||
| 36 | is => 'rw', | ||
| 37 | isa => 'Str', | ||
| 38 | required => 1, | ||
| 39 | lazy => 1, | ||
| 40 | default => '/tmp/images/' | ||
| 41 | ); | ||
| 42 | |||
| 43 | around 'graph' => sub { | ||
| 44 | my $orig = shift; | ||
| 45 | my ( $self, $tests ) = @_; | ||
| 46 | |||
| 47 | foreach my $test (@{$tests}) { | ||
| 48 | my @fparts = split( /\./, $test->{file} ); | ||
| 49 | my $file = $fparts[0]; | ||
| 50 | $file =~ s/\//-/g; | ||
| 51 | $file = $self->rrd_dir . $file.'.rrd'; | ||
| 52 | print STDERR "graphing ".$file."\n" if $self->debug; | ||
| 53 | |||
| 54 | my $rrd = RRD::Simple->new( | ||
| 55 | file => $file, | ||
| 56 | rrdtool => $self->rrd_bin, | ||
| 57 | tmpdir => $self->rrd_tmp, | ||
| 58 | ); | ||
| 59 | my %rtn = $rrd->graph( | ||
| 60 | destination => $self->img_dir, | ||
| 61 | title => $test->{file} .': '. $test->{steps}->[0]->{message}, | ||
| 62 | periods => [ qw(hour day week month) ], | ||
| 63 | vertical_label => "passed/failed", | ||
| 64 | interlaced => "", | ||
| 65 | extended_legend => 1, | ||
| 66 | source_labels => { | ||
| 67 | passed => 'passed Tests', | ||
| 68 | failed => 'failed Tests', | ||
| 69 | delta => 'time needed (s)' | ||
| 70 | }, | ||
| 71 | source_colors => { | ||
| 72 | passed => '66CC00', | ||
| 73 | failed => 'FF3300', | ||
| 74 | delta => 'CCCCCC' | ||
| 75 | }, | ||
| 76 | source_drawtypes => { | ||
| 77 | passed => 'LINE', | ||
| 78 | failed => 'AREA', | ||
| 79 | delta => 'LINE1' | ||
| 80 | }, | ||
| 81 | ); | ||
| 82 | printf( "Created %s\n", join( ", ", map { $rtn{$_}->[0] } | ||
| 83 | keys %rtn ) ) if $self->debug; | ||
| 84 | } | ||
| 85 | }; | ||
| 86 | |||
| 87 | 1; | ||
| 88 | |||
| 89 | __END__ |