Projet

Général

Profil

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

root / plugins / spotweb / spotweb_total @ 332c74d7

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

1 e7dfd772 Rowdy.nl
#!/usr/bin/perl
2
#
3
# Munin plugin for different stats over a spotweb 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_total]
33
# env.spotsfull yes                                      # Also show Full spots?
34
#
35
#
36
37
use strict;
38
39
my $MYSQL = $ENV{mysql} || "/usr/bin/mysql";
40
my $MYSQLOPTS = $ENV{mysqlopts} || "";
41
my $DATABASE = $ENV{database} || "spotweb";
42
my $SPOTSFULL = $ENV{spotsfull} || "yes";
43
44
# Output for config
45
if(defined $ARGV[0] && $ARGV[0] eq 'config') {
46
    print <<EOC
47
graph_title Spotweb spots and comments (Totals)
48
graph_vlabel Spots/comments
49
graph_category spotweb
50
spots.label Spots
51
EOC
52
;
53
54
    if($SPOTSFULL eq 'yes') {
55
        print <<EOC
56
spotsfull.label Full spots
57
EOC
58
;
59
    }
60
61
    print <<EOC
62
comments.label Comments
63
EOC
64
;
65
        exit 0;
66
}
67
68
# Spot count
69
my $spots = `$MYSQL $MYSQLOPTS -e 'SELECT count(*) as spots FROM $DATABASE.spots;'`;
70
$spots =~ /(\d+)/; 
71
print "spots.value ".$1."\n";
72
73
if($SPOTSFULL eq 'yes') {
74
    my $spotsfull = `$MYSQL $MYSQLOPTS -e 'SELECT count(*) as fullspots FROM $DATABASE.spotsfull;'`;
75
    $spotsfull =~ /(\d+)/;
76
    print "spotsfull.value ".$1."\n";
77
}
78
79
# Comment count
80
my $comments = `$MYSQL $MYSQLOPTS -e 'SELECT count(*) as comments FROM $DATABASE.commentsxover'`;
81
$comments =~/(\d+)/;
82
print "comments.value ".$1."\n";