root / plugins / wuala / wuala_stats @ 430d68ff
Historique | Voir | Annoter | Télécharger (4,38 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monior the Wua.la Linux client |
| 4 |
# for shared, social storage from http://wua.la. |
| 5 |
# |
| 6 |
# Author: Dominik Schulz <lkml@ds.gauner.org> |
| 7 |
# URL: http://developer.gauner.org/munin/ |
| 8 |
# |
| 9 |
# Configuration: |
| 10 |
# |
| 11 |
# Set env.wualadir <yourpathtowuala>, e.g. /home/fred/wuala |
| 12 |
# and user fred. Please note, that if you don't run this |
| 13 |
# plugin as the correct user it won't work, since the |
| 14 |
# wualacmd command will only work when running as the correct user. |
| 15 |
# |
| 16 |
# The Plugin tries to detect if wuala is running and will |
| 17 |
# report unknown (U) as values if it is not running. |
| 18 |
# |
| 19 |
# This is a dual-personality plugin. If the file- or |
| 20 |
# softlink-name of this plugin ends in _storage it will report |
| 21 |
# the storage values and if it ends in _uptime it will report the |
| 22 |
# uptime. |
| 23 |
# |
| 24 |
# Example Configuration: |
| 25 |
# |
| 26 |
# [wuala*] |
| 27 |
# user fred |
| 28 |
# env.wualadir /home/fred/wuala |
| 29 |
# |
| 30 |
# Parameters: |
| 31 |
# |
| 32 |
# config (required) |
| 33 |
# |
| 34 |
my $wualadir = $ENV{wualadir};
|
| 35 |
|
| 36 |
if ($ARGV[0] and $ARGV[0] eq "autoconf") |
| 37 |
{
|
| 38 |
print "no\n"; |
| 39 |
exit 1; |
| 40 |
} elsif ($ARGV[0] and $ARGV[0] eq "config") |
| 41 |
{
|
| 42 |
if($0 =~ /.*_uptime/) {
|
| 43 |
print "graph_args -l0 --vertical-label %\n"; |
| 44 |
print "graph_title Wuala Uptime\n"; |
| 45 |
print "graph_category wuala\n"; |
| 46 |
print "graph_info This graph shows the Wua.la uptime\n"; |
| 47 |
print "uptime.label Uptime\n"; |
| 48 |
print "uptime.draw LINE2\n"; |
| 49 |
print "uptime.info Uptime of the Wua.la Client on this computer.\n"; |
| 50 |
} elsif($0 =~ /.*_storage/) {
|
| 51 |
print "graph_args --base 1024 -l 0 --vertical-label GB\n"; |
| 52 |
print "graph_title Wuala Storage\n"; |
| 53 |
print "graph_category wuala\n"; |
| 54 |
print "graph_info This graph shows several storage related statistics of Wua.la.\n"; |
| 55 |
print "limit.label Local Storage Limit\n"; |
| 56 |
print "limit.draw LINE2\n"; |
| 57 |
print "limit.info Local shared storage.\n"; |
| 58 |
print "earned.label Local Earned Storage\n"; |
| 59 |
print "earned.draw LINE2\n"; |
| 60 |
print "earned.info Sum of local earned storage.\n"; |
| 61 |
print "local.label Remote earned storage.\n"; |
| 62 |
print "local.draw LINE1\n"; |
| 63 |
print "local.info Storage earned on other nodes.\n"; |
| 64 |
print "quota.label Sum of available storage.\n"; |
| 65 |
print "quota.draw LINE2\n"; |
| 66 |
print "quota.info The sum of the available storage.\n"; |
| 67 |
print "used.label Used storage.\n"; |
| 68 |
print "used.draw LINE2\n"; |
| 69 |
print "used.info The amount of free storage.\n"; |
| 70 |
} |
| 71 |
} else {
|
| 72 |
if($0 =~ /.*_uptime/) {
|
| 73 |
get_uptime(); |
| 74 |
} elsif($0 =~ /.*_storage/) {
|
| 75 |
get_storage(); |
| 76 |
} |
| 77 |
} |
| 78 |
# Report the wua.la storage |
| 79 |
# values. |
| 80 |
sub get_storage |
| 81 |
{
|
| 82 |
my $limit = U; |
| 83 |
my $earned = U; |
| 84 |
my $localStored = U; |
| 85 |
my $quota = U; |
| 86 |
my $used = U; |
| 87 |
if(is_running()) {
|
| 88 |
chdir($wualadir); |
| 89 |
open(WUALA, "$wualadir/wualacmd tradeStats |"); |
| 90 |
while(my $line = <WUALA>) {
|
| 91 |
#print "D: ".$line; |
| 92 |
if ($line =~ /Current limit/) {
|
| 93 |
$line =~ s/Current limit: ([0-9]*.?[0-9]*) GB/$1/i; |
| 94 |
$limit = trim($line); |
| 95 |
#print "Current limit: ".$limit."\n"; |
| 96 |
} elsif ($line =~ /Earned storage:/) {
|
| 97 |
$line =~ s/Earned storage: ([0-9]*.?[0-9]*) GB/$1/i; |
| 98 |
$earned = trim($line); |
| 99 |
#print "Earned: ".$earned."\n"; |
| 100 |
} elsif ($line =~ /Locally stored data/) {
|
| 101 |
$line =~ s/Locally stored data .*: ([0-9]*.?[0-9]*) GB/$1/i; |
| 102 |
$localStored = trim($line); |
| 103 |
#print "Local data: ".$localStored."\n"; |
| 104 |
} |
| 105 |
} |
| 106 |
close(WUALA); |
| 107 |
open(WUALA, "$wualadir/wualacmd showQuota |"); |
| 108 |
while(my $line = <WUALA>) {
|
| 109 |
#print "D: ".$line; |
| 110 |
if($line =~ /Quota:/) {
|
| 111 |
$line =~ s/Quota: ([0-9]*.[0-9]*) GB/$1/i; |
| 112 |
$quota = trim($line); |
| 113 |
#print "Quota: ".$quota."\n"; |
| 114 |
} elsif ($line =~ /List use/) {
|
| 115 |
$line =~ s/List use: ([0-9]*.?[0-9]*) GB/$1/i; |
| 116 |
$used = trim($line); |
| 117 |
#print "Used: $used\n"; |
| 118 |
} |
| 119 |
} |
| 120 |
close(WUALA); |
| 121 |
} |
| 122 |
print "limit.value $limit\n"; |
| 123 |
print "earned.value $earned\n"; |
| 124 |
print "local.value $localStored\n"; |
| 125 |
print "quota.value $quota\n"; |
| 126 |
print "used.value $used\n"; |
| 127 |
} |
| 128 |
# Return the wua.la uptime in percent of day. |
| 129 |
sub get_uptime |
| 130 |
{
|
| 131 |
my $uptime = U; |
| 132 |
if(is_running()) {
|
| 133 |
chdir($wualadir); |
| 134 |
open(WUALA, "$wualadir/wualacmd tradeStats |"); |
| 135 |
while(my $line = <WUALA>) {
|
| 136 |
#print "D: ".$line; |
| 137 |
if($line =~ /Average online time/) {
|
| 138 |
$line =~ s/Average online time: ([0-9]*.[0-9]*)%/$1/i; |
| 139 |
$uptime = trim($line); |
| 140 |
} |
| 141 |
} |
| 142 |
close(WUALA); |
| 143 |
} |
| 144 |
print "uptime.value $uptime\n"; |
| 145 |
} |
| 146 |
# Determine if wua.la is running. |
| 147 |
sub is_running |
| 148 |
{
|
| 149 |
$output = qx(ps aux | grep loader2.jar); |
| 150 |
if($output =~ /java/) {
|
| 151 |
return 1; |
| 152 |
} |
| 153 |
} |
| 154 |
# Remove whitespaces (inclduing tabs and newlines) from the |
| 155 |
# given string. |
| 156 |
sub trim |
| 157 |
{
|
| 158 |
my $string = shift; |
| 159 |
$string =~ s/^\s+//; |
| 160 |
$string =~ s/\s+$//; |
| 161 |
return $string; |
| 162 |
} |
