我正在尝试在Mac OS X 10.9上从tsung(通过brew安装)运行tsung_stats.pl并收到错误:
无法在@INC中找到Template.pm(@INC包含: /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。)在tsung_stats.pl第564行
我搜索过,似乎我必须安装perl模板,所以我运行了“sudo cpan Template”,但仍然遇到同样的错误。
cpan和perl都在/ usr / bin /中。 Tsung位于/usr/local/Cellar/tsung/1.5.0/bin/tsung
版本是: perl:perl 5,版本16,颠覆2(v5.16.2) cpan:1.57 tsung:1.5.0
我搜索了我的系统,发现没有文件名Template.pm。我找到的最接近的是
中的两个TextTemplate.pm文件/System/Library/Perl/Extras/5.16/Locale/Maketext/Extract/Plugin/
/System/Library/Perl/Extras/5.12/Locale/Maketext/Extract/Plugin/
以下代码段从第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 : $!";
}
}
我相信$ template_dir在这段代码中(从第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 !";
}
}
我检查了这些位置并找到了一些.pm文件,但没有一个是Template.pm。
任何帮助都将不胜感激。
答案 0 :(得分:8)
正如评论中所推断:
您需要安装Template::Toolkit
。
答案 1 :(得分:3)
对于tsung> = 1.6和perl 5:
sudo cpan Template
答案 2 :(得分:0)
只是(在Windows上)在cmd上运行以下行
cd C:\Perl64\bin
ppm install Template-Toolkit
答案 3 :(得分:0)
如果您尝试通过运行cpan Template
或cpan Template:Toolkit
仍然遇到此问题,请检查版本号和路径。
文件tsung_stats.pl
正在使用/usr/bin/perl
,如果由于某种原因您在/usr/local/Cellar/perl
中有另一个perl(像我一样),则脚本可能永远找不到您刚安装的模板。 / p>
在以下位置的第一行中修改文件tsung_stats.pl
:
#!/usr/bin/perl -w
到
#!/usr/bin/env perl -w
这将加载cpan使用的perl版本。