Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / boinc / boinc_processes @ 17f78427

Historique | Voir | Annoter | Télécharger (4,21 ko)

1 cf19700c Petr Ruzicka
#!/usr/bin/perl -w
2
#
3
# Plugin for monitoring boinc processes
4
#
5
# Parameters:
6
#
7
#	password	-- The password for RPC authentication
8 17f78427 Lars Kruse
#			   (default: boinc_cmd will look for a file
9 cf19700c Petr Ruzicka
#			   'gui_rpc_auth.cfg' and use the password in it)
10
#       host 		-- the host to connect to (default: localhost)
11
#	port 		-- optional (default: 31416)
12
#
13 17f78427 Lars Kruse
# This plugin can monitor boinc processes running on local/remote machines.
14 cf19700c Petr Ruzicka
# You can see the progress on various projects.
15
#
16
# Author: Petr Ruzicka <petr.ruzicka@gmail.com>
17
# GPL v3
18
#
19
#%# family=auto
20
#%# capabilities=autoconf
21
22
use IO::Socket;
23
use Digest::MD5 qw(md5_hex);
24
25
26
if ($ENV{'password_path'}) {
27
  $password = $ENV{'password_path'};
28
} else {
29
    $password = $ENV{'password'} || `cat /var/lib/boinc/gui_rpc_auth.cfg 2>/dev/null`;
30
  }
31
32
my $host = $ENV{'host'} || '127.0.0.1';
33
my $port = $ENV{'port'} || '31416';
34
35
36
sub autoconf {
37
  my $client = new IO::Socket::INET (
38
  PeerAddr => $host,
39
  PeerPort => $port,
40
  Proto => 'tcp' );
41
42
  if ($client) {
43
    print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
44
45
    {
46
      local $/ = "\003";
47
      $reply = <$client>;
48
    }
49
50
    $reply =~ /<nonce>(.*)<\/nonce>/;
51
    $hash = md5_hex($1, $password);
52 17f78427 Lars Kruse
53 cf19700c Petr Ruzicka
    print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
54 17f78427 Lars Kruse
55 cf19700c Petr Ruzicka
    {
56
      local $/ = "\003";
57
      $reply = <$client>;
58
    }
59 17f78427 Lars Kruse
60 cf19700c Petr Ruzicka
    if ($reply =~ /<authorized\/>/) {
61
      print "yes\n";
62
      exit 0;
63
    }
64
  }
65
  print "no\n";
66
  exit 1;
67
}
68
69
sub config {
70
  my $client = IO::Socket::INET->new ( PeerAddr => $host,
71
    				       PeerPort => $port,
72
				       Proto => 'tcp' )
73 17f78427 Lars Kruse
  or die "Can't bind : $@\n";
74 cf19700c Petr Ruzicka
75
  print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
76
77 17f78427 Lars Kruse
  {
78 cf19700c Petr Ruzicka
    local $/ = "\003";
79
    $reply = <$client>;
80
  }
81
82
  $reply =~ /<nonce>(.*)<\/nonce>/;
83
  my $hash = md5_hex($1, $password);
84 17f78427 Lars Kruse
85 cf19700c Petr Ruzicka
  print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
86 17f78427 Lars Kruse
87 cf19700c Petr Ruzicka
  {
88
    local $/ = "\003";
89
    $reply = <$client>;
90
  }
91 17f78427 Lars Kruse
92 cf19700c Petr Ruzicka
  if ($reply !~ /<authorized\/>/) {
93
    die "Wrong password: $_";
94
  }
95 17f78427 Lars Kruse
96 cf19700c Petr Ruzicka
  print $client "<boinc_gui_rpc_request><get_state></boinc_gui_rpc_request>";
97
98
  while (chomp($reply = <$client>) && ($reply ne "</boinc_gui_rpc_reply>")) {
99
    if ($reply =~ /<domain_name>(.*)<\/domain_name>/) {
100
      print "graph_title BOINC task progress [$1]\n";
101 84c28707 dipohl
      print "graph_category htc\n";
102 cf19700c Petr Ruzicka
      print "graph_args -l 0\n";
103
      print "graph_vlabel %\n";
104 17f78427 Lars Kruse
    }
105 cf19700c Petr Ruzicka
    if ($reply =~ /<project_name>(.*)<\/project_name>/) {
106
      my $boinc_munin_name=$1;
107
      $boinc_munin_name =~ /(\w+).*/;
108
      print "$1.label $boinc_munin_name\n";
109
    }
110
  }
111
  close ($client);
112
}
113
114
sub report {
115
  my $client = IO::Socket::INET->new ( PeerAddr => $host,
116
    				       PeerPort => $port,
117
				       Proto => 'tcp' )
118 17f78427 Lars Kruse
  or die "Can't bind : $@\n";
119 cf19700c Petr Ruzicka
120
  print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
121
122 17f78427 Lars Kruse
  {
123 cf19700c Petr Ruzicka
    local $/ = "\003";
124
    $reply = <$client>;
125
  }
126
127
  $reply =~ /<nonce>(.*)<\/nonce>/;
128
  my $hash = md5_hex($1, $password);
129 17f78427 Lars Kruse
130 cf19700c Petr Ruzicka
  print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
131 17f78427 Lars Kruse
132 cf19700c Petr Ruzicka
  {
133
    local $/ = "\003";
134
    $reply = <$client>;
135
  }
136 17f78427 Lars Kruse
137 cf19700c Petr Ruzicka
  if ($reply !~ /<authorized\/>/) {
138
    die "Wrong password: $_";
139
  }
140 17f78427 Lars Kruse
141 cf19700c Petr Ruzicka
  print $client "<boinc_gui_rpc_request><get_state></boinc_gui_rpc_request>";
142 17f78427 Lars Kruse
143 cf19700c Petr Ruzicka
  while (chomp($reply = <$client>) && ($reply ne "</boinc_gui_rpc_reply>")) {
144
    if ($reply =~ /<project_name>(\w+).*<\/project_name>/) {
145
      $project = $1;
146
      $fraction_done=0;
147
      while (chomp($reply = <$client>) && ($reply ne "<project>") && ($reply ne "</client_state>")) {
148
        if ($reply =~ /\s*<active_task_state>1<\/active_task_state>/) {
149
	  while (chomp($reply = <$client>) && ($reply ne "</active_task>")) {
150
            if ($reply =~ /<fraction_done>(.*)<\/fraction_done>/) {
151
	      $fraction_done+=int($1*100 + .5 * ($1*100 <=> 0));
152
	    }
153
	  }
154
	}
155
      }
156
      print "$project.value $fraction_done\n";
157
    }
158
  }
159
  close ($client);
160
}
161
162
if (defined $ARGV[0]) {
163
  my $arg = $ARGV[0];
164
  my %funcs = ( config => \&config,
165
		autoconf => \&autoconf,
166
		report => \&report
167
	      );
168
169
  if (exists $funcs{$arg}) {
170
    $funcs{$arg}->();
171
  }
172
  else {
173
    $funcs{"report"}->();
174
  }
175
} else {
176
    report();
177
  }