-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpads_stats
executable file
·151 lines (114 loc) · 4.09 KB
/
pads_stats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
# vim: set filetype=perl sw=4 tabstop=4 expandtab smartindent: #
=head1 NAME
pads_stats_- plugin to get stats from etherpad lite (must have the ep_pads_stats plugin)
=head1 AUTHOR AND COPYRIGHT
Copyright 2015 Luc Didry <luc AT didry.org>
=head1 HOWTO CONFIGURE AND USE :
=over
=item - /etc/munin/plugin-conf.d/pads_stats
[pads_stats]
env.urls https://pad.example.org https://pad.whatever.org
=item - env.urls
This is the URLs of the etherpad instances to get stats from (without trailing slash)
You can specify the port, or a login and a password for HTTP authentication
https://login:password@pad.example.org:9001
=item - /etc/munin/plugins
ln -s pads_stats /etc/munin/plugins/pads_stats
=item - restart Munin node
service munin-node restart
=back
=head1 DEPENDENCIES
You will need the Perl distribution Mojolicious
Although it is certainly available in your GNU/Linux packages, it recommended to install it trough the cpan command:
cpan Mojolicious
If you want to monitor secured etherpad instances (HTTPS), you need IO::Socket::SSL (may require libssl-dev to install)
cpan IO::Socket::SSL
=head1 LICENSE
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
=cut
use warnings;
use strict;
use Munin::Plugin;
use Mojo::UserAgent;
use Mojo::JSON qw(decode_json);
my $PLUGIN_NAME = 'pads_stats';
munin_exit_fail() unless (defined($ENV{urls}));
my @urls = split(' ', $ENV{urls});
##### config
if( (defined $ARGV[0]) && ($ARGV[0] eq 'config') ) {
print "multigraph pads_stats\n";
print "graph_title Pads Stats\n";
print "graph_vlabel Number of pads\n";
print "graph_args --lower-limit 0\n";
print "graph_category etherpad\n";
print "graph_total Total\n";
print "graph_info This graph shows the count of pads across multiple Etherpad lite instance\n";
my $i = 0;
for my $url (@urls) {
my $u = Mojo::URL->new($url);
my $host = $u->host;
$host =~ s/\./_/g;
my $draw = ($i++) ? 'AREASTACK' : 'AREA';
print "$host.label $host\n";
print "$host.draw $draw\n";
}
for my $url (@urls) {
my $u = Mojo::URL->new($url);
my $host = $u->host;
$host =~ s/\./_/g;
print "multigraph pads_stats.$host\n";
print "graph_title Pads Stats for ".$u->host."\n";
print "graph_vlabel Number of pads on ".$u->host."\n";
print "graph_args --lower-limit 0\n";
print "graph_category etherpad\n";
print "$host.label $host\n";
print "$host.draw AREA\n";
}
munin_exit_done();
}
##### fetch
my $ua = Mojo::UserAgent->new();
my %cache;
for my $url (@urls) {
$url = $url.'/stats.json';
my $u = Mojo::URL->new($url);
my $tx = $ua->get($url);
if (my $res = $tx->success) {
my $r = decode_json($res->body);
my $host = $u->host;
$host =~ s/\./_/g;
print $host, '.value ', $r->{padsCount}, "\n";
$cache{$host} = $r->{padsCount};
}
}
for my $url (@urls) {
my $u = Mojo::URL->new($url);
my $host = $u->host;
$host =~ s/\./_/g;
print "multigraph pads_stats.$host\n";
print $host, '.value ', $cache{$host}, "\n";
}
munin_exit_done();
#
##
### INTERNALS FONCTIONS
###############################################################################
sub munin_exit_done {
munin_exit(0);
} ## sub munin_exit_done
sub munin_exit_fail {
munin_exit(1);
} ## sub munin_exit_fail
sub munin_exit {
my $exitcode = shift;
exit($exitcode) if(defined $exitcode);
exit(1);
} ## sub munin_exit