����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.170 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/self/root/proc/1630575/root/usr/lib64/nagios/plugins/base/ |
Upload File : |
#!/usr/bin/env perl
use extreme;
use JSON::XS;
use IPC::Run qw(run);
use Carp;
use Getopt::Long;
use experimental qw(smartmatch);
my ( @perfdata, $opt_c );
# Set options
GetOptions(
"help|h" => \&help,
"c=s" => \$opt_c
);
my %units = (
'KiB' => '0.0009765625', 'MiB' => '1',
'GiB' => '1024', 'TiB' => '1048576',
'kB' => '0.001', 'MB' => '1', 'GB' => '1000'
);
my @containers = split( ',', $opt_c ) if $opt_c;
my $data = run_cmd( '/bin/docker', 'stats', '--no-stream', '--format', '{{ json . }}' );
exit if !$data;
my @data = split( "\n", $data);
chomp @data;
for (@data) {
my $container_info = decode_json($_);
my $name = $container_info->{Name};
if (@containers) {
next unless $name ~~ @containers;
}
my $cpu = ($1) if $container_info->{CPUPerc} =~ /([\d\.]+)%/;
my ( $mem, $memunit ) = ( $1, $2 ) if $container_info->{MemUsage} =~ /^([\d\.]+)([a-zA-Z]+)/;
my ( $io, $iounit ) = ( $1, $2 ) if $container_info->{NetIO} =~ /^([\d\.]+)([a-zA-Z]+)/;
$mem = $mem * $units{$memunit};
$io = $io * $units{$iounit};
push @perfdata, ( "${name}_cpu=$cpu", "${name}_mem=$mem", "${name}_io=$io" );
}
say 'OK | ' . join( ';;; ', @perfdata );
# subs
sub run_cmd {
my @cmd = @_;
my ( $out, $err );
run \@cmd, \undef, \$out, \$err;
croak $err if $? != 0;
return $out;
}
sub help {
print "Usage : $0 -c CONTAINER_UUID \n\n";
print "Options :\n";
print " -c\n\tContainers UUIDs to be checked, separated by comma\n";
print " -h, --help\n\tPrint this help screen\n";
print "\nExample : $0 -c 82249f22-4b0a-4206-924d-080343ff70b6,09eadad4-5eaa-4acc-a5f3-f5484f899c82\n";
exit 3;
}