#!/usr/bin/env perl

use strict;
use warnings;
use Inca::Reporter::SimpleUnit;

my $reporter = new Inca::Reporter::SimpleUnit(
  name => 'cluster.ps.count.unit',
  description => 'Checks process count under max',
  version => 4,
  unit_name => 'psCount'
);

$reporter->addArg( "max", "maximum number of ps", "15" );
$reporter->addArg( "psArgs", "arguments to pass to ps", "-x -o pid,command" );
$reporter->processArgv(@ARGV);
my $psMax = $reporter->argValue( "max" );
my $psArgs = $reporter->argValue( "psArgs" );

my $psCmd = "ps $psArgs";
my @output = $reporter->loggedCommand( $psCmd );
$reporter->log("debug", join("\n",@output));
$reporter->failPrintAndExit("$psCmd failed: @output $!") if $?;
my $psCount = scalar(@output);
if ($psCount > $psMax) {
  $reporter->log("debug", "Number of ps is $psCount");
  $reporter->failPrintAndExit("Number of ps exceeds $psMax");
}
$reporter->unitSuccess();
$reporter->print();


Click here to see help information for the cluster.ps.count.unit reporter.