Projet

Général

Profil

Révision 624d53fb

ID624d53fbc25019a2d9f5afd3d7f3d053d856f636
Parent 0e3f150b
Enfant 24bd2f7c

Ajouté par realdigger il y a plus de 12 ans

Create smf_stats

Voir les différences:

plugins/forums/smf_stats
1
#!/usr/bin/perl
2
#
3
# Munin plugin for different stats over a SMF forum database
4
#
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
#env.db_prefix           _smf                     # SMF database prefix(required)
29
#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
graph_category SMF
45
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
$members =~ /(\d+)/; 
63
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
$messages =~ /(\d+)/; 
68
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";

Formats disponibles : Unified diff