-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathmunin-httpd
More file actions
executable file
·186 lines (126 loc) · 4.14 KB
/
Copy pathmunin-httpd
File metadata and controls
executable file
·186 lines (126 loc) · 4.14 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/perl -T
use strict;
use warnings;
package Munin::Master::Http;
use HTTP::Server::Simple::CGI::PreFork;
use base qw(HTTP::Server::Simple::CGI::PreFork);
use Munin::Master::Graph;
use Munin::Master::HTML;
use Munin::Common::Logger;
sub handle_request {
my $self = shift;
my $cgi = shift; # XXX - this is NOT thread-safe?
my $path = $cgi->path_info();
# Dispatch by extension, so we can have the same URL prefix
my $is_graph
= ( $path !~ m/\.html$/x ) && ( $path =~ m/.*-(day|hour|week|month|year|pinpoint).*$/x );
if ($is_graph) {
Munin::Master::Graph::handle_request($cgi);
}
else {
Munin::Master::HTML::handle_request($cgi);
}
return;
}
package main; ## no critic qw(Modules::ProhibitMultiplePackages)
use Getopt::Long;
my $listen = ":";
my $debug = 0;
my $stdout = 0;
my $loglevel = 'info';
print_usage_and_exit()
unless GetOptions(
"listen=s" => \$listen,
"debug" => \$debug,
"stdout" => \$stdout,
"loglevel=s" => \$loglevel,
"version" => \&print_version_and_exit,
"help" => \&print_usage_and_exit,
);
die "ERROR: Invalid listen argument supplied: '$listen'\n" unless $listen =~ /^((\S*|\[\S+\]):)?(\d+)?$/x;
my $host = defined $2 ? $2 : "*";
my $port = defined $3 ? $3 : 4948;
# start the server
if ($debug) {
Munin::Common::Logger::configure( output => 'screen', level => 'debug');
Munin::Common::Logger::INFO("Starting in debug mode\n");
Munin::Master::Http->new( { host => $host, port => $port } )->run();
exit;
}
if ($stdout) {
Munin::Common::Logger::configure( output => 'screen',
level => $loglevel);
} else {
# FIXME: Logfile location to be taken from install-time config?
Munin::Common::Logger::configure( output => 'file',
level => $loglevel,
logfile => '/var/log/munin/munin-httpd.log' );
}
Munin::Common::Logger::INFO("Starting preforking munin http server at $host:$port");
Munin::Master::Http->new( { host => $host, port => $port } )->run(
prefork => ($max_servers > 0),
min_servers => 1,
max_servers => $max_servers,
min_spare_servers => 1,
max_spare_servers => $max_servers / 10,
);
sub print_usage_and_exit {
require Pod::Usage;
Pod::Usage::pod2usage( -verbose => 1 );
}
sub print_version_and_exit {
require Pod::Usage;
Pod::Usage::pod2usage(
-verbose => 99,
-sections => 'VERSION|COPYRIGHT',
-exit => 0,
);
}
__END__
=head1 NAME
munin-httpd - Runs a http server for displaying Munin graphs.
=head1 USAGE
munin-httpd [options]
=head1 REQUIRED ARGUMENTS
None.
=head1 EXIT STATUS
This daemon should normally not exit, non-zero on failure.
=head1 DESCRIPTION
munin-httpd is a simple http server to display Munin graphs.
It supports three click zooming.
=head1 OPTIONS
=over 5
=item B<< --listen <hostname:port> >>
Sets the hostname and port to listen on. [*:4948]
=item B<--help >
View this help message.
=item B<--version >
Show version information.
=item B<--debug >
Set debug mode. Server starts single threaded in the foreground and
sets log level to debug.
=item B<--stdout >
Send logs to stdout. Suitable for systemd use in some versions of Linux.
=item B<--loglevel >
Set which level of logs you want. One of debug, info, notice, warning
or error. Default is warning.
=back
=head1 VERSION
This is munin-httpd (munin) v@@VERSION@@
=head1 AUTHOR
Steve Schnepp
=head1 BUGS AND LIMITATIONS
None known. If you found one, please report under L<https://github.com/munin-monitoring/munin/issues>.
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2014-2015 Steve Schnepp
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; version 2 dated June,
1991.
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