App-ProcTrends

 view release on metacpan or  search on metacpan

lib/App/ProcTrends/Commandline.pm  view on Meta::CPAN

            print "=" x 50, "\n";

            for my $hashref ( @{ $ref->{ $metric }->{ $proc } } ) {
                my ( $time, $value ) = ( $hashref->{ time }, $hashref->{ value } );
                $value = "-" unless( $value );
                my $t_string = localtime( $time );
                print $t_string, " " x 20, $value, "\n";
            }
            print "\n";
        }
    }
    return 1;
}

=head2 list_handler

    Return $ref->{ 'cpu', 'rss' } = [ procs ]

=cut

sub list_handler {
    my $self = shift;

    my $rrd_dir = $self->{ rrd_dir };
    my $rrd = $self->{ rrd };
    my $result;
    
    for my $metric ( 'cpu', 'rss' ) {
        my $path = $rrd_dir . "/$metric";
        
        my $ref = $rrd->find_rrds( $path );
        $result->{ $metric } = [ sort keys %{ $ref } ];
    }
    return $self->print_list( $result );
}

=head2 print_list 

    Prints the list (output from list method) on screen

=cut

sub print_list {
    my ( $self, $arg ) = @_;
    
    for my $metric ( 'cpu', 'rss' ) {
        my @procs = @{ $arg->{ $metric } };
        print "$metric processes:\n";
        print "=" x 19 . "\n";

        for my $proc ( @procs ) {
            print $proc, "\n";
        }
        print "\n";
    }
    return 1;
}

=head2 img_handler

    Generates png image files using object params, and store them in $self->{ out_dir }

=cut

sub img_handler {
    my $self = shift;
    
    my $rrd_dir = $self->{ rrd_dir };
    my $out_dir = $self->{ out_dir };
    my $rrd     = $self->{ rrd };
    my $procs   = $self->{ procs };
    my @procs   = split( /,\s*/, $procs ) if ( $procs );
    my $start   = $self->{ start };
    my $end     = $self->{ end };
    
    make_path( $out_dir ) unless( -d $out_dir );
    
    for my $metric ( 'cpu', 'rss' ) {
        my $path = $rrd_dir . "/$metric";
        my $ref = $rrd->find_rrds( $path );

        for my $process ( keys %{ $ref } ) {
            if ( @procs ) {
                next unless ( grep( /^$process$/, @procs ) );
            }
            my $rrdfile = $ref->{ $process };
            my $filename = $out_dir . "/${metric}_$process.png";
            my @params;

            push @params, $filename;
            push @params, "-s $start";
            push @params, "-e $end";
            push @params, "DEF:mydata=$rrdfile:$process:AVERAGE";
            push @params, "AREA:mydata#0000FF:foo";
            RRDs::graph( @params );
        }
    }
    return 1;
}

=head1 AUTHOR

Satoshi Yagi, C<< <satoshi.yagi at yahoo.com> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-app-proctrends-cron at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ProcTrends-Cron>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc App::ProcTrends::Commandline


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ProcTrends-Cron>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/App-ProcTrends-Cron>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/App-ProcTrends-Cron>

=item * Search CPAN

L<http://search.cpan.org/dist/App-ProcTrends-Cron/>

=back


=head1 ACKNOWLEDGEMENTS


=head1 LICENSE AND COPYRIGHT



( run in 0.663 second using v1.01-cache-2.11-cpan-df04353d9ac )