Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more work on the poudriere extend #513

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 85 additions & 13 deletions snmp/poudriere
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env perl
#!/usr/local/bin/perl

=head1 NAME

poudriere - LibreNMS JSON style SNMP extend for monitoring Poudriere

=head1 VERSION

0.0.1
0.1.0

=head1 SYNOPSIS

Expand Down Expand Up @@ -45,6 +45,12 @@ meaning it will be written out to the two locations.
The later is for use with returning data for SNMP. Will be compressed
if possible.

=head1 REQUIREMENTS

p5-File-Slurp
p5-MIME-Base64
p5-JSON

=cut

use strict;
Expand All @@ -55,6 +61,7 @@ use MIME::Base64;
use IO::Compress::Gzip qw(gzip $GzipError);
use Pod::Usage;
use JSON;
use Cwd 'abs_path';

sub time_to_seconds {
my $time = $_[0];
Expand All @@ -66,21 +73,31 @@ sub time_to_seconds {
if ( $time =~ /^0\:[0-9]+\.[0-9]+$/ ) {
$time =~ s/^0\://;
return $time;
} elsif ( $time =~ /^[0-9]+\:[0-9]+\.[0-9]+$/ ) {
} elsif ( $time =~ /^[0-9]+\:[0-9]+\.[0-9]+$/
|| $time =~ /^[0-9]+\:[0-9]+$/ )
{
my $minutes = $time;
$minutes =~ s/\:.*//;
$time =~ s/.*\://;
$time = ( $minutes * 60 ) + $time;
return $time;
} elsif ( $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+\.[0-9]+$/ ) {
} elsif ( $time =~ /^[0-9]+\:[0-9]+\:[0-9]+\.[0-9]+$/
|| $time =~ /^[0-9]+\:[0-9]+\:[0-9]+$/ )
{
my ( $hours, $minutes, $seconds ) = split( /:/, $time );
$time = ( $hours * 3600 ) + ( $minutes * 60 ) + $seconds;
return $time;
} elsif ( $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+\.[0-9]+$/
|| $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+$/ )
{
my $days = $time;
$days =~ s/D\:.*$//;
my $minutes = $time;
$minutes =~ s/^.*D\://;
$minutes =~ s/\:.*//;
$time = ( $days * 86400 ) + ( $minutes * 60 ) + $time;
return $time;
}
} ## end elsif ( $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+\.[0-9]+$/...)

# return 0 for anything unknown
return 0;
Expand Down Expand Up @@ -162,7 +179,8 @@ my $data = {
'check-sanity' => 0,
'pkg-depends' => 0,
'fetch-depends' => 0,
'fetch checksum' => 0,
'fetch' => 0,
'checksum' => 0,
'extract-depends' => 0,
'extract' => 0,
'patch-depends' => 0,
Expand All @@ -174,6 +192,12 @@ my $data = {
'run-depends' => 0,
'stage' => 0,
'package' => 0,
'package_size_all' => 0,
'package_size_latest' => 0,
'package_size_building' => 0,
'log_size_latest' => 0,
'log_size_done' => 0,
'log_size_per_package' => 0,
},
jailANDportsANDset => {}
};
Expand All @@ -195,10 +219,10 @@ my @poudriere_stats = ( 'QUEUE', 'BUILT', 'FAIL', 'SKIP', 'IGNORE', 'FETCH', 'RE
###
###

my $status_raw = `poudriere -N status -f 2> /dev/null`;
my $status_raw = `poudriere -N status -f -l 2> /dev/null`;
if ( $? == 0 ) {
$data->{status} = $status_raw;
$data->{build_info} = `poudriere -N status -f -b 2>&1`;
$data->{build_info} = `poudriere -N status -f -b -l 2>&1`;

my @status_split = split( /\n/, $status_raw );
my $status_split_int = 1;
Expand Down Expand Up @@ -235,7 +259,8 @@ if ( $? == 0 ) {
'check-sanity' => 0,
'pkg-depends' => 0,
'fetch-depends' => 0,
'fetch checksum' => 0,
'fetch' => 0,
'checksum' => 0,
'extract-depends' => 0,
'extract' => 0,
'patch-depends' => 0,
Expand All @@ -247,6 +272,12 @@ if ( $? == 0 ) {
'run-depends' => 0,
'stage' => 0,
'package' => 0,
'package_size_all' => 0,
'package_size_latest' => 0,
'package_size_building' => 0,
'log_size_latest' => 0,
'log_size_done' => 0,
'log_size_per_package' => 0,
};
(
$found->{SET}, $found->{PORTS}, $found->{JAIL}, $found->{BUILD}, $found->{STATUS},
Expand All @@ -265,11 +296,52 @@ if ( $? == 0 ) {
$jailANDportsANDset = $found->{JAIL} . '-' . $found->{PORTS} . '-' . $found->{SET};
}

$found->{packages_dir_all} = $found->{LOGS} . '/../../../../packages/' . $jailANDportsANDset . '/All';
$found->{packages_dir_latest} = $found->{LOGS} . '/../../../../packages/' . $jailANDportsANDset . '/Latest';
$found->{packages_dir_building}
= $found->{LOGS} . '/../../../../packages/' . $jailANDportsANDset . '/.building';
$found->{logs_dir_latest} = $found->{LOGS} . '/logs';
$found->{logs_dir_done} = $found->{LOGS} . '/../latest-done/logs';
$found->{logs_dir_per_package} = $found->{LOGS} . '/../latest-per-pkg/';
my %dir_size_stats = (
'logs_dir_per_package' => 'log_size_per_package',
'logs_dir_done' => 'log_size_done',
'logs_dir_latest' => 'log_size_latest',
'packages_dir_building' => 'package_size_building',
'packages_dir_latest' => 'package_size_latest',
'packages_dir_all' => 'package_size_all',
);

foreach my $item ( keys(%dir_size_stats) ) {
eval {
if ( defined( $found->{$item} ) ) {
$found->{$item} = abs_path( $found->{$item} );
if ( defined( $found->{$item} ) ) {
if ( -d $found->{$item} ) {
my @files = read_dir( $found->{$item} );
foreach my $to_stat (@files) {
if ( -f $found->{$item} . '/' . $to_stat ) {
my (
$dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
$size, $atime, $mtime, $ctime, $blksize, $blocks
) = stat( $found->{$item} . '/' . $to_stat );
$found->{ $dir_size_stats{$item} } += $size;
}
}
$data->{stats}{ $dir_size_stats{$item} } = $found->{ $dir_size_stats{$item} };
} ## end if ( -d $found->{$item} )
} ## end if ( defined( $found->{$item} ) )
} ## end if ( defined( $found->{$item} ) )
};
} ## end foreach my $item ( keys(%dir_size_stats) )

foreach my $item (@poudriere_stats) {
if ( $item eq 'TIME' ) {
$found->{$item} = time_to_seconds( $found->{$item} );
}
$data->{stats}{$item} += $found->{$item};
if ( $item =~ /^\d+$/ ) {
$data->{stats}{$item} += $found->{$item};
}
}

##
Expand Down Expand Up @@ -367,13 +439,13 @@ if ( $? == 0 ) {
} elsif ( $line =~ /[\ \t]package[\ \t]/ ) {
$type = 'package';
}
if (defined($type)) {
if ( defined($type) ) {
$data->{stats}{$type}++;
if (defined($data->{jailANDportsANDset}{$current_section})) {
if ( defined( $data->{jailANDportsANDset}{$current_section} ) ) {
$data->{jailANDportsANDset}{$current_section}{$type}++;
}
}
} ## end elsif ( $line =~ /^\[[0-9]+\].*\/.*\|.*-.*\:/)
} ## end elsif ( $line =~ /^\[.*\].*\:.*\|.*\:/ )
} ## end foreach my $line (@build_info_split)
} else {
$to_return->{error} = 1;
Expand Down
Loading