Projet

Général

Profil

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

root / plugins / smf / smf_online @ 63351ab5

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

1
#!/usr/bin/perl
2
#
3
# Munin plugin for online users 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 Users Online
43
graph_vlabel Number of sessions
44
graph_category forum
45
guests.label Guests
46
graph_scale no
47
all.warning  1000
48
all.critical 10000
49
EOC
50
;
51
    print <<EOC
52
users.label Registered Users
53
EOC
54
;
55
    print <<EOC
56
spiders.label Spiders
57
EOC
58
;
59
    print <<EOC
60
all.label All
61
EOC
62
;
63
    exit 0;
64
}
65

    
66
#Guests count
67
my $guests = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT(*) FROM ${DATABASE}.${PREFIX}log_online WHERE id_member = 0 AND id_spider = 0'`;
68
$guests =~ /(\d+)/; 
69
print "guests.value ".$1."\n";
70

    
71
#Spiders count
72
my $spiders = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT(*) FROM ${DATABASE}.${PREFIX}log_online WHERE id_spider > 0'`;
73
$spiders =~ /(\d+)/; 
74
print "spiders.value ".$1."\n";
75

    
76
#Users count
77
my $users = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT(*) FROM ${DATABASE}.${PREFIX}log_online WHERE id_member > 0'`;
78
$users =~/(\d+)/;
79
print "users.value ".$1."\n";
80

    
81
#All count
82
my $all = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT(*) FROM ${DATABASE}.${PREFIX}log_online'`;
83
$all =~/(\d+)/;
84
print "all.value ".$1."\n";