Projet

Général

Profil

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

root / plugins / joomla / joomla-sessions @ 29bdf34e

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

1
#!/usr/bin/perl
2

    
3
=head1 NAME
4

    
5
joomla-sessions - Munin plugin for different stats over a Joomla MySQL
6
database
7

    
8
=head1 CONFIGURATION
9

    
10
=over
11

    
12
=item env.mysql
13

    
14
Optional, path to the MySQL binary.  Defaults to C</usr/bin/mysql>.
15

    
16
=item env.mysqlopts
17

    
18
Optional, command line options for "mysql". May be used to set
19
username and password.  No default value.
20

    
21
=item env.database
22

    
23
Optional, name of the joomla database name.  Defaults to C<mydatabase>.
24

    
25
=back
26

    
27
=head2 Configuration example
28

    
29

    
30
  [joomla_sessions*]
31
    env.mysql /usr/bin/mysql                               # MySQL binary (optional)
32
    env.mysqlopts -u <MYSQL_USERNAME> -p<MYSQL_PASSWORD>   # How to connect to the database (optional if no password is set)
33
    env.database databasename                              # Joomla database (optional)
34

    
35
=head1 AUTHORS
36

    
37
Copyright (C) 2011 - Csaba Martha (http://www.zenebuzi.com)
38

    
39
Based on Rowdy Schwachfer (http://rowdy.nl) 's Spotweb plugin
40

    
41
=head1 LICENSE
42

    
43
GPLv3 or later
44

    
45

    
46
=cut
47

    
48
# This program is free software: you can redistribute it and/or modify
49
# it under the terms of the GNU General Public License as published by
50
# the Free Software Foundation, either version 3 of the License, or
51
# (at your option) any later version.
52
#
53
# This program is distributed in the hope that it will be useful,
54
# but WITHOUT ANY WARRANTY; without even the implied warranty of
55
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56
# GNU General Public License for more details.
57
#
58
# You should have received a copy of the GNU General Public License
59
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
60

    
61
use strict;
62

    
63
my $MYSQL = $ENV{mysql} || "/usr/bin/mysql";
64
my $MYSQLOPTS = $ENV{mysqlopts} || "";
65
my $DATABASE = $ENV{database} || "mydatabase";
66

    
67
# Output for config
68
if(defined $ARGV[0] && $ARGV[0] eq 'config') {
69
    print <<EOC
70
graph_title Joomla Actual User Sessions (Totals)
71
graph_vlabel Session Number
72
graph_category cms
73
anonsessions.label Anonym Sessions
74
graph_scale no
75
all.warning 10000
76
all.critical 15000
77
EOC
78
;
79
    print <<EOC
80
all.label All
81
EOC
82
;
83
    print <<EOC
84
registered.label Registered
85
EOC
86
;
87

    
88
        exit 0;
89
}
90

    
91
#Anonym Session count
92
my $anonsessions = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT( session_id ) FROM $DATABASE.jos_session WHERE usertype = "''"'`;
93
$anonsessions =~ /(\d+)/; 
94
print "anonsessions.value ".$1."\n";
95

    
96
#Registered count
97
my $registered = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT(usertype) FROM $DATABASE.jos_session WHERE usertype = "'Registered'"'`;
98
$registered =~/(\d+)/;
99
print "registered.value ".$1."\n";
100

    
101
#All count
102
my $all = `$MYSQL $MYSQLOPTS -e 'SELECT COUNT(usertype) FROM $DATABASE.jos_session'`;
103
$all =~/(\d+)/;
104
print "all.value ".$1."\n";