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

4

11

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.

Garbo answered 28/5, 2014 at 12:49 Comment(4)
just edited it with some code, please advise, thank you.Garbo
That's what I thought. That's why I ran "sudo cpan Template". I thought that would install Template::Toolkit, no?Garbo
I tried cpan Template::Toolkit and got "Warning: Cannot install Template::Toolkit, don't know what it is."Garbo
I decided to try "sudo cpan Template" again and it solved my problem… my last "sudo cpan Template" installation wasn't complete for some unknown reason.Garbo
F
8

As deduced in the comments:

You need to install Template::Toolkit.

Foofaraw answered 28/5, 2014 at 12:49 Comment(4)
And to do that on OS X, run 'cpan Template::Toolkit'Straightjacket
Just ran into this exact issue, Tsung version 1.6.0, OS version of Perl. This answer is incorrect (at least for this version). The correct solution is sudo cpan Template, which seems to install everything required.Nickey
@Nickey Template is just another name for Template::Toolkit. I did originally have this alias, but eventually took it over.Foofaraw
@Foofaraw thanks for the explanation. Just want to clarify that Template::Toolkit does not work as an alias (at least with my default OSX Perl setup). Is this expected?Nickey
R
5

For tsung >= 1.6 and perl 5:

sudo cpan Template
Rhinoscopy answered 27/9, 2017 at 3:17 Comment(0)
D
0

just (on windows) run the following lines on cmd

cd C:\Perl64\bin
ppm install Template-Toolkit
Debut answered 3/8, 2014 at 15:31 Comment(0)
I
0

If you tried by running cpan Template or cpan Template:Toolkit and still have this issue, check the version number and the path.

The file: tsung_stats.pl is using /usr/bin/perl and if for some reason you have another perl (like me) in /usr/local/Cellar/perl chances are the script never finds the Template you just installed.

Modify the file tsung_stats.pl in the first line from:

#!/usr/bin/perl -w

to

#!/usr/bin/env perl -w

This will load your perl version used by cpan.

Impractical answered 5/3, 2019 at 4:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.