[Slim-Checkins] r11028 - in /trunk/server: Plugins/Health/NetTest.pm
Plugins/Health/PerfMon.pm Plugins/Health/Plugin.pm Slim/Plugin/Base.pm
adrian at svn.slimdevices.com
adrian at svn.slimdevices.com
Fri Dec 22 10:17:40 PST 2006
Author: adrian
Date: Fri Dec 22 10:17:40 2006
New Revision: 11028
URL: http://svn.slimdevices.com?rev=11028&view=rev
Log:
Bug: N/A
Description: update Health plugin to start to use class based plugin api
Added:
trunk/server/Plugins/Health/PerfMon.pm (with props)
Modified:
trunk/server/Plugins/Health/NetTest.pm
trunk/server/Plugins/Health/Plugin.pm
trunk/server/Slim/Plugin/Base.pm
Modified: trunk/server/Plugins/Health/NetTest.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/Health/NetTest.pm?rev=11028&r1=11027&r2=11028&view=diff
==============================================================================
--- trunk/server/Plugins/Health/NetTest.pm (original)
+++ trunk/server/Plugins/Health/NetTest.pm Fri Dec 22 10:17:40 2006
@@ -12,16 +12,16 @@
# modify it under the terms of the GNU General Public License,
# version 2.
+package Plugins::Health::NetTest;
+
+use base qw(Slim::Plugin::Base);
use strict;
-package Plugins::Health::NetTest;
-
-our @testRates = ( 64, 128, 192, 256, 320, 500, 1000, 1500, 2000, 2500, 3000, 4000, 5000);
+our @testRates = ( 64, 128, 192, 256, 320, 500, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6000);
our %functions = (
'left' => sub {
my $client = shift;
- exitMode($client);
Slim::Buttons::Common::popModeRight($client);
},
@@ -60,13 +60,19 @@
);
+sub getFunctions {
+ my $class = shift;
+ return \%functions;
+}
+
sub setMode {
+ my $class = shift;
my $client = shift;
if (!$client->display->isa("Slim::Display::Graphics")) {
$client->lines(\&errorLines);
return;
- }
+ }
if ($client->isa('Slim::Player::Transporter')) {
$client->modeParam('listLen', scalar(@testRates));
@@ -101,12 +107,13 @@
}
sub exitMode {
+ my $class = shift;
my $client = shift;
Slim::Utils::Timers::killTimers($client, \&updateDisplay);
Slim::Utils::Timers::killHighTimers($client, \&sendDisplay);
Slim::Utils::Timers::killTimers($client, \&startDisplay);
-
+
$client->modeParam('Health.NetTest', undef);
$client->updateMode(0); # unblock screen updates
}
@@ -154,8 +161,8 @@
my $client = shift;
my $params = shift;
- if (Slim::Buttons::Common::mode($client) ne 'PLUGIN.Health::Plugin') {
- exitMode($client);
+ if (Slim::Buttons::Common::mode($client) ne 'Plugins::Health::Plugin') {
+ exitMode(undef, $client);
return;
}
@@ -171,8 +178,8 @@
my $client = shift;
my $params = shift;
- if (Slim::Buttons::Common::mode($client) ne 'PLUGIN.Health::Plugin') {
- exitMode($client);
+ if (Slim::Buttons::Common::mode($client) ne 'Plugins::Health::Plugin') {
+ exitMode(undef, $client);
return;
}
@@ -195,7 +202,7 @@
} else {
$params->{'refresh'} += 0.5;
}
-
+
Slim::Utils::Timers::setHighTimer($client, $params->{'refresh'}, \&sendDisplay, $params);
}
@@ -230,9 +237,3 @@
1;
-__END__
-
-# Local Variables:
-# tab-width:4
-# indent-tabs-mode:t
-# End:
Added: trunk/server/Plugins/Health/PerfMon.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/Health/PerfMon.pm?rev=11028&view=auto
==============================================================================
--- trunk/server/Plugins/Health/PerfMon.pm (added)
+++ trunk/server/Plugins/Health/PerfMon.pm Fri Dec 22 10:17:40 2006
@@ -1,0 +1,334 @@
+# Plugin for Slimserver to monitor Server and Network Health
+#
+# Web interface to perfmon logs + command line parser for --perfwarn
+
+# $Id$
+
+# This code is derived from code with the following copyright message:
+#
+# SlimServer Copyright (C) 2005 Sean Adams, Slim Devices Inc.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License,
+# version 2.
+
+package Plugins::Health::PerfMon;
+
+use base qw(Slim::Plugin::Base);
+use strict;
+
+use Slim::Utils::Misc;
+use Slim::Utils::Strings qw(string);
+
+# Perfmon logs managed by this plugin module
+my @perfmonLogs = (
+ { 'type' => 'server', 'name' => 'response', 'monitor' => \$Slim::Networking::Select::responseTime, 'warn' => 1 },
+ { 'type' => 'server', 'name' => 'select', 'monitor' => \$Slim::Networking::Select::selectTask, 'warn' => 1 },
+ { 'type' => 'server', 'name' => 'timer', 'monitor' => \$Slim::Utils::Timers::timerTask, 'warn' => 1 },
+ { 'type' => 'server', 'name' => 'request', 'monitor' => \$Slim::Control::Request::requestTask, 'warn' => 1 },
+ { 'type' => 'server', 'name' => 'scheduler', 'monitor' => \$Slim::Utils::Scheduler::schedulerTask, 'warn' => 1 },
+ { 'type' => 'server', 'name' => 'timerlate', 'monitor' => \$Slim::Utils::Timers::timerLate, },
+ { 'type' => 'server', 'name' => 'dbaccess', 'monitor' => \$Slim::Schema::Storage::dbAccess, },
+ { 'type' => 'server', 'name' => 'pagebuild', 'monitor' => \$Slim::Web::HTTP::pageBuild, },
+ { 'type' => 'server', 'name' => 'template', 'monitor' => \$Slim::Web::Template::Context::procTemplate, },
+ { 'type' => 'server', 'name' => 'irqueue', 'monitor' => \$Slim::Hardware::IR::irPerf, },
+ { 'type' => 'player', 'name' => 'signal', 'monitor' => \&Slim::Player::Client::signalStrengthLog, },
+ { 'type' => 'player', 'name' => 'buffer', 'monitor' => \&Slim::Player::Client::bufferFullnessLog, },
+ { 'type' => 'player', 'name' => 'control', 'monitor' => \&Slim::Player::Client::slimprotoQLenLog, },
+);
+
+sub initPlugin {
+ my $class = shift;
+
+ if (defined $::perfwarn) {
+ parseCmdLine($::perfwarn);
+ }
+
+ $class->SUPER::initPlugin();
+}
+
+sub webPages {
+ my $class = shift;
+
+ my $urlBase = 'plugins/Health';
+
+ Slim::Web::Pages->addPageLinks('help', { 'PLUGIN_HEALTH' => "$urlBase/index.html" });
+
+ Slim::Web::HTTP::addPageFunction("$urlBase/index.html", \&handleIndex);
+ Slim::Web::HTTP::addPageFunction("$urlBase/player.html", \&handleGraphs);
+ Slim::Web::HTTP::addPageFunction("$urlBase/server.html", \&handleGraphs);
+}
+
+sub parseCmdLine {
+ my $cmdline = shift;
+
+ $::perfmon = 1;
+
+ if ( $cmdline =~ /^\d+$|^\d+\.\d+$/ ) {
+ foreach my $mon (@perfmonLogs) {
+ if ($mon->{'type'} eq 'server' && $mon->{'warn'}) {
+ ${$mon->{'monitor'}}->setWarnHigh($cmdline);
+ }
+ }
+ } elsif ($cmdline =~ /=/) {
+ for my $statement (split /\s*,\s*/, $cmdline) {
+ my ($name, $thresh) = split /=/, $statement;
+ next if ($thresh !~ /^\d+$|^\d+\.\d+$/);
+ foreach my $mon (@perfmonLogs) {
+ if ($mon->{'type'} eq 'server' && $mon->{'name'} eq $name) {
+ ${$mon->{'monitor'}}->setWarnHigh($thresh);
+ }
+ }
+ }
+ } else {
+ print "Valid perfwarn options: [--perfwarn=<threshold secs>] | [--perfwarn <monitor1>=<threshold1>,<monitor2>=<threshold2>,...]\n";
+ print "monitors: ";
+ foreach my $mon (@perfmonLogs) {
+ if ($mon->{'type'} eq 'server') {
+ print $mon->{'name'}. " ";
+ }
+ }
+ print "\n";
+ }
+}
+
+sub clearAllCounters {
+
+ foreach my $mon (@perfmonLogs) {
+ if ($mon->{'type'} eq 'server') {
+ ${$mon->{'monitor'}}->clear();
+ } elsif ($mon->{'type'} eq 'player') {
+ foreach my $client (Slim::Player::Client::clients()) {
+ my $perfmon = $mon->{'monitor'}($client);
+ $perfmon->clear();
+ }
+ }
+ }
+ $Slim::Networking::Select::endSelectTime = undef;
+}
+
+# Summary info which attempts to categorise common problems based on performance measurments taken
+sub summary {
+ my $client = shift;
+
+ my ($summary, @warn);
+
+ if (defined($client) && $client->isa("Slim::Player::Squeezebox")) {
+
+ my ($control, $stream, $signal, $buffer);
+
+ if ($client->tcpsock() && $client->tcpsock()->opened()) {
+ if ($client->slimprotoQLenLog()->percentAbove(2) < 5) {
+ $control = string("PLUGIN_HEALTH_OK");
+ } else {
+ $control = string("PLUGIN_HEALTH_CONGEST");
+ push @warn, string("PLUGIN_HEALTH_CONTROLCONGEST_DESC");
+ }
+ } else {
+ $control = string("PLUGIN_HEALTH_FAIL");
+ push @warn, string("PLUGIN_HEALTH_CONTROLFAIL_DESC");
+ }
+
+ if ($client->streamingsocket() && $client->streamingsocket()->opened()) {
+ $stream = string("PLUGIN_HEALTH_OK");
+ } else {
+ $stream = string("PLUGIN_HEALTH_INACTIVE");
+ push @warn, string("PLUGIN_HEALTH_STREAMINACTIVE_DESC");
+ }
+
+ if ($client->signalStrengthLog()->percentBelow(30) < 1) {
+ $signal = string("PLUGIN_HEALTH_OK");
+ } elsif ($client->signalStrengthLog()->percentBelow(30) < 5) {
+ $signal = string("PLUGIN_HEALTH_SIGNAL_INTERMIT");
+ push @warn, string("PLUGIN_HEALTH_SIGNAL_INTERMIT_DESC");
+ } elsif ($client->signalStrengthLog()->percentBelow(30) < 20) {
+ $signal = string("PLUGIN_HEALTH_SIGNAL_POOR");
+ push @warn, string("PLUGIN_HEALTH_SIGNAL_POOR_DESC");
+ } else {
+ $signal = string("PLUGIN_HEALTH_SIGNAL_BAD");
+ push @warn, string("PLUGIN_HEALTH_SIGNAL_BAD_DESC");
+ }
+
+ $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_CONTROL'), $control;
+ $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_STREAM'), $stream;
+ $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_SIGNAL'), $signal;
+
+ if (Slim::Player::Source::playmode($client) eq 'play') {
+
+ if ($client->isa("Slim::Player::Squeezebox2")) {
+ if ($client->bufferFullnessLog()->percentBelow(30) < 15) {
+ $buffer = string("PLUGIN_HEALTH_OK");
+ } else {
+ $buffer = string("PLUGIN_HEALTH_BUFFER_LOW");
+ push @warn, string("PLUGIN_HEALTH_BUFFER_LOW_DESC2");
+ }
+ } else {
+ if ($client->bufferFullnessLog()->percentBelow(50) < 5) {
+ $buffer = string("PLUGIN_HEALTH_OK");
+ } else {
+ $buffer = string("PLUGIN_HEALTH_BUFFER_LOW");
+ push @warn, string("PLUGIN_HEALTH_BUFFER_LOW_DESC1");
+ }
+ }
+ $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_BUFFER'), $buffer;
+ }
+ } elsif (defined($client) && $client->isa("Slim::Player::SLIMP3")) {
+ push @warn, string("PLUGIN_HEALTH_SLIMP3_DESC");
+ } else {
+ push @warn, string("PLUGIN_HEALTH_NO_PLAYER_DESC");
+ }
+
+ if ($Slim::Networking::Select::responseTime->percentAbove(1) < 0.01 ||
+ $Slim::Networking::Select::responseTime->above(1) < 3 ) {
+ $summary .= sprintf "%-22s : %s\n", string("PLUGIN_HEALTH_RESPONSE"), string("PLUGIN_HEALTH_OK");
+ } elsif ($Slim::Networking::Select::responseTime->percentAbove(1) < 0.5) {
+ $summary .= sprintf "%-22s : %s\n", string("PLUGIN_HEALTH_RESPONSE"), string("PLUGIN_HEALTH_RESPONSE_INTERMIT");
+ push @warn, string("PLUGIN_HEALTH_RESPONSE_INTERMIT_DESC");
+ } else {
+ $summary .= sprintf "%-22s : %s\n", string("PLUGIN_HEALTH_RESPONSE"), string("PLUGIN_HEALTH_RESPONSE_POOR");
+ push @warn, string("PLUGIN_HEALTH_RESPONSE_POOR_DESC");
+ }
+
+ if (defined($client) && scalar(@warn) == 0) {
+ push @warn, string("PLUGIN_HEALTH_NORMAL");
+ }
+
+ return ($summary, \@warn);
+}
+
+# Main page
+sub handleIndex {
+ my ($client, $params) = @_;
+
+ my $refresh;
+ my ($newtest, $stoptest);
+
+ # process input parameters
+
+ if ($params->{'perf'}) {
+ if ($params->{'perf'} eq 'on') {
+ $::perfmon = 1;
+ clearAllCounters();
+ } elsif ($params->{'perf'} eq 'off') {
+ $::perfmon = 0;
+ }
+ if ($params->{'perf'} eq 'clear') {
+ clearAllCounters();
+ }
+ }
+
+ if (defined($params->{'test'})) {
+ if ($params->{'test'} eq 'stop') {
+ $stoptest = 1;
+ } else {
+ $newtest = $params->{'test'};
+ }
+ }
+
+ # create params to build new page
+
+ # status of perfmon
+ if ($::perfmon) {
+ $params->{'perfon'} = 1;
+ } else {
+ $params->{'perfoff'} = 1;
+ }
+
+ # summary section
+ ($params->{'summary'}, $params->{'warn'}) = summary($client);
+
+ # client specific details
+ if (defined($client)) {
+
+ $params->{'playername'} = $client->name();
+ $params->{'nettest_options'} = \@Plugins::Health::NetTest::testRates;
+
+ if (!$client->display->isa("Slim::Display::Graphics")) {
+ $params->{'nettest_notsupported'} = 1;
+
+ } elsif (Slim::Buttons::Common::mode($client) eq 'Plugins::Health::Plugin') {
+ # network test currently running on this player
+ my $modeParam = $client->modeParam('Health.NetTest');
+ if ($stoptest) {
+ # stop tests
+ Slim::Buttons::Common::popMode($client);
+ $client->update();
+ $refresh = 2;
+ } elsif (defined($newtest)) {
+ # change test rate
+ Plugins::Health::NetTest::setTest($client, undef, $newtest, $modeParam);
+ $refresh = 2;
+ }
+ if (!$stoptest && defined($modeParam) && ref($modeParam) eq 'HASH' && defined $modeParam->{'log'}) {
+ # display current results & refresh in a minute
+ $params->{'nettest_rate'} = $modeParam->{'rate'};
+ $params->{'nettest_graph'} = $modeParam->{'log'}->sprint();
+ $refresh = 60;
+ }
+
+ } elsif (defined($newtest)) {
+ # start tests - power on if necessary
+ $client->power(1) if !$client->power();
+ Slim::Buttons::Common::pushMode($client, 'Plugins::Health::Plugin');
+ my $modeParam = $client->modeParam('Health.NetTest');
+ Plugins::Health::NetTest::setTest($client, undef, $newtest, $modeParam);
+ if (defined($modeParam) && ref($modeParam) eq 'HASH' && defined $modeParam->{'log'}) {
+ $params->{'nettest_rate'} = $modeParam->{'rate'};
+ $params->{'nettest_graph'} = $modeParam->{'log'}->sprint();
+ }
+ $refresh = 2;
+ }
+ }
+
+ $params->{'refresh'} = $refresh;
+
+ return Slim::Web::HTTP::filltemplatefile('plugins/Health/index.html',$params);
+}
+
+# Statistics pages
+sub handleGraphs {
+ my ($client, $params) = @_;
+ my @graphs;
+
+ my $type = ($params->{'path'} =~ /server/) ? 'server' : 'player';
+
+ foreach my $mon (@perfmonLogs) {
+
+ next if ($type ne $mon->{'type'} || $type eq 'player' && !$client);
+
+ my $monitor = ($type eq 'server') ? ${$mon->{'monitor'}} : $mon->{'monitor'}($client);
+
+ if (defined $params->{'monitor'} && ($params->{'monitor'} eq $mon->{'name'} || $params->{'monitor'} eq 'all') ) {
+ if (exists($params->{'setwarn'})) {
+ if (defined $monitor->warnHigh() || $params->{'warnhi'} ne '') {
+ $monitor->setWarnHigh(Slim::Utils::Validate::number($params->{'warnhi'}));
+ }
+ if (defined $monitor->warnLow() || $params->{'warnlo'} ne '') {
+ $monitor->setWarnLow(Slim::Utils::Validate::number($params->{'warnlo'}));
+ }
+ if (defined $monitor->warnBt() || $params->{'warnbt'} ne '') {
+ $monitor->setWarnBt($params->{'warnbt'});
+ }
+ }
+ if (exists($params->{'clear'})) {
+ $monitor->clear();
+ }
+ }
+
+ push @graphs, {
+ 'name' => $mon->{'name'},
+ 'graph' => $monitor->sprint(),
+ 'warnlo'=> $monitor->warnLow(),
+ 'warnhi'=> $monitor->warnHigh(),
+ 'warnbt'=> $monitor->warnBt(),
+ };
+ }
+
+ $params->{'playername'} = $client->name() if $client;
+ $params->{'type'} = $type;
+ $params->{'graphs'} = \@graphs;
+ $params->{'serverlog'} = Slim::Utils::Log::perfmonLogFile();
+
+ return Slim::Web::HTTP::filltemplatefile("plugins/Health/graphs.html",$params);
+}
+
+1;
Propchange: trunk/server/Plugins/Health/PerfMon.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/Plugins/Health/PerfMon.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/Plugins/Health/PerfMon.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: trunk/server/Plugins/Health/Plugin.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/Health/Plugin.pm?rev=11028&r1=11027&r2=11028&view=diff
==============================================================================
--- trunk/server/Plugins/Health/Plugin.pm (original)
+++ trunk/server/Plugins/Health/Plugin.pm Fri Dec 22 10:17:40 2006
@@ -11,336 +11,8 @@
package Plugins::Health::Plugin;
-use strict;
+# Plugin is implemented in two sub plugins:
-use Slim::Utils::Misc;
-use Slim::Utils::Strings qw(string);
-
-use Plugins::Health::NetTest;
-
-sub initPlugin {
- my $class = shift;
-
- if (defined $::perfwarn) {
- parseCmdLine($::perfwarn);
- }
-
- Slim::Buttons::Common::addMode($class, $class->getFunctions, \&Plugins::Health::NetTest::setMode);
-
- my $urlBase = 'plugins/Health';
-
- Slim::Web::Pages->addPageLinks("help", { 'PLUGIN_HEALTH' => "$urlBase/index.html" });
-
- Slim::Web::HTTP::addPageFunction("$urlBase/index.html", \&handleIndex);
- Slim::Web::HTTP::addPageFunction("$urlBase/player.html", \&handleGraphs);
- Slim::Web::HTTP::addPageFunction("$urlBase/server.html", \&handleGraphs);
-}
-
-# Player inteface for network test - shows up on player as 'NetTest'
-sub getDisplayName {
- return('PLUGIN_HEALTH_NETTEST');
-}
-
-sub getFunctions {
- return \%Plugins::Health::NetTest::functions;
-}
-
-####################################################################################################
-
-# Perfmon logs managed by this plugin
-my @perfmonLogs = (
- { 'type' => 'server', 'name' => 'response', 'monitor' => \$Slim::Networking::Select::responseTime, 'warn' => 1 },
- { 'type' => 'server', 'name' => 'select', 'monitor' => \$Slim::Networking::Select::selectTask, 'warn' => 1 },
- { 'type' => 'server', 'name' => 'timer', 'monitor' => \$Slim::Utils::Timers::timerTask, 'warn' => 1 },
- { 'type' => 'server', 'name' => 'request', 'monitor' => \$Slim::Control::Request::requestTask, 'warn' => 1 },
- { 'type' => 'server', 'name' => 'scheduler', 'monitor' => \$Slim::Utils::Scheduler::schedulerTask, 'warn' => 1 },
- { 'type' => 'server', 'name' => 'timerlate', 'monitor' => \$Slim::Utils::Timers::timerLate, },
- { 'type' => 'server', 'name' => 'dbaccess', 'monitor' => \$Slim::Schema::Storage::dbAccess, },
- { 'type' => 'server', 'name' => 'pagebuild', 'monitor' => \$Slim::Web::HTTP::pageBuild, },
- { 'type' => 'server', 'name' => 'template', 'monitor' => \$Slim::Web::Template::Context::procTemplate, },
- { 'type' => 'server', 'name' => 'irqueue', 'monitor' => \$Slim::Hardware::IR::irPerf, },
- { 'type' => 'player', 'name' => 'signal', 'monitor' => \&Slim::Player::Client::signalStrengthLog, },
- { 'type' => 'player', 'name' => 'buffer', 'monitor' => \&Slim::Player::Client::bufferFullnessLog, },
- { 'type' => 'player', 'name' => 'control', 'monitor' => \&Slim::Player::Client::slimprotoQLenLog, },
-);
-
-sub parseCmdLine {
- my $cmdline = shift;
-
- $::perfmon = 1;
-
- if ( $cmdline =~ /^\d+$|^\d+\.\d+$/ ) {
- foreach my $mon (@perfmonLogs) {
- if ($mon->{'type'} eq 'server' && $mon->{'warn'}) {
- ${$mon->{'monitor'}}->setWarnHigh($cmdline);
- }
- }
- } elsif ($cmdline =~ /=/) {
- for my $statement (split /\s*,\s*/, $cmdline) {
- my ($name, $thresh) = split /=/, $statement;
- next if ($thresh !~ /^\d+$|^\d+\.\d+$/);
- foreach my $mon (@perfmonLogs) {
- if ($mon->{'type'} eq 'server' && $mon->{'name'} eq $name) {
- ${$mon->{'monitor'}}->setWarnHigh($thresh);
- }
- }
- }
- } else {
- print "Valid perfwarn options: [--perfwarn=<threshold secs>] | [--perfwarn <monitor1>=<threshold1>,<monitor2>=<threshold2>,...]\n";
- print "monitors: ";
- foreach my $mon (@perfmonLogs) {
- if ($mon->{'type'} eq 'server') {
- print $mon->{'name'}. " ";
- }
- }
- print "\n";
- }
-}
-
-sub clearAllCounters {
-
- foreach my $mon (@perfmonLogs) {
- if ($mon->{'type'} eq 'server') {
- ${$mon->{'monitor'}}->clear();
- } elsif ($mon->{'type'} eq 'player') {
- foreach my $client (Slim::Player::Client::clients()) {
- my $perfmon = $mon->{'monitor'}($client);
- $perfmon->clear();
- }
- }
- }
- $Slim::Networking::Select::endSelectTime = undef;
-}
-
-# Summary info which attempts to categorise common problems based on performance measurments taken
-sub summary {
- my $client = shift;
-
- my ($summary, @warn);
-
- if (defined($client) && $client->isa("Slim::Player::Squeezebox")) {
-
- my ($control, $stream, $signal, $buffer);
-
- if ($client->tcpsock() && $client->tcpsock()->opened()) {
- if ($client->slimprotoQLenLog()->percentAbove(2) < 5) {
- $control = string("PLUGIN_HEALTH_OK");
- } else {
- $control = string("PLUGIN_HEALTH_CONGEST");
- push @warn, string("PLUGIN_HEALTH_CONTROLCONGEST_DESC");
- }
- } else {
- $control = string("PLUGIN_HEALTH_FAIL");
- push @warn, string("PLUGIN_HEALTH_CONTROLFAIL_DESC");
- }
-
- if ($client->streamingsocket() && $client->streamingsocket()->opened()) {
- $stream = string("PLUGIN_HEALTH_OK");
- } else {
- $stream = string("PLUGIN_HEALTH_INACTIVE");
- push @warn, string("PLUGIN_HEALTH_STREAMINACTIVE_DESC");
- }
-
- if ($client->signalStrengthLog()->percentBelow(30) < 1) {
- $signal = string("PLUGIN_HEALTH_OK");
- } elsif ($client->signalStrengthLog()->percentBelow(30) < 5) {
- $signal = string("PLUGIN_HEALTH_SIGNAL_INTERMIT");
- push @warn, string("PLUGIN_HEALTH_SIGNAL_INTERMIT_DESC");
- } elsif ($client->signalStrengthLog()->percentBelow(30) < 20) {
- $signal = string("PLUGIN_HEALTH_SIGNAL_POOR");
- push @warn, string("PLUGIN_HEALTH_SIGNAL_POOR_DESC");
- } else {
- $signal = string("PLUGIN_HEALTH_SIGNAL_BAD");
- push @warn, string("PLUGIN_HEALTH_SIGNAL_BAD_DESC");
- }
-
- $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_CONTROL'), $control;
- $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_STREAM'), $stream;
- $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_SIGNAL'), $signal;
-
- if (Slim::Player::Source::playmode($client) eq 'play') {
-
- if ($client->isa("Slim::Player::Squeezebox2")) {
- if ($client->bufferFullnessLog()->percentBelow(30) < 15) {
- $buffer = string("PLUGIN_HEALTH_OK");
- } else {
- $buffer = string("PLUGIN_HEALTH_BUFFER_LOW");
- push @warn, string("PLUGIN_HEALTH_BUFFER_LOW_DESC2");
- }
- } else {
- if ($client->bufferFullnessLog()->percentBelow(50) < 5) {
- $buffer = string("PLUGIN_HEALTH_OK");
- } else {
- $buffer = string("PLUGIN_HEALTH_BUFFER_LOW");
- push @warn, string("PLUGIN_HEALTH_BUFFER_LOW_DESC1");
- }
- }
- $summary .= sprintf "%-22s : %s\n", string('PLUGIN_HEALTH_BUFFER'), $buffer;
- }
- } elsif (defined($client) && $client->isa("Slim::Player::SLIMP3")) {
- push @warn, string("PLUGIN_HEALTH_SLIMP3_DESC");
- } else {
- push @warn, string("PLUGIN_HEALTH_NO_PLAYER_DESC");
- }
-
- if ($Slim::Networking::Select::responseTime->percentAbove(1) < 0.01 ||
- $Slim::Networking::Select::responseTime->above(1) < 3 ) {
- $summary .= sprintf "%-22s : %s\n", string("PLUGIN_HEALTH_RESPONSE"), string("PLUGIN_HEALTH_OK");
- } elsif ($Slim::Networking::Select::responseTime->percentAbove(1) < 0.5) {
- $summary .= sprintf "%-22s : %s\n", string("PLUGIN_HEALTH_RESPONSE"), string("PLUGIN_HEALTH_RESPONSE_INTERMIT");
- push @warn, string("PLUGIN_HEALTH_RESPONSE_INTERMIT_DESC");
- } else {
- $summary .= sprintf "%-22s : %s\n", string("PLUGIN_HEALTH_RESPONSE"), string("PLUGIN_HEALTH_RESPONSE_POOR");
- push @warn, string("PLUGIN_HEALTH_RESPONSE_POOR_DESC");
- }
-
- if (defined($client) && scalar(@warn) == 0) {
- push @warn, string("PLUGIN_HEALTH_NORMAL");
- }
-
- return ($summary, \@warn);
-}
-
-# Main page
-sub handleIndex {
- my ($client, $params) = @_;
-
- my $refresh;
- my ($newtest, $stoptest);
-
- # process input parameters
-
- if ($params->{'perf'}) {
- if ($params->{'perf'} eq 'on') {
- $::perfmon = 1;
- clearAllCounters();
- } elsif ($params->{'perf'} eq 'off') {
- $::perfmon = 0;
- }
- if ($params->{'perf'} eq 'clear') {
- clearAllCounters();
- }
- }
-
- if (defined($params->{'test'})) {
- if ($params->{'test'} eq 'stop') {
- $stoptest = 1;
- } else {
- $newtest = $params->{'test'};
- }
- }
-
- # create params to build new page
-
- # status of perfmon
- if ($::perfmon) {
- $params->{'perfon'} = 1;
- } else {
- $params->{'perfoff'} = 1;
- }
-
- # summary section
- ($params->{'summary'}, $params->{'warn'}) = summary($client);
-
- # client specific details
- if (defined($client)) {
-
- $params->{'playername'} = $client->name();
- $params->{'nettest_options'} = \@Plugins::Health::NetTest::testRates;
-
- if (!$client->display->isa("Slim::Display::Graphics")) {
- $params->{'nettest_notsupported'} = 1;
-
- } elsif (Slim::Buttons::Common::mode($client) eq 'PLUGIN.Health::Plugin') {
- # network test currently running on this player
- my $modeParam = $client->modeParam('Health.NetTest');
- if ($stoptest) {
- # stop tests
- Plugins::Health::NetTest::exitMode($client);
- Slim::Buttons::Common::popMode($client);
- $client->update();
- $refresh = 2;
- } elsif (defined($newtest)) {
- # change test rate
- Plugins::Health::NetTest::setTest($client, undef, $newtest, $modeParam);
- $refresh = 2;
- }
- if (!$stoptest && defined($modeParam) && ref($modeParam) eq 'HASH' && defined $modeParam->{'log'}) {
- # display current results & refresh in a minute
- $params->{'nettest_rate'} = $modeParam->{'rate'};
- $params->{'nettest_graph'} = $modeParam->{'log'}->sprint();
- $refresh = 60;
- }
-
- } elsif (defined($newtest)) {
- # start tests - power on if necessary
- $client->power(1) if !$client->power();
- Slim::Buttons::Common::pushMode($client, 'PLUGIN.Health::Plugin');
- my $modeParam = $client->modeParam('Health.NetTest');
- Plugins::Health::NetTest::setTest($client, undef, $newtest, $modeParam);
- if (defined($modeParam) && ref($modeParam) eq 'HASH' && defined $modeParam->{'log'}) {
- $params->{'nettest_rate'} = $modeParam->{'rate'};
- $params->{'nettest_graph'} = $modeParam->{'log'}->sprint();
- }
- $refresh = 2;
- }
- }
-
- $params->{'refresh'} = $refresh;
-
- return Slim::Web::HTTP::filltemplatefile('plugins/Health/index.html',$params);
-}
-
-# Statistics pages
-sub handleGraphs {
- my ($client, $params) = @_;
- my @graphs;
-
- my $type = ($params->{'path'} =~ /server/) ? 'server' : 'player';
-
- foreach my $mon (@perfmonLogs) {
-
- next if ($type ne $mon->{'type'} || $type eq 'player' && !$client);
-
- my $monitor = ($type eq 'server') ? ${$mon->{'monitor'}} : $mon->{'monitor'}($client);
-
- if (defined $params->{'monitor'} && ($params->{'monitor'} eq $mon->{'name'} || $params->{'monitor'} eq 'all') ) {
- if (exists($params->{'setwarn'})) {
- if (defined $monitor->warnHigh() || $params->{'warnhi'} ne '') {
- $monitor->setWarnHigh(Slim::Utils::Validate::number($params->{'warnhi'}));
- }
- if (defined $monitor->warnLow() || $params->{'warnlo'} ne '') {
- $monitor->setWarnLow(Slim::Utils::Validate::number($params->{'warnlo'}));
- }
- if (defined $monitor->warnBt() || $params->{'warnbt'} ne '') {
- $monitor->setWarnBt($params->{'warnbt'});
- }
- }
- if (exists($params->{'clear'})) {
- $monitor->clear();
- }
- }
-
- push @graphs, {
- 'name' => $mon->{'name'},
- 'graph' => $monitor->sprint(),
- 'warnlo'=> $monitor->warnLow(),
- 'warnhi'=> $monitor->warnHigh(),
- 'warnbt'=> $monitor->warnBt(),
- };
- }
-
- $params->{'playername'} = $client->name() if $client;
- $params->{'type'} = $type;
- $params->{'graphs'} = \@graphs;
- $params->{'serverlog'} = Slim::Utils::Log::perfmonLogFile();
-
- return Slim::Web::HTTP::filltemplatefile("plugins/Health/graphs.html",$params);
-}
+use base qw(Plugins::Health::NetTest Plugins::Health::PerfMon);
1;
-
-# Local Variables:
-# tab-width:4
-# indent-tabs-mode:t
-# End:
Modified: trunk/server/Slim/Plugin/Base.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Plugin/Base.pm?rev=11028&r1=11027&r2=11028&view=diff
==============================================================================
--- trunk/server/Slim/Plugin/Base.pm (original)
+++ trunk/server/Slim/Plugin/Base.pm Fri Dec 22 10:17:40 2006
@@ -23,7 +23,9 @@
# can be called as class method.
if ($class->can('setMode')) {
- Slim::Buttons::Common::addMode($class, $class->getFunctions, sub { $class->setMode(@_) });
+ my $exitMode = $class->can('exitMode') ? sub { $class->exitMode(@_) } : undef;
+
+ Slim::Buttons::Common::addMode($class, $class->getFunctions, sub { $class->setMode(@_) }, $exitMode);
}
my %params = (
More information about the checkins
mailing list