Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static generation #1526

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
24 changes: 20 additions & 4 deletions .github/workflows/build-n-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,28 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Fetch the deps
run: sudo dev_scripts/deps

- run: perl -V

- name: Devel-Cover-Report-Coveralls install deps
run: sudo apt-get install -y dh-make-perl libdevel-cover-perl libhttp-tiny-perl libio-socket-ssl-perl libjson-pp-perl libyaml-perl libmodule-build-tiny-perl
- name: Devel-Cover-Report-Coveralls fetch
run: cd /tmp && wget https://cpan.metacpan.org/authors/id/M/MI/MIKIHOSHI/Devel-Cover-Report-Coveralls-0.32.tar.gz
- name: Devel-Cover-Report-Coveralls uncompress
run: cd /tmp && tar zxvf Devel-Cover-Report-Coveralls-0.32.tar.gz
- name: Devel-Cover-Report-Coveralls create the package
run: cd /tmp && DEB_BUILD_OPTIONS=nocheck dh-make-perl make --build Devel-Cover-Report-Coveralls-0.32
- name: Devel-Cover-Report-Coveralls install the package
run: cd /tmp && sudo dpkg -i libdevel-cover-report-coveralls-perl*.deb
- name: Devel-Cover-Report-Coveralls install any needed deps
run: sudo apt-get install -yf

- name: Setup the mock hostname
run: echo "127.0.0.1 testing.acme.com" | sudo tee -a /etc/hosts

- name: Testing
run: make test

- name: Compute coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cover -test -report coveralls
2 changes: 1 addition & 1 deletion contrib/munin-node-debug
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ sub service
} elsif ($line =~ m/^fetch (\w+)/) {
my $plugin_number = get_plugin_number($1);
for (my $i = 0; $i < $fields_per_plugin; $i ++) {
my $value = sin( (time / 3600) * $plugin_number + $i) * (4 ** $plugin_number);
my $value = sin( (time / 3600) * $plugin_number + $i) * (4 ** ($plugin_number%5));

$value = int($value * 1024) if ($plugin_number + $i) % 3;
print $client get_ds($plugin_number, $i) . ".value $value\n";
Expand Down
2 changes: 2 additions & 0 deletions lib/Munin/Common/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ my %legal = map { $_ => 1 } qw(
contacts
create_args
critical
db_journal_mode
db_synchronous_mode
dbdir
dburl
dbdriver
Expand Down
2 changes: 1 addition & 1 deletion lib/Munin/Master/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ sub get_param
# Ok, now SQL is needed to go further
use DBI;
my $datafilename = $ENV{MUNIN_DBURL} || "$Munin::Common::Defaults::MUNIN_DBDIR/datafile.sqlite";
my $dbh = Munin::Master::Update::get_dbh();
my $dbh = Munin::Master::Update::get_dbh(1);
my ($value) = $dbh->selectrow_array("SELECT value FROM param WHERE name = ?", undef, ($param));
return $value;
}
Expand Down
21 changes: 16 additions & 5 deletions lib/Munin/Master/Update.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ sub get_dbh {
my %db_args;
$db_args{ReadOnly} = 1 if $is_read_only;
# $db_args{AutoCommit} = 0 if $is_read_only;
$db_args{AutoCommit} = 0;
$db_args{RaiseError} = 1;

use Carp;
Expand All @@ -88,6 +87,15 @@ sub get_dbh {

DEBUG 'get_dbh: $dbh->{Driver}->{Name} = ' . $dbh->{Driver}->{Name};

# Sets some session vars
my $db_journal_mode = $ENV{MUNIN_DB_JOURNAL_MODE} || $config->{db_journal_mode} || "TRUNCATE";
$dbh->do("PRAGMA journal_mode=$db_journal_mode;") if $db_driver eq "SQLite";

my $db_synchronous_mode = $ENV{MUNIN_DB_SYNCHRONOUS_MODE} || $config->{db_synchronous_mode} || "OFF";
$dbh->do("PRAGMA main.synchronous=$db_synchronous_mode;") if $db_driver eq "SQLite";

$dbh->{AutoCommit} = 1;

# Plainly returns it, but do *not* put it in $self, as it will let Perl
# do its GC properly and closing it when out of scope.
return $dbh;
Expand Down Expand Up @@ -200,7 +208,12 @@ sub _run_workers {
$res = $worker->do_work();
};

$worker->{dbh}->disconnect();
# Disconnect via removing it from scope
#
# We don't want to call disconnect forcefully, in order to
# fully leverage the reference counting and the automatic call
# to ->DESTROY
delete($worker->{dbh});

my $worker_id = $worker->{ID};
if (! $res || $@) {
Expand Down Expand Up @@ -243,12 +256,10 @@ sub _handle_worker_result {
sub _db_init {
my ($self, $dbh) = @_;

my $db_serial_type = "INTEGER";
my $db_driver = $ENV{MUNIN_DBDRIVER} || "$config->{dbdriver}";
my $db_serial_type = "INTEGER";
$db_serial_type = "SERIAL" if $db_driver eq "Pg";

# Sets some session vars
$dbh->do("PRAGMA journal_mode=DELETE;") if $db_driver eq "SQLite";
$dbh->do("SET LOCAL client_min_messages = error") if $db_driver eq "Pg";

# Initialize DB Schema
Expand Down
10 changes: 9 additions & 1 deletion script/munin-graph
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ my @paths;

use Parallel::ForkManager;
my $pm = Parallel::ForkManager->new($jobs);
for my $path (@paths) {
$pm->set_waitpid_blocking_sleep(0); # true blocking calls enabled

use List::MoreUtils qw(slideatatime);

my $paths_it = slideatatime(50, 50, @paths);
while (my @paths_batch = $paths_it->()) {

my $worker_id = $pm->start();
next if $worker_id;

for my $path (@paths_batch) {
# Mock CGI interface, in order to reuse most of munin-httpd internals
my $cgi = CGI->new({
path_info => "/$path",
Expand All @@ -67,6 +74,7 @@ for my $path (@paths) {
use Munin::Master::Graph;
Munin::Master::Graph::handle_request($cgi);
};
}

$pm->finish();
}
Expand Down
66 changes: 45 additions & 21 deletions script/munin-html
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ use strict;
use warnings;

use Getopt::Long;
use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove);

use Munin::Master::Config;

my $jobs = 0;
my $destination = "/tmp";
my $htmldir;

print_usage_and_exit()
unless GetOptions(
"jobs|j=i" => \$jobs,
"destination|d=s" => \$destination,
"version" => \&print_version_and_exit,
"help" => \&print_usage_and_exit,
);

# Get the list of HTML pages to create
unless GetOptions(
"jobs|j=i" => \$jobs,
"htmldir|d=s" => \$htmldir,
"version" => \&print_version_and_exit,
"help" => \&print_usage_and_exit,
);

my $staticdir;
my @paths;
{
use Munin::Master::Update;
my $dbh = Munin::Master::Update::get_dbh(1);

($staticdir) = $dbh->selectrow_array("SELECT value FROM param WHERE name = 'staticdir'");
($htmldir) = $dbh->selectrow_array("SELECT value FROM param WHERE name = 'htmldir'") || ("/tmp");

# Get the list of HTML pages to create
my $row_ref = $dbh->selectall_arrayref("SELECT path FROM url");

# Process results
Expand All @@ -31,20 +39,34 @@ my @paths;
push @paths, "/";
}

# Copy the static part
{
$staticdir = $1 if $staticdir =~ m/(.*)/;
$htmldir = $1 if $htmldir =~ m/(.*)/;
dircopy($staticdir, "$htmldir/static/");
}

use Parallel::ForkManager;
my $pm = Parallel::ForkManager->new($jobs);
for my $path (@paths) {
$pm->set_waitpid_blocking_sleep(0); # true blocking calls enabled

use List::MoreUtils qw(slideatatime);

my $paths_it = slideatatime(50, 50, @paths);

while (my @paths_batch = $paths_it->()) {
my $worker_id = $pm->start();
next if $worker_id;

for my $path (@paths) {
# Mock CGI interface, in order to reuse most of munin-httpd internals
my $cgi = CGI->new({
path_info => $path,
});

$destination = $1 if $destination =~ m/(.*)/;
my $filepath = "$destination/$path";
$filepath = "$destination/index.html" if $path eq "/";
htmldir = $1 if $htmldir =~ m/(.*)/;
my $filepath = "$htmldir/$path";
$filepath = "$htmldir/index.html" if $path eq "/";

# redirect STDOUT to the file
print "s: $filepath\n";
Expand All @@ -63,6 +85,8 @@ for my $path (@paths) {
Munin::Master::HTML::handle_request($cgi);
};

}

$pm->finish();
}

Expand All @@ -71,16 +95,16 @@ $pm->wait_all_children();


sub print_usage_and_exit {
require Pod::Usage;
Pod::Usage::pod2usage( -verbose => 1 );
require Pod::Usage;
Pod::Usage::pod2usage( -verbose => 1 );
}

sub print_version_and_exit {
require Pod::Usage;
Pod::Usage::pod2usage(
-verbose => 99,
-sections => 'VERSION|COPYRIGHT',
);
require Pod::Usage;
Pod::Usage::pod2usage(
-verbose => 99,
-sections => 'VERSION|COPYRIGHT',
);
}

package CGI;
Expand Down Expand Up @@ -149,7 +173,7 @@ It doesn't support zooming, but does support multi-process execution, via forkin
This is the number of workers jobs to launch.
Default is 0, meaning no fork is done.

=item B<< --destination <destination directory> >>
=item B<< --htmldir <destination directory> >>

Default is "/tmp".

Expand Down
7 changes: 6 additions & 1 deletion script/munin-httpd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use Munin::Master::Graph;
use Munin::Master::HTML;
use Munin::Common::Logger;

# Untaint $ENV{PATH}
$ENV{PATH} = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";

sub handle_request {
my $self = shift;
Expand Down Expand Up @@ -41,13 +43,16 @@ my $debug = 0;
my $stdout = 0;
my $loglevel = 'info';

my $max_servers = 10;

print_usage_and_exit()
unless GetOptions(
"listen=s" => \$listen,
"debug" => \$debug,
"stdout" => \$stdout,
"loglevel=s" => \$loglevel,
"version" => \&print_version_and_exit,
"max-servers=i" => \$max_servers,
"help" => \&print_usage_and_exit,
);

Expand Down Expand Up @@ -75,7 +80,7 @@ if ($stdout) {

Munin::Common::Logger::INFO("Starting preforking munin http server at $host:$port");

Munin::Master::Http->new( { host => $host, port => $port } )->run( prefork => 1, max_servers => 10 );
Munin::Master::Http->new( { host => $host, port => $port } )->run( prefork => ($max_servers > 0), max_servers => $max_servers );


sub print_usage_and_exit {
Expand Down
2 changes: 1 addition & 1 deletion web/static/css/materialdesignicons.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading