Projet

Général

Profil

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

root / plugins / wuala / wuala_stats @ 46e2de55

Historique | Voir | Annoter | Télécharger (4,31 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

    
37
if ($ARGV[0] and $ARGV[0] eq "config")
38
{
39
	if($0 =~ /.*_uptime/) {
40
		print "graph_args -l0 --vertical-label %\n";
41
		print "graph_title Wuala Uptime\n";
42
		print "graph_category backup\n";
43
		print "graph_info This graph shows the Wua.la uptime\n";
44
		print "uptime.label Uptime\n";
45
		print "uptime.draw LINE2\n";
46
		print "uptime.info Uptime of the Wua.la Client on this computer.\n";
47
	} elsif($0 =~ /.*_storage/) {
48
		print "graph_args --base 1024 -l 0 --vertical-label GB\n";
49
		print "graph_title Wuala Storage\n";
50
		print "graph_category backup\n";
51
		print "graph_info This graph shows several storage related statistics of Wua.la.\n";
52
		print "limit.label Local Storage Limit\n";
53
		print "limit.draw LINE2\n";
54
		print "limit.info Local shared storage.\n";
55
		print "earned.label Local Earned Storage\n";
56
		print "earned.draw LINE2\n";
57
		print "earned.info Sum of local earned storage.\n";
58
		print "local.label Remote earned storage.\n";
59
		print "local.draw LINE1\n";
60
		print "local.info Storage earned on other nodes.\n";
61
		print "quota.label Sum of available storage.\n";
62
		print "quota.draw LINE2\n";
63
		print "quota.info The sum of the available storage.\n";
64
		print "used.label Used storage.\n";
65
		print "used.draw LINE2\n";
66
		print "used.info The amount of free storage.\n";
67
	}
68
} else {
69
	if($0 =~ /.*_uptime/) {
70
		get_uptime();
71
	} elsif($0 =~ /.*_storage/) {
72
		get_storage();
73
	}
74
}
75
# Report the wua.la storage
76
# values.
77
sub get_storage
78
{
79
	my $limit = U;
80
	my $earned = U;
81
	my $localStored = U;
82
	my $quota = U;
83
	my $used = U;
84
	if(is_running()) {
85
	chdir($wualadir);
86
	open(WUALA, "$wualadir/wualacmd tradeStats |");
87
	while(my $line = <WUALA>) {
88
	  #print "D: ".$line;
89
	  if ($line =~ /Current limit/) {
90
	    $line =~ s/Current limit: ([0-9]*.?[0-9]*) GB/$1/i;
91
	    $limit = trim($line);
92
	    #print "Current limit: ".$limit."\n";
93
	  } elsif ($line =~ /Earned storage:/) {
94
	    $line =~ s/Earned storage: ([0-9]*.?[0-9]*) GB/$1/i;
95
	    $earned = trim($line);
96
	    #print "Earned: ".$earned."\n";
97
	  } elsif ($line =~ /Locally stored data/) {
98
	    $line =~ s/Locally stored data .*: ([0-9]*.?[0-9]*) GB/$1/i;
99
	    $localStored = trim($line);
100
	    #print "Local data: ".$localStored."\n";
101
	  }
102
	}
103
	close(WUALA);
104
	open(WUALA, "$wualadir/wualacmd showQuota |");
105
	while(my $line = <WUALA>) {
106
	  #print "D: ".$line;
107
	  if($line =~ /Quota:/) {
108
	    $line =~ s/Quota: ([0-9]*.[0-9]*) GB/$1/i;
109
	    $quota = trim($line);
110
	    #print "Quota: ".$quota."\n";
111
	  } elsif ($line =~ /List use/) {
112
	    $line =~ s/List use: ([0-9]*.?[0-9]*) GB/$1/i;
113
	    $used = trim($line);
114
	    #print "Used: $used\n";
115
	  }
116
	}
117
	close(WUALA);
118
	}
119
	print "limit.value $limit\n";
120
	print "earned.value $earned\n";
121
	print "local.value $localStored\n";
122
	print "quota.value $quota\n";
123
	print "used.value $used\n";
124
}
125
# Return the wua.la uptime in percent of day.
126
sub get_uptime
127
{
128
	my $uptime = U;
129
	if(is_running()) {
130
	chdir($wualadir);
131
	open(WUALA, "$wualadir/wualacmd tradeStats |");
132
	while(my $line = <WUALA>) {
133
	  #print "D: ".$line;
134
	  if($line =~ /Average online time/) {
135
	    $line =~ s/Average online time: ([0-9]*.[0-9]*)%/$1/i;
136
	    $uptime = trim($line);
137
	  }
138
	}
139
	close(WUALA);
140
	}
141
	print "uptime.value $uptime\n";
142
}
143
# Determine if wua.la is running.
144
sub is_running
145
{
146
	$output = qx(ps aux | grep loader2.jar);
147
	if($output =~ /java/) {
148
		return 1;
149
	}
150
}
151
# Remove whitespaces (inclduing tabs and newlines) from the
152
# given string.
153
sub trim
154
{
155
	my $string = shift;
156
	$string =~ s/^\s+//;
157
	$string =~ s/\s+$//;
158
	return $string;
159
}