Projet

Général

Profil

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

root / plugins / smf / smf_stats @ 17f78427

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

1 624d53fb realdigger
#!/usr/bin/perl
2
#
3 97c6ae56 realdigger
# Munin plugin for members, messages and topics stats over a SMF forum database
4 624d53fb realdigger
#
5
# Copyright (C) 2013 - digger (http://simplemachines.ru)
6
# Based on Rowdy Schwachfer (http://rowdy.nl) 's Spotweb plugin
7
#
8
#
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
13
#
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
#
22
#
23
# Configuration example
24
#
25
#[smf*]
26
#env.mysql               /usr/bin/mysql           # MySQL binary (optional)
27
#env.db                  smf                      # SMF database (required)
28 2db7c069 realdigger
#env.db_prefix           smf_                     # SMF database prefix(required)
29 624d53fb realdigger
#env.db_user             myuser                   # SMF database user (required)
30
#env.db_password         mypassword               # SMF database password (required)
31
32
use strict;
33
34
my $MYSQL = $ENV{'mysql'} || "/usr/bin/mysql";
35
my $MYSQLOPTS = "-u " . $ENV{'db_user'} . " -p" . $ENV{'db_password'};
36
my $DATABASE = $ENV{'db'} || "smf";
37
my $PREFIX = $ENV{'db_prefix'} || "smf_";
38
39
# Output for config
40
if(defined $ARGV[0] && $ARGV[0] eq 'config') {
41
    print <<EOC
42
graph_title SMF Statistics
43
graph_vlabel Number of items
44 63351ab5 dipohl
graph_category forum
45 624d53fb realdigger
members.label Total members
46
graph_scale no
47
EOC
48
;
49
    print <<EOC
50
messages.label Total messages
51
EOC
52
;
53
    print <<EOC
54
topics.label Total topics
55
EOC
56
;
57
    exit 0;
58
}
59
60
#Members count
61
my $members = `$MYSQL $MYSQLOPTS -e 'SELECT value FROM ${DATABASE}.${PREFIX}settings WHERE variable = "totalMembers"'`;
62 17f78427 Lars Kruse
$members =~ /(\d+)/;
63 624d53fb realdigger
print "members.value ".$1."\n";
64
65
#Messages count
66
my $messages = `$MYSQL $MYSQLOPTS -e 'SELECT value FROM ${DATABASE}.${PREFIX}settings WHERE variable="totalMessages"'`;
67 17f78427 Lars Kruse
$messages =~ /(\d+)/;
68 624d53fb realdigger
print "messages.value ".$1."\n";
69
70
#Topics count
71
my $topics = `$MYSQL $MYSQLOPTS -e 'SELECT value FROM ${DATABASE}.${PREFIX}settings WHERE variable="totalTopics"'`;
72
$topics =~/(\d+)/;
73
print "topics.value ".$1."\n";