Projet

Général

Profil

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

root / plugins / spotweb / spotweb_average @ 8589c6df

Historique | Voir | Annoter | Télécharger (2,78 ko)

1
#!/usr/bin/perl
2
#
3
# Munin plugin for number of spots in a MySQL database
4
#
5
# Copyright (C) 2011 - Rowdy Schwachöfer (http://rowdy.nl)
6
#
7
# Spotweb       : http://github.com/spotweb/spotweb
8
# Original idea : smeerbartje (http://gathering.tweakers.net/forum/myreact/190949)
9
#                 slommer     (http://gathering.tweakers.net/forum/myreact/353335)
10
#
11
# This program is free software: you can redistribute it and/or modify 
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation, either version 3 of the License, or
14
# (at your option) any later version.
15
#
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
# GNU General Public License for more details.
20
#
21
# You should have received a copy of the GNU General Public License
22
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
#
24
#
25
# Configuration example
26
#
27
# [spotweb*]
28
# env.mysql /usr/bin/mysql                               # MySQL binary (optional)
29
# env.mysqlopts -u <MYSQL_USERNAME> -p<MYSQL_PASSWORD>   # How to connect to the database (optional if no password is set)
30
# env.database spotweb                                   # Spotweb database (optional)
31
#
32
# [spotweb_average]
33
# env.period 1800                                        # The period over which to check in seconds, default to 30 minutes (1800 seconds)
34
# env.watchlist yes                                      # Show items in the watchlist (period independent)
35
#
36
#
37

    
38
use strict;
39

    
40
my $MYSQL = $ENV{mysql} || "/usr/bin/mysql";
41
my $MYSQLOPTS = $ENV{mysqlopts} || "";
42
my $DATABASE = $ENV{database} || "spotweb";
43
my $PERIOD = $ENV{period} || 1800;
44
my $SHOW_WATCHLIST = $ENV{watchlist} || "yes";
45
my $FROMSTAMP = time - $PERIOD;
46
my $TITLE = "Spotweb (".($PERIOD / 60)." minute average)";
47

    
48
# Output for config
49
if(defined $ARGV[0] && $ARGV[0] eq 'config')
50
{
51
    print <<EOC
52
graph_title $TITLE
53
graph_vlabel Totals
54
graph_category other
55
spots.label New Spots
56
downloaded.label Downloads
57
EOC
58
;
59

    
60
    if($SHOW_WATCHLIST eq 'yes') {
61
		print <<EOC
62
watchlist.label Watchlist (total)
63
EOC
64
;
65
    }
66
    exit 0;
67
}
68

    
69
# Spot count
70
my $spots = `$MYSQL $MYSQLOPTS -e 'SELECT count(*) as spots FROM $DATABASE.spots WHERE stamp > $FROMSTAMP;'`;
71
$spots =~ /(\d+)/; 
72
print "spots.value ".$1."\n";
73

    
74
# Downloaded
75
my $downloaded = `$MYSQL $MYSQLOPTS -e 'SELECT count(messageid) as comments FROM $DATABASE.spotstatelist WHERE download IS NOT NULL'`;
76
$downloaded =~ /(\d+)/;
77
print "downloaded.value ".$1."\n";
78

    
79
# Watchlist
80
if($SHOW_WATCHLIST eq 'yes') {
81
	my $watchlist = `$MYSQL $MYSQLOPTS -e 'SELECT count(messageid) as watchlist FROM $DATABASE.spotstatelist WHERE watch IS NOT NULL'`;
82
	$watchlist =~ /(\d+)/;
83
	print "watchlist.value ".$1."\n";
84
}