root / plugins / boinc / boinc_credit @ 84c28707
Historique | Voir | Annoter | Télécharger (7,34 ko)
| 1 | 480eb0f3 | Paul Saunders | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # -*- cperl -*- |
||
| 3 | |||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | boinc_credit - Munin plugin to monitor BOINC credit for a user |
||
| 7 | |||
| 8 | =head1 APPLICABLE SYSTEMS |
||
| 9 | |||
| 10 | Any |
||
| 11 | |||
| 12 | =head1 CONFIGURATION |
||
| 13 | |||
| 14 | All that should be needed is to add the following to your config: |
||
| 15 | |||
| 16 | [boinc_credit] |
||
| 17 | env.cpid 1234abcd.... |
||
| 18 | |||
| 19 | Where the value is your Cross Project ID (CPID). |
||
| 20 | |||
| 21 | =head1 MAGIC MARKERS |
||
| 22 | |||
| 23 | #%# family=auto contrib |
||
| 24 | #%# capabilities=autoconf |
||
| 25 | |||
| 26 | =head1 VERSION |
||
| 27 | |||
| 28 | 1.0 |
||
| 29 | |||
| 30 | =head1 AUTHOR |
||
| 31 | |||
| 32 | Paul Saunders <darac+munin@darac.org.uk> |
||
| 33 | |||
| 34 | =cut |
||
| 35 | |||
| 36 | use strict; |
||
| 37 | use warnings; |
||
| 38 | |||
| 39 | use lib $ENV{'MUNIN_LIBDIR'};
|
||
| 40 | use Munin::Plugin; |
||
| 41 | |||
| 42 | my $CPID = $ENV{cpid};
|
||
| 43 | my $STATSURL = $ENV{statsurl}
|
||
| 44 | || "http://boinc.netsoft-online.com/get_user.php?cpid=$CPID"; |
||
| 45 | my $TICK = $ENV{tick} || 60; # minutes
|
||
| 46 | |||
| 47 | my $ret; |
||
| 48 | if ( !eval "require XML::Simple;" ) {
|
||
| 49 | $ret += "Could not load XML::Simple; "; |
||
| 50 | } |
||
| 51 | if ( !eval "require LWP::Simple;" ) {
|
||
| 52 | $ret += "Could not load LWP::Simple; "; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
|
||
| 56 | |||
| 57 | # Can't auto configure at the moment. |
||
| 58 | # At least, until we can calculate CPID |
||
| 59 | print "no\n"; |
||
| 60 | exit 0; |
||
| 61 | } |
||
| 62 | |||
| 63 | my $lastread; |
||
| 64 | |||
| 65 | sub save_data {
|
||
| 66 | my @projdata = @_; |
||
| 67 | |||
| 68 | # Do we need to save this data? |
||
| 69 | if ( !defined $lastread or time >= $lastread + ( $TICK * 60 ) ) {
|
||
| 70 | $lastread = time; |
||
| 71 | |||
| 72 | my @save_vector; |
||
| 73 | push @save_vector, $lastread; |
||
| 74 | foreach (@projdata) {
|
||
| 75 | |||
| 76 | # Serialise the hash |
||
| 77 | my @tempbuf; |
||
| 78 | foreach my $key ( keys %{$_} ) {
|
||
| 79 | push @tempbuf, $key . '¬' . $_->{$key};
|
||
| 80 | } |
||
| 81 | push @save_vector, join( '^^', @tempbuf ); |
||
| 82 | } |
||
| 83 | save_state(@save_vector); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | sub load_data {
|
||
| 88 | |||
| 89 | # Bring the data back in |
||
| 90 | my @save_vector = restore_state(); |
||
| 91 | |||
| 92 | # Read the timestamp, Do we need to refresh the data? |
||
| 93 | $lastread = shift @save_vector; |
||
| 94 | |||
| 95 | my @projarray; |
||
| 96 | foreach (@save_vector) {
|
||
| 97 | my $hashref; |
||
| 98 | foreach ( split /\^\^/ ) {
|
||
| 99 | my ( $key, $value ) = split /¬/; |
||
| 100 | $hashref->{$key} = $value;
|
||
| 101 | } |
||
| 102 | push @projarray, $hashref; |
||
| 103 | } |
||
| 104 | |||
| 105 | if ( !defined $lastread or time >= ( $lastread + ( $TICK * 60 ) ) ) {
|
||
| 106 | |||
| 107 | # Data is stale |
||
| 108 | |||
| 109 | eval {
|
||
| 110 | |||
| 111 | # Fetch the XML |
||
| 112 | my $content; |
||
| 113 | unless ( defined( $content = LWP::Simple::get $STATSURL) ) {
|
||
| 114 | die "Could not get $STATSURL"; |
||
| 115 | } |
||
| 116 | my $xmlref = XML::Simple::XMLin( $content, ForceArray => 1 ); |
||
| 117 | |||
| 118 | my @temparray; |
||
| 119 | foreach ( @{ $xmlref->{project} } ) {
|
||
| 120 | my $temphash; |
||
| 121 | $temphash->{name} = $_->{name}[0];
|
||
| 122 | $temphash->{id} = $_->{project_id}[0];
|
||
| 123 | $temphash->{credit} = $_->{total_credit}[0];
|
||
| 124 | $temphash->{creditfract} =
|
||
| 125 | $_->{total_credit}[0] / $xmlref->{total_credit}[0];
|
||
| 126 | $temphash->{totalcredit} = $xmlref->{total_credit}[0];
|
||
| 127 | $temphash->{rank} = $_->{project_rank_total_credit}[0];
|
||
| 128 | |||
| 129 | push @temparray, $temphash; |
||
| 130 | } |
||
| 131 | |||
| 132 | # If the above threw an error, we won't overwrite the old data |
||
| 133 | @projarray = @temparray; |
||
| 134 | |||
| 135 | 1; |
||
| 136 | } or do {
|
||
| 137 | print $@; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | return @projarray; |
||
| 141 | } |
||
| 142 | |||
| 143 | # Project Colours from http://boinc.netsoft-online.com/e107_plugins/forum/forum_viewtopic.php?3 |
||
| 144 | sub rgb($$$) {
|
||
| 145 | return sprintf( '%02x%02x%02x', shift, shift, shift ); |
||
| 146 | } |
||
| 147 | my %project_colour = ( |
||
| 148 | 'climatepredition.net' => rgb( 0, 139, 69 ), |
||
| 149 | 'Predictor@Home' => rgb( 135, 206, 235 ), |
||
| 150 | 'SETI@home' => rgb( 65, 105, 225 ), |
||
| 151 | 'Einstein@Home' => rgb( 255, 165, 0 ), |
||
| 152 | 'Rosetta@home' => rgb( 238, 130, 238 ), |
||
| 153 | 'PrimeGrid' => rgb( 205, 197, 191 ), |
||
| 154 | 'LHC@home' => rgb( 255, 127, 80 ), |
||
| 155 | 'World Community Grid' => rgb( 250, 128, 114 ), |
||
| 156 | 'BURP' => rgb( 0, 255, 127 ), |
||
| 157 | 'SZTAKI Desktop Grid' => rgb( 205, 79, 57 ), |
||
| 158 | 'uFluids' => rgb( 0, 0, 0 ), |
||
| 159 | 'SIMAP' => rgb( 143, 188, 143 ), |
||
| 160 | 'Folding@Home' => rgb( 153, 50, 204 ), |
||
| 161 | 'MalariaControl' => rgb( 30, 144, 255 ), |
||
| 162 | 'The Lattice Project' => rgb( 0, 100, 0 ), |
||
| 163 | 'Pirates@Home' => rgb( 127, 255, 0 ), |
||
| 164 | 'BBC Climate Change Experiment' => rgb( 205, 173, 0 ), |
||
| 165 | 'Leiden Classical' => rgb( 140, 34, 34 ), |
||
| 166 | 'SETI@home Beta' => rgb( 152, 245, 255 ), |
||
| 167 | 'RALPH@Home' => rgb( 250, 240, 230 ), |
||
| 168 | 'QMC@HOME' => rgb( 144, 238, 144 ), |
||
| 169 | 'XtremLab' => rgb( 130, 130, 130 ), |
||
| 170 | 'HashClash' => rgb( 255, 105, 180 ), |
||
| 171 | 'cpdn seasonal' => rgb( 255, 255, 255 ), |
||
| 172 | 'Chess960@Home Alpha' => rgb( 165, 42, 42 ), |
||
| 173 | 'vtu@home' => rgb( 255, 0, 0 ), |
||
| 174 | 'LHC@home alpha' => rgb( 205, 133, 63 ), |
||
| 175 | 'TANPAKU' => rgb( 189, 183, 107 ), |
||
| 176 | 'other' => rgb( 255, 193, 37 ), |
||
| 177 | 'Rectilinear Crossing Number' => rgb( 83, 134, 139 ), |
||
| 178 | 'Nano-Hive@Home' => rgb( 193, 205, 193 ), |
||
| 179 | 'Spinhenge@home' => rgb( 255, 240, 245 ), |
||
| 180 | 'RieselSieve' => rgb( 205, 183, 158 ), |
||
| 181 | 'Project Neuron' => rgb( 139, 58, 98 ), |
||
| 182 | 'RenderFarm@Home' => rgb( 210, 105, 30 ), |
||
| 183 | 'Docking@Home' => rgb( 178, 223, 238 ), |
||
| 184 | 'proteins@home' => rgb( 0, 0, 255 ), |
||
| 185 | 'DepSpid' => rgb( 139, 90, 43 ), |
||
| 186 | 'ABC@home' => rgb( 222, 184, 135 ), |
||
| 187 | 'BOINC alpha test' => rgb( 245, 245, 220 ), |
||
| 188 | 'WEP-M+2' => rgb( 0, 250, 154 ), |
||
| 189 | 'Zivis Superordenador Ciudadano' => rgb( 255, 239, 219 ), |
||
| 190 | 'SciLINC' => rgb( 240, 248, 255 ), |
||
| 191 | 'APS@Home' => rgb( 205, 91, 69 ), |
||
| 192 | 'PS3GRID' => rgb( 0, 139, 139 ), |
||
| 193 | 'Superlink@Technion' => rgb( 202, 255, 112 ), |
||
| 194 | 'BRaTS@Home' => rgb( 255, 106, 106 ), |
||
| 195 | 'Cosmology@Home' => rgb( 240, 230, 140 ), |
||
| 196 | 'SHA 1 Collision Search' => rgb( 255, 250, 205 ), |
||
| 197 | ); |
||
| 198 | |||
| 199 | if ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
|
||
| 200 | if ($ret) {
|
||
| 201 | print $ret; |
||
| 202 | exit 1; |
||
| 203 | } |
||
| 204 | my @projdata = load_data(); |
||
| 205 | print <<EOF; |
||
| 206 | graph_args --base 1000 --logarithmic |
||
| 207 | graph_vlabel Cobblestones |
||
| 208 | 84c28707 | dipohl | graph_category htc |
| 209 | 480eb0f3 | Paul Saunders | graph_title BOINC Total Credit |
| 210 | EOF |
||
| 211 | foreach ( sort { $a->{id} <=> $b->{id} } @projdata ) {
|
||
| 212 | my $fieldname = 'proj' . $_->{id};
|
||
| 213 | print <<EOF; |
||
| 214 | $fieldname.label $_->{name}
|
||
| 215 | $fieldname.type GAUGE |
||
| 216 | $fieldname.info Total Credit for project $_->{name}
|
||
| 217 | EOF |
||
| 218 | if ( exists $project_colour{ $_->{name} } ) {
|
||
| 219 | print "$fieldname.colour $project_colour{$_->{name}}\n";
|
||
| 220 | } |
||
| 221 | } |
||
| 222 | save_data(@projdata); |
||
| 223 | exit 0; |
||
| 224 | } |
||
| 225 | |||
| 226 | my @projdata = load_data(); |
||
| 227 | foreach ( sort { $a->{id} <=> $b->{id} } @projdata ) {
|
||
| 228 | my $fieldname = 'proj' . $_->{id};
|
||
| 229 | print "$fieldname.value $_->{credit}\n";
|
||
| 230 | printf "$fieldname.extinfo %.2f%% of Total Credit (%.2f out of %.2f)\n", |
||
| 231 | $_->{creditfract} * 100, $_->{credit}, $_->{totalcredit};
|
||
| 232 | } |
||
| 233 | save_data(@projdata); |
||
| 234 | exit 0; |
