forked from lix-project/hydra
Merge pull request #895 from Mic92/fix-hydra-send-stats
hydra-send-stats: fix imports
This commit is contained in:
commit
e14175fc36
|
@ -2,15 +2,17 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use utf8;
|
use utf8;
|
||||||
|
use Hydra::Helper::Nix;
|
||||||
use Net::Statsd;
|
use Net::Statsd;
|
||||||
use File::Slurp;
|
use File::Slurp;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
use Getopt::Long qw(:config gnu_getopt);
|
||||||
|
|
||||||
STDERR->autoflush(1);
|
STDERR->autoflush(1);
|
||||||
binmode STDERR, ":encoding(utf8)";
|
binmode STDERR, ":encoding(utf8)";
|
||||||
|
|
||||||
my $config = getHydraConfig();
|
my $config = getHydraConfig();
|
||||||
my $statsdConfig = Hydra::Helper::Nix::getStatsdConfig($config);
|
my $statsdConfig = getStatsdConfig($config);
|
||||||
$Net::Statsd::HOST = $statsdConfig->{'host'};
|
$Net::Statsd::HOST = $statsdConfig->{'host'};
|
||||||
$Net::Statsd::PORT = $statsdConfig->{'port'};
|
$Net::Statsd::PORT = $statsdConfig->{'port'};
|
||||||
|
|
||||||
|
@ -64,6 +66,26 @@ sub sendQueueRunnerStats {
|
||||||
gauge("hydra.queue.machines.in_use", scalar(grep { $_->{currentJobs} > 0 } (values %{$json->{machines}})));
|
gauge("hydra.queue.machines.in_use", scalar(grep { $_->{currentJobs} > 0 } (values %{$json->{machines}})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub showHelp {
|
||||||
|
print <<EOF;
|
||||||
|
Usage: $0 [--once]
|
||||||
|
|
||||||
|
Send stats to statsd. The --once flag can be used to send one round
|
||||||
|
of stats and then exit.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
\$ $0 --once
|
||||||
|
EOF
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $once = 0;
|
||||||
|
|
||||||
|
GetOptions("once" => \$once,
|
||||||
|
"help" => sub { showHelp() }
|
||||||
|
) or exit 1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
eval {
|
eval {
|
||||||
sendQueueRunnerStats();
|
sendQueueRunnerStats();
|
||||||
|
@ -77,5 +99,8 @@ while (1) {
|
||||||
gauge("hydra.mem.dirty", $dirty);
|
gauge("hydra.mem.dirty", $dirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($once) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
sleep(30);
|
sleep(30);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,10 @@ use File::Basename;
|
||||||
use Cwd qw(abs_path getcwd);
|
use Cwd qw(abs_path getcwd);
|
||||||
|
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild sendNotifications updateRepository);
|
our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset
|
||||||
|
nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput
|
||||||
|
evalSucceeds runBuild sendNotifications updateRepository
|
||||||
|
captureStdoutStderr);
|
||||||
|
|
||||||
# Set up the environment for running tests.
|
# Set up the environment for running tests.
|
||||||
#
|
#
|
||||||
|
|
20
t/scripts/hydra-send-stats.t
Normal file
20
t/scripts/hydra-send-stats.t
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use feature 'unicode_strings';
|
||||||
|
use strict;
|
||||||
|
use Setup;
|
||||||
|
|
||||||
|
my %ctx = test_init();
|
||||||
|
|
||||||
|
require Hydra::Schema;
|
||||||
|
require Hydra::Model::DB;
|
||||||
|
|
||||||
|
use Test2::V0;
|
||||||
|
|
||||||
|
my $db = Hydra::Model::DB->new;
|
||||||
|
hydra_setup($db);
|
||||||
|
|
||||||
|
my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-send-stats", "--once"));
|
||||||
|
is($stdout, "", "hydra-send-stats stdout should be empty");
|
||||||
|
is($stderr, "", "hydra-send-stats stderr should be empty");
|
||||||
|
is($res, 0, "hydra-send-stats --once should exit zero");
|
||||||
|
|
||||||
|
done_testing;
|
Loading…
Reference in a new issue