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   = 'tsung-users@process-one.net';
    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.

T1000
  • 918
  • 2
  • 15
  • 30
  • just edited it with some code, please advise, thank you. – T1000 May 28 '14 at 14:08
  • That's what I thought. That's why I ran "sudo cpan Template". I thought that would install Template::Toolkit, no? – T1000 May 28 '14 at 14:35
  • I tried cpan Template::Toolkit and got "Warning: Cannot install Template::Toolkit, don't know what it is." – T1000 May 28 '14 at 15:34
  • 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. – T1000 May 28 '14 at 15:35

4 Answers4

8

As deduced in the comments:

You need to install Template::Toolkit.

Miller
  • 34,962
  • 4
  • 39
  • 60
  • 8
    And to do that on OS X, run 'cpan Template::Toolkit' – TonyD Jul 01 '15 at 01:27
  • 6
    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. – robbles Nov 07 '15 at 22:13
  • @robbles [Template](https://metacpan.org/pod/Template) is just another name for [Template::Toolkit](https://metacpan.org/pod/distribution/Template-Toolkit/lib/Template/Toolkit.pod). I did originally have this alias, but eventually took it over. – Miller Nov 08 '15 at 23:44
  • @Miller 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? – robbles Nov 09 '15 at 03:04
5

For tsung >= 1.6 and perl 5:

sudo cpan Template
anhlc
  • 13,839
  • 4
  • 33
  • 40
0

just (on windows) run the following lines on cmd

cd C:\Perl64\bin
ppm install Template-Toolkit
Dario Rusignuolo
  • 2,090
  • 6
  • 38
  • 68
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.

gzfrancisco
  • 812
  • 10
  • 14