hydra-notify: make the prometheus endpoint configurable, default-off

This commit is contained in:
Your Name
2021-08-18 15:09:54 -04:00
parent 5d0ad5f649
commit 6d7ee27d25
5 changed files with 152 additions and 14 deletions

View File

@ -70,6 +70,29 @@ sub getStatsdConfig {
}
}
sub getHydraNotifyPrometheusConfig {
my ($config) = @_;
my $cfg = $config->{hydra_notify};
if (!defined($cfg) || ref $cfg ne "HASH") {
return undef;
}
my $cfg = $cfg->{prometheus};
if (!defined($cfg) || ref $cfg ne "HASH") {
return undef;
}
if (defined($cfg->{"listen_address"}) && defined($cfg->{"port"})) {
return {
"listen_address" => $cfg->{'listen_address'},
"port" => $cfg->{'port'},
};
}
return undef;
}
sub getBaseUrl {
my ($config) = @_;

View File

@ -14,30 +14,34 @@ use Parallel::ForkManager;
use Prometheus::Tiny::Shared;
use Time::HiRes qw( gettimeofday tv_interval );
my $prom = Prometheus::Tiny::Shared->new;
my $fork_manager = Parallel::ForkManager->new(1 );
$fork_manager->start_child("metrics_exporter", sub {
my $server = HTTP::Server::PSGI->new(
host => "127.0.0.1",
port => 9091,
timeout => 5,
);
$server->run($prom->psgi);
});
STDERR->autoflush(1);
STDOUT->autoflush(1);
binmode STDERR, ":encoding(utf8)";
my $config = getHydraConfig();
my $prom = Prometheus::Tiny::Shared->new;
my $promCfg = Hydra::Helper::Nix::getHydraNotifyPrometheusConfig($config);
if (defined($promCfg)) {
my $fork_manager = Parallel::ForkManager->new(1);
$fork_manager->start_child("metrics_exporter", sub {
my $server = HTTP::Server::PSGI->new(
host => $promCfg->{"listen_address"},
port => $promCfg->{"port"},
timeout => 1,
);
$server->run($prom->psgi);
});
}
my $queued_only;
GetOptions(
"queued-only" => \$queued_only
) or exit 1;
my $config = getHydraConfig();
my $db = Hydra::Model::DB->new();