1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 18:38:30 +00:00

Update for BOINC 6.12.

This commit is contained in:
Paul Saunders 2011-03-22 12:15:32 +01:00 committed by Steve Schnepp
parent 0af9ab186c
commit 562e63a7bc

View file

@ -1,327 +1,394 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# boinc_projs - Munin plugin to monitor actively running BOINC projects # boinc_projs - Munin plugin to monitor actively running BOINC projects
# #
# Run 'perldoc boinc_projs' for full man page # Run 'perldoc boinc_projs' for full man page
# #
# Author: Palo M. <palo.gm@gmail.com> # Author: Palo M. <palo.gm@gmail.com>
# License: GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt> # Modified by: Paul Saunders <darac+munin@darac.org.uk>
# # License: GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt>
# #
# Parameters supported: #
# config # Parameters supported:
# # config
# #
# Configurable variables #
# boinccmd - command-line control program (default: boinccmd) # Configurable variables
# host - Host to query (default: none = use local host) # boinccmd - command-line control program (default: boinccmd)
# port - GUI RPC port (default: none = use BOINC-default) # host - Host to query (default: none = use local host)
# boincdir - Directory containing appropriate password file # port - GUI RPC port (default: none = use BOINC-default)
# gui_rpc_auth.cfg (default: none) # boincdir - Directory containing appropriate password file
# password - Password for BOINC (default: none) !!! UNSAFE !!! # gui_rpc_auth.cfg (default: none)
# # password - Password for BOINC (default: none) !!! UNSAFE !!!
# #
# $Log$ #
# # $Log$
# Revision 1.0 2009/09/13 Palo M. #
# Add documentation and license information # Revision 1.1 2011/03/22 Paul Saunders
# Ready to publish on Munin Exchange # Update for BOINC 6.12
# Revision 0.9 2009/09/13 Palo M. # Add colours from http://boinc.netsoft-online.com/e107_plugins/forum/forum_viewtopic.php?3
# Add possibility to read password from file # Revision 1.0 2009/09/13 Palo M.
# Revision 0.8 2009/09/12 Palo M. # Add documentation and license information
# Update default binary name: boinc_cmd -> boinccmd # Ready to publish on Munin Exchange
# Revision 0.7 2008/08/29 Palo M. # Revision 0.9 2009/09/13 Palo M.
# Creation - Attempt to port functionality from C++ code # Add possibility to read password from file
# # Revision 0.8 2009/09/12 Palo M.
# (Revisions 0.1 - 0.6) were done in C++ # Update default binary name: boinc_cmd -> boinccmd
# # Revision 0.7 2008/08/29 Palo M.
# # Creation - Attempt to port functionality from C++ code
# #
# Magic markers: # (Revisions 0.1 - 0.6) were done in C++
#%# family=contrib #
#
use strict; #
# Magic markers:
#%# family=contrib
#########################################################################
# 1. Parse configuration variables use strict;
#
my $BOINCCMD = exists $ENV{'boinccmd'} ? $ENV{'boinccmd'} : "boinccmd";
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : undef; #########################################################################
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : undef; # 1. Parse configuration variables
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef; #
my $BOINCDIR = exists $ENV{'boincdir'} ? $ENV{'boincdir'} : undef; my $BOINCCMD = exists $ENV{'boinccmd'} ? $ENV{'boinccmd'} : "boinccmd";
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : undef;
######################################################################### my $PORT = exists $ENV{'port'} ? $ENV{'port'} : undef;
# 2. Basic executable my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef;
# my $BOINCDIR = exists $ENV{'boincdir'} ? $ENV{'boincdir'} : undef;
if (defined $HOST) {
$BOINCCMD .= " --host $HOST"; #########################################################################
if (defined $PORT) { # 2. Basic executable
$BOINCCMD .= ":$PORT"; #
} if (defined $HOST) {
} $BOINCCMD .= " --host $HOST";
if (defined $PASSWORD) { if (defined $PORT) {
$BOINCCMD .= " --passwd $PASSWORD"; $BOINCCMD .= ":$PORT";
} }
if (defined $BOINCDIR) { }
chdir $BOINCDIR; if (defined $PASSWORD) {
} $BOINCCMD .= " --passwd $PASSWORD";
}
######################################################################### if (defined $BOINCDIR) {
# 3. Fetch all needed data from BOINC-client with single call chdir $BOINCDIR || die "Could not chdir to $BOINCDIR";
# }
my $prj_status = "";
my $results = ""; #########################################################################
# 3. Fetch all needed data from BOINC-client with single call
my $simpleGuiInfo = `$BOINCCMD --get_simple_gui_info 2>/dev/null`; #
if ($simpleGuiInfo ne "") { my $prj_status = "";
# Some data were retrieved, so let's split them my $results = "";
my @sections;
my @section1; my $simpleGuiInfo = `$BOINCCMD --get_simple_gui_info 2>/dev/null`;
@sections = split /=+ Projects =+\n/, $simpleGuiInfo; if ($simpleGuiInfo ne "") {
@section1 = split /=+ [A-z]+ =+\n/, $sections[1]; # Some data were retrieved, so let's split them
$prj_status = $section1[0]; my @sections;
my @section1;
@sections = split /=+ Results =+\n/, $simpleGuiInfo; @sections = split /=+ Projects =+\n/, $simpleGuiInfo;
@section1 = split /=+ [A-z]+ =+\n/, $sections[1]; @section1 = split /=+ [A-z]+ =+\n/, $sections[1];
$results = $section1[0]; $prj_status = $section1[0];
}
@sections = split /=+ (?:Results|Tasks) =+\n/, $simpleGuiInfo;
if ($prj_status eq "") { exit -1; } @section1 = split /=+ [A-z]+ =+\n/, $sections[1];
$results = $section1[0];
# 3.a) Split --get_project_status into projects }
my @prjInfos = split /\d+\) -+\n/, $prj_status;
shift @prjInfos; # Throw out first empty line if ($prj_status eq "") { exit -1; }
# 3.b) Fetch project infos # 3.a) Split --get_project_status into projects
my %projects; # Store projects infos here my @prjInfos = split /\d+\) -+\n/, $prj_status;
my @projects; # Just to keep the order of projects shift @prjInfos; # Throw out first empty line
for my $prj_info (@prjInfos) {
my @lines = split /\n/, $prj_info; # 3.b) Fetch project infos
my $line1 = shift @lines; # get project name my %projects; # Store projects infos here
if ($line1 !~ /^\s+name: /) { die "Unexpected output from boinccmd"; } my @projects; # Just to keep the order of projects
$line1 =~ s/^\s+name: //; # Make just the project name itself for my $prj_info (@prjInfos) {
my $line2 = shift @lines; # get project URL my @lines = split /\n/, $prj_info;
if ($line2 !~ /^\s+master URL: /) { die "Unexpected output from boinccmd"; } my $line1 = shift @lines; # get project name
$line2 =~ s/^\s+master URL: //; # Make just the URL itself if ($line1 !~ /^\s+name: /) { die "Unexpected output from boinccmd"; }
my $prj_url = $line2; $line1 =~ s/^\s+name: //; # Make just the project name itself
my $prj_name = $line1; my $line2 = shift @lines; # get project URL
$line1 =~ s/\@/at/g; if ($line2 !~ /^\s+master URL: /) { die "Unexpected output from boinccmd"; }
$line1 =~ s/[^0-9A-z]/_/g; $line2 =~ s/^\s+master URL: //; # Make just the URL itself
my $prj_var = "prj_" . $line1; my $prj_url = $line2;
push @projects,$prj_url; my $prj_name = $line1;
$projects{$prj_url} = { $line1 =~ s/\@/at/g;
prj_name => $prj_name, $line1 =~ s/[^0-9A-z]/_/g;
prj_var => $prj_var, my $prj_var = "prj_" . $line1;
prj_running => 0 push @projects,$prj_url;
}; $projects{$prj_url} = {
} prj_name => $prj_name,
prj_var => $prj_var,
prj_running => 0
######################################################################### };
# 4. Parse results }
#
# 4.a) Split --get_results
my @rsltInfos = split /\d+\) -+\n/, $results; #########################################################################
shift @rsltInfos; # Throw out first empty line # 4. Parse results
#
# 4.b) Parse results, find those which are running # 4.a) Split --get_results
for my $rslt_info (@rsltInfos) { my @rsltInfos = split /\d+\) -+\n/, $results;
my @lines = split /\n/, $rslt_info; shift @rsltInfos; # Throw out first empty line
my @url = grep /^\s+project URL: /,@lines;
my $url = $url[0]; # 4.b) Parse results, find those which are running
$url =~ s/^\s+project URL: //; # Make just the URL itself for my $rslt_info (@rsltInfos) {
my @schedstat = grep /^\s+scheduler state: /,@lines; my @lines = split /\n/, $rslt_info;
my $schedstat = $schedstat[0]; my @url = grep /^\s+project URL: /,@lines;
$schedstat =~ s/^\s+scheduler state: //; my $url = $url[0];
my @state = grep /^\s+state: /,@lines; $url =~ s/^\s+project URL: //; # Make just the URL itself
my $state = $state[0]; my @schedstat = grep /^\s+scheduler state: /,@lines;
$state =~ s/^\s+state: //; my $schedstat = $schedstat[0];
my @acttask = grep /^\s+active_task_state: /,@lines; $schedstat =~ s/^\s+scheduler state: //;
my $acttask = $acttask[0]; my @state = grep /^\s+state: /,@lines;
$acttask =~ s/^\s+active_task_state: //; my $state = $state[0];
if ( ($schedstat eq "2") && ($state eq "2") && ($acttask eq "1") ) { $state =~ s/^\s+state: //;
# This is running task my @acttask = grep /^\s+active_task_state: /,@lines;
$projects{$url}->{prj_running} += 1; my $acttask = $acttask[0];
} $acttask =~ s/^\s+active_task_state: //;
} if ( ($schedstat eq "2") && ($state eq "2") && ($acttask eq "1") ) {
# This is running task
$projects{$url}->{prj_running} += 1;
######################################################################### }
# 5. Display output }
#
if ( (defined $ARGV[0]) && ($ARGV[0] eq "config") ) { #########################################################################
# # 5. Display output
# 5.a) Display config #
#
# Project Colours from http://boinc.netsoft-online.com/e107_plugins/forum/forum_viewtopic.php?3
if (defined $HOST) { sub rgb($$$){
print "host_name $HOST\n"; return sprintf ('%02x%02x%02x', shift, shift, shift);
} }
my %project_colour = (
print "graph_title Running BOINC processes\n"; 'climatepredition.net' => rgb(0,139,69),
print "graph_category BOINC\n"; 'Predictor@Home' => rgb(135,206,235),
print "graph_args --base 1000 -l 0\n"; 'SETI@home' => rgb(65,105,225),
print "graph_vlabel BOINC applications\n"; 'Einstein@Home' => rgb(255,165,0),
'Rosetta@home' => rgb(238,130,238),
# First project is AREA, next are STACK 'PrimeGrid' => rgb(205,197,191),
# Not nice, but fast: 'LHC@home' => rgb(255,127,80),
my $prj1 = shift @projects; 'World Community Grid' => rgb(250,128,114),
print "$projects{$prj1}->{prj_var}.label $projects{$prj1}->{prj_name}\n"; 'BURP' => rgb(0,255,127),
print "$projects{$prj1}->{prj_var}.draw AREA\n"; 'SZTAKI Desktop Grid' => rgb(205,79,57),
print "$projects{$prj1}->{prj_var}.type GAUGE\n"; 'uFluids' => rgb(0,0,0),
'SIMAP' => rgb(143,188,143),
for my $prjN (@projects) { 'Folding@Home' =>rgb(153,50,204),
print "$projects{$prjN}->{prj_var}.label $projects{$prjN}->{prj_name}\n"; 'MalariaControl' => rgb(30,144,255),
print "$projects{$prjN}->{prj_var}.draw STACK\n"; 'The Lattice Project' => rgb(0,100,0),
print "$projects{$prjN}->{prj_var}.type GAUGE\n"; 'Pirates@Home' => rgb(127,255,0),
} 'BBC Climate Change Experiment' => rgb(205,173,0),
'Leiden Classical' => rgb(140,34,34),
exit 0; 'SETI@home Beta' => rgb(152,245,255),
} 'RALPH@Home' => rgb(250,240,230),
'QMC@HOME' => rgb(144,238,144),
# 'XtremLab' => rgb(130,130,130),
# 5.b) Display running state of projects 'HashClash' => rgb(255,105,180),
# 'cpdn seasonal' => rgb(255,255,255),
'Chess960@Home Alpha' => rgb(165,42,42),
for my $prjN (@projects) { 'vtu@home' => rgb(255,0,0),
print "$projects{$prjN}->{prj_var}.value $projects{$prjN}->{prj_running}\n"; 'LHC@home alpha' => rgb(205,133,63),
} 'TANPAKU' => rgb(189,183,107),
'other' => rgb(255,193,37),
exit 0; 'Rectilinear Crossing Number' => rgb(83,134,139),
'Nano-Hive@Home' => rgb(193,205,193),
'Spinhenge@home' => rgb(255,240,245),
######################################################################### 'RieselSieve' => rgb(205,183,158),
# perldoc section 'Project Neuron' => rgb(139,58,98),
'RenderFarm@Home' => rgb(210,105,30),
=head1 NAME 'Docking@Home' => rgb(178,223,238),
'proteins@home' => rgb(0,0,255),
boinc_projs - Munin plugin to monitor actively running BOINC projects. 'DepSpid' => rgb(139,90,43),
'ABC@home' => rgb(222,184,135),
=head1 APPLICABLE SYSTEMS 'BOINC alpha test' => rgb(245,245,220),
'WEP-M+2' => rgb(0,250,154),
Linux machines running BOINC and munin-node 'Zivis Superordenador Ciudadano' => rgb(255,239,219),
'SciLINC' => rgb(240,248,255),
- or - 'APS@Home' => rgb(205,91,69),
'PS3GRID' => rgb(0,139,139),
Linux servers (running munin-node) used to collect data from other systems 'Superlink@Technion' => rgb(202,255,112),
which are running BOINC, but not running munin-node (e.g. non-Linux systems) 'BRaTS@Home' => rgb(255,106,106),
'Cosmology@Home' => rgb(240,230,140),
=head1 CONFIGURATION 'SHA 1 Collision Search' => rgb(255,250,205),
);
Following configuration variables are supported:
=over 12 if ( (defined $ARGV[0]) && ($ARGV[0] eq "config") ) {
#
=item B<boinccmd> # 5.a) Display config
#
command-line control program (default: boinccmd)
if (defined $HOST) {
=item B<host> print "host_name $HOST\n";
}
Host to query (default: none)
print "graph_title Running BOINC processes\n";
=item B<port> print "graph_category BOINC\n";
print "graph_args --base 1000 -l 0\n";
GUI RPC port (default: none = use BOINC-default) print "graph_vlabel BOINC applications\n";
=item B<boincdir> # First project is AREA, next are STACK
# Not nice, but fast:
Directory containing appropriate file gui_rpc_auth.cfg (default: none) my $prj1 = shift @projects;
print "$projects{$prj1}->{prj_var}.label $projects{$prj1}->{prj_name}\n";
=item B<password> if (exists $project_colour{$projects{$prj1}->{prj_name}}){
print "$projects{$prj1}->{prj_var}.colour $project_colour{$projects{$prj1}->{prj_name}}\n";
Password for BOINC (default: none) }
print "$projects{$prj1}->{prj_var}.draw AREA\n";
=back print "$projects{$prj1}->{prj_var}.type GAUGE\n";
=head2 B<Security Consideration:> for my $prjN (@projects) {
print "$projects{$prjN}->{prj_var}.label $projects{$prjN}->{prj_name}\n";
Using of variable B<password> poses a security risk. Even if the Munin if (exists $project_colour{$projects{$prjN}->{prj_name}}){
configuration file for this plugin containing BOINC-password is properly print "$projects{$prjN}->{prj_var}.colour $project_colour{$projects{$prjN}->{prj_name}}\n";
protected, the password is exposed as environment variable and finally passed }
to boinccmd as a parameter. It is therefore possible for local users of the print "$projects{$prjN}->{prj_var}.draw STACK\n";
machine running this plugin to eavesdrop the BOINC password. print "$projects{$prjN}->{prj_var}.type GAUGE\n";
}
Using of variable password is therefore strongly discouraged and is left here
as a legacy option and for testing purposes. exit 0;
}
It should be always possible to use B<boincdir> variable instead - in such case
the file gui_rpc_auth.cfg is read by boinccmd binary directly. #
If this plugin is used to fetch data from remote system, the gui_rpc_auth.cfg # 5.b) Display running state of projects
can be copied to special directory in a secure way (e.g. via scp) and properly #
protected by file permissions.
for my $prjN (@projects) {
=head1 INTERPRETATION print "$projects{$prjN}->{prj_var}.value $projects{$prjN}->{prj_running}\n";
}
This plugin shows the number of currently running BOINC tasks on the machine.
If machine is attached to several BOINC projects, data for all these projects exit 0;
are displayed.
=head1 EXAMPLES #########################################################################
# perldoc section
=head2 Local BOINC Example
=head1 NAME
BOINC is running on local machine. The BOINC binaries are installed in
F</opt/boinc/custom-6.10.1/>, the BOINC is running in directory boinc_projs - Munin plugin to monitor actively running BOINC projects.
F</usr/local/boinc/> under username boinc, group boinc and the password is used
to protect access to BOINC: =head1 APPLICABLE SYSTEMS
[boinc_*] Linux machines running BOINC and munin-node
group boinc
env.boinccmd /opt/boinc/custom-6.10.1/boinccmd - or -
env.boincdir /usr/local/boinc
Linux servers (running munin-node) used to collect data from other systems
=head2 Remote BOINC Example which are running BOINC, but not running munin-node (e.g. non-Linux systems)
BOINC is running on 2 remote machines C<foo> and C<bar>. =head1 CONFIGURATION
On the local machine the binary of command-line interface is installed in
directory F</usr/local/bin/>. Following configuration variables are supported:
The BOINC password used on the remote machine C<foo> is stored in file
F</etc/munin/boinc/foo/gui_rpc_auth.cfg>. =over 12
The BOINC password used on the remote machine C<bar> is stored in file
F</etc/munin/boinc/bar/gui_rpc_auth.cfg>. =item B<boinccmd>
These files are owned and readable by root, readable by group munin and not
readable by others. command-line control program (default: boinccmd)
There are 2 symbolic links to this plugin created in the munin plugins
directory (usually F</etc/munin/plugins/>): F<snmp_foo_boincprojs> and =item B<host>
F<snmp_bar_boincprojs>
Host to query (default: none)
[snmp_foo_boinc*]
group munin =item B<port>
env.boinccmd /usr/local/bin/boinccmd
env.host foo GUI RPC port (default: none = use BOINC-default)
env.boincdir /etc/munin/boinc/foo
=item B<boincdir>
[snmp_bar_boinc*]
group munin Directory containing appropriate file gui_rpc_auth.cfg (default: none)
env.boinccmd /usr/local/bin/boinccmd
env.host bar =item B<password>
env.boincdir /etc/munin/boinc/bar
Password for BOINC (default: none)
This way the plugin can be used by Munin the same way as the Munin plugins
utilizng SNMP (although this plugin itself does not use SNMP). =back
=head1 BUGS =head2 B<Security Consideration:>
There is no C<autoconf> capability at the moment. This is due to the fact, that Using of variable B<password> poses a security risk. Even if the Munin
BOINC installations may vary over different systems, sometimes using default configuration file for this plugin containing BOINC-password is properly
directory from distribution (e.g. F</var/lib/boinc/> in Debian or Ubuntu), but protected, the password is exposed as environment variable and finally passed
often running in user directories or in other separate directories. to boinccmd as a parameter. It is therefore possible for local users of the
Also the user-ID under which BOINC runs often differs. machine running this plugin to eavesdrop the BOINC password.
Under these circumstances the C<autoconf> would be either lame or too
complicated. Using of variable password is therefore strongly discouraged and is left here
as a legacy option and for testing purposes.
=head1 AUTHOR
It should be always possible to use B<boincdir> variable instead - in such case
Palo M. <palo.gm@gmail.com> the file gui_rpc_auth.cfg is read by boinccmd binary directly.
If this plugin is used to fetch data from remote system, the gui_rpc_auth.cfg
=head1 LICENSE can be copied to special directory in a secure way (e.g. via scp) and properly
protected by file permissions.
GPLv3
=head1 INTERPRETATION
=cut
This plugin shows the number of currently running BOINC tasks on the machine.
# vim:syntax=perl If machine is attached to several BOINC projects, data for all these projects
are displayed.
=head1 EXAMPLES
=head2 Local BOINC Example
BOINC is running on local machine. The BOINC binaries are installed in
F</opt/boinc/custom-6.10.1/>, the BOINC is running in directory
F</usr/local/boinc/> under username boinc, group boinc and the password is used
to protect access to BOINC:
[boinc_*]
group boinc
env.boinccmd /opt/boinc/custom-6.10.1/boinccmd
env.boincdir /usr/local/boinc
=head2 Remote BOINC Example
BOINC is running on 2 remote machines C<foo> and C<bar>.
On the local machine the binary of command-line interface is installed in
directory F</usr/local/bin/>.
The BOINC password used on the remote machine C<foo> is stored in file
F</etc/munin/boinc/foo/gui_rpc_auth.cfg>.
The BOINC password used on the remote machine C<bar> is stored in file
F</etc/munin/boinc/bar/gui_rpc_auth.cfg>.
These files are owned and readable by root, readable by group munin and not
readable by others.
There are 2 symbolic links to this plugin created in the munin plugins
directory (usually F</etc/munin/plugins/>): F<snmp_foo_boincprojs> and
F<snmp_bar_boincprojs>
[snmp_foo_boinc*]
group munin
env.boinccmd /usr/local/bin/boinccmd
env.host foo
env.boincdir /etc/munin/boinc/foo
[snmp_bar_boinc*]
group munin
env.boinccmd /usr/local/bin/boinccmd
env.host bar
env.boincdir /etc/munin/boinc/bar
This way the plugin can be used by Munin the same way as the Munin plugins
utilizng SNMP (although this plugin itself does not use SNMP).
=head1 BUGS
There is no C<autoconf> capability at the moment. This is due to the fact, that
BOINC installations may vary over different systems, sometimes using default
directory from distribution (e.g. F</var/lib/boinc/> in Debian or Ubuntu), but
often running in user directories or in other separate directories.
Also the user-ID under which BOINC runs often differs.
Under these circumstances the C<autoconf> would be either lame or too
complicated.
=head1 AUTHOR
Palo M. <palo.gm@gmail.com>
=head1 LICENSE
GPLv3
=cut
# vim:syntax=perl