statsd: add a chance to set hostname and port in hydra.conf
Co-authored-by: Graham Christensen <graham@grahamc.com>
This commit is contained in:
committed by
Graham Christensen
parent
1f4183e05f
commit
a551fba346
@ -15,7 +15,7 @@ use IPC::Run;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
getHydraHome getHydraConfig getBaseUrl
|
||||
getSCMCacheDir
|
||||
getSCMCacheDir getStatsdConfig
|
||||
registerRoot getGCRootsDir gcRootFor
|
||||
jobsetOverview jobsetOverview_
|
||||
getDrvLogPath findLog
|
||||
@ -55,6 +55,23 @@ sub getHydraConfig {
|
||||
}
|
||||
|
||||
|
||||
# Return hash of statsd configuration of the following shape:
|
||||
# (
|
||||
# host => string,
|
||||
# port => digit
|
||||
# )
|
||||
sub getStatsdConfig {
|
||||
my ($config) = @_;
|
||||
my $cfg = $config->{statsd};
|
||||
my %statsd = defined $cfg ? ref $cfg eq "HASH" ? %$cfg : ($cfg) : ();
|
||||
|
||||
return {
|
||||
"host" => %statsd{'host'} // 'localhost',
|
||||
"port" => %statsd{'port'} // 8125,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub getBaseUrl {
|
||||
my ($config) = @_;
|
||||
return $config->{'base_uri'} // "http://" . hostname_long . ":3000";
|
||||
|
@ -33,6 +33,10 @@ my $plugins = [Hydra::Plugin->instantiate(db => $db, config => $config)];
|
||||
|
||||
my $dryRun = defined $ENV{'HYDRA_DRY_RUN'};
|
||||
|
||||
my $statsdConfig = Hydra::Helper::Nix::getStatsdConfig($config);
|
||||
$Net::Statsd::HOST = $statsdConfig->{'host'};
|
||||
$Net::Statsd::PORT = $statsdConfig->{'port'};
|
||||
|
||||
alarm 3600; # FIXME: make configurable
|
||||
|
||||
|
||||
|
@ -9,6 +9,11 @@ use JSON;
|
||||
STDERR->autoflush(1);
|
||||
binmode STDERR, ":encoding(utf8)";
|
||||
|
||||
my $config = getHydraConfig();
|
||||
my $statsdConfig = Hydra::Helper::Nix::getStatsdConfig($config);
|
||||
$Net::Statsd::HOST = $statsdConfig->{'host'};
|
||||
$Net::Statsd::PORT = $statsdConfig->{'port'};
|
||||
|
||||
sub gauge {
|
||||
my ($name, $val) = @_;
|
||||
die unless defined $val;
|
||||
|
Reference in New Issue
Block a user