Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tsung_stats.pl on Mac OS X Mavericks run into "Can't locate Template.pm" error

I'm trying to run tsung_stats.pl from tsung (installed through brew) on Mac OS X 10.9 and got error:

Can't locate Template.pm in @INC (@INC contains: /Library/Perl/5.16/darwin-thread-multi-2level /Library/Perl/5.16 /Network/Library/Perl/5.16/darwin-thread-multi-2level /Network/Library/Perl/5.16 /Library/Perl/Updates/5.16.2 /System/Library/Perl/5.16/darwin-thread-multi-2level /System/Library/Perl/5.16 /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level /System/Library/Perl/Extras/5.16 .) at tsung_stats.pl line 564

I searched and it seems I have to install perl templates, so I ran "sudo cpan Template" and yet still get the same error.

cpan and perl are all in /usr/bin/. Tsung is in /usr/local/Cellar/tsung/1.5.0/bin/tsung

Versions are: perl: perl 5, version 16, subversion 2 (v5.16.2) cpan: 1.57 tsung: 1.5.0

I searched my system and found no file name Template.pm. The closest I found was two TextTemplate.pm files in

/System/Library/Perl/Extras/5.16/Locale/Maketext/Extract/Plugin/
/System/Library/Perl/Extras/5.12/Locale/Maketext/Extract/Plugin/

The following code snippet in question starts from line 563:

sub html_report {
    require Template;
    my $titre     = 'Tsung ';
    my $version   = $tagvsn;
    my $contact   = '[email protected]';
    my $output   = 'index.html';

    my $tt = Template->new({
                            INCLUDE_PATH => $template_dir,
                            PRE_CHOMP    => 1,
                            INTERPOLATE  => 1,
                           }) or die "Template error " . Template->error();
    my $xml_conf;
    opendir (DIR, ".") or warn "can't open directory .";
    while (my $file = readdir (DIR) ) {
        if ($file =~ /.xml$/) {
            $xml_conf= $file;
        }
    }
    foreach my $type ("mean", "maxmean", "minmean") {
        foreach my $data (keys % {$maxval->{$type}} ) {
            next if ($data =~ m/^size/);
            if ($data =~ m/os_mon/) {
                $maxval->{$type}->{$data} = sprintf "%.2f",$maxval->{$type}->{$data};
                next;
            }
            next if not ($data eq "session" or $data eq "connect" or $data eq "request" or $data eq "page" or $data =~ m/^tr_/);
            $maxval->{$type}->{$data} = &formattime($maxval->{$type}->{$data});
        }
    }
    foreach my $size ("size_rcv", "size_sent") {
        if ($maxval->{rate}->{$size}) {
            $maxval->{rate}->{$size} = &formatsize($maxval->{rate}->{$size}*8,"bits");
            $maxval->{maxmean}->{$size} = &formatsize($maxval->{maxmean}->{$size},"B");
        } else {
            warn "$size is equal to 0 !\n";
        }
    }

    my $vars =
        {
         version     => $version,
         os_mon      => $extra,
         errors      => $errors,
         title       => $titre,
         subtitle    => "Stats Report",
         http        => $http,
         stats_subtitle => "Stats Report ",
         graph_subtitle => "Graphs Report ",
         contact     => $contact,
         data        => $maxval,
         cat_data    => $category,
         conf        => $xml_conf
        };
    $tt->process("report.thtml", $vars, "report.html") or die $tt->error(), "\n";
    $vars =
        {
         version     => $version,
         os_mon      => $extra,
         errors      => $errors,
         http        => $http,
         match       => $match,
         async       => $async,
         bosh       => $bosh,
         title       => $titre,
         subtitle    => "Graphs Report",
         stats_subtitle => "Stats Report ",
         graph_subtitle => "Graphs Report ",
         os_mon_other=> $os_mon_other,
         contact     => $contact,
         conf        => $xml_conf,
         ext         => $imgfmt
        };
  if (not $dygraph) {
    $tt->process("graph.thtml", $vars, "graph.html") or die $tt->error(), "\n";
  } else {
    $tt->process("graph_dy.thtml", $vars, "graph.html") or die $tt->error(), "\n";
    copy (($template_dir . "/dygraph-combined.js"), ".") or die "copy failed : $!";
  }
}

I believe $template_dir is in this piece of code (start from line 71):

my $prefix ="/usr/local/Cellar/tsung/1.5.0";

unless ($template_dir) {
    if (-d (dirname($0) . "/templates/")) {
        $template_dir = dirname($0)."/templates/";
    } elsif (-d "$ENV{HOME}/.tsung/templates/") {
        $template_dir = "$ENV{HOME}/.tsung/templates/";
    } elsif (-d "${prefix}/share/tsung/templates") {
        $template_dir = "${prefix}/share/tsung/templates";
    } elsif (-d "/usr/share/tsung/templates") {
        $template_dir = "/usr/share/tsung/templates";
    } elsif (-d "/usr/local/share/tsung/templates") {
        $template_dir = "/usr/local/share/tsung/templates";
    } else {
        warn "Can't find template directory !";
    }
}

I checked those locations and found some .pm files, but none were Template.pm.

Any help would be appreciated.

like image 609
T1000 Avatar asked May 28 '14 12:05

T1000


2 Answers

As deduced in the comments:

You need to install Template::Toolkit.

like image 78
Miller Avatar answered Oct 02 '22 06:10

Miller


For tsung >= 1.6 and perl 5:

sudo cpan Template
like image 37
anhlc Avatar answered Oct 02 '22 06:10

anhlc