Skip to content

Commit

Permalink
Merge pull request #1629 from RexOps/solaris
Browse files Browse the repository at this point in the history
Fix memory detection warnings on Solaris
  • Loading branch information
ferki committed Nov 3, 2024
2 parents f186140 + 7a93955 commit d39f8a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Revision history for Rex
[BUG FIXES]
- Fix precedence warning after perl-5.41.4
- Fix missing argument warnings from Text::Wrap
- Fix memory detection warnings on Solaris

[DOCUMENTATION]

Expand Down
38 changes: 24 additions & 14 deletions lib/Rex/Hardware/Memory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use English qw(-no_match_vars);
use Rex::Hardware::Host;
use Rex::Commands::Run;
use Rex::Helper::Run;
Expand Down Expand Up @@ -54,25 +55,34 @@ sub get {
elsif ( $os eq "SunOS" ) {
my @data = i_run "echo ::memstat | mdb -k", fail_ok => 1;

my ($free_cache) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data;
my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data;
my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data;
if ( $CHILD_ERROR == 0 ) {
my ($free_cache) =
map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data;
my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data;
my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data;

my $free = $free_cache + $free_list;
my $free = $free_cache + $free_list;

#my ($total, $total_e) = grep { $_=$1 if /^Memory Size: (\d+) ([a-z])/i } i_run "prtconf";
my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data;
my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data;

&$convert( $free, "M" );
&$convert( $total, "M" );
my $used = $total - $free;

$data = {
used => $used,
total => $total,
free => $free,
};
&$convert( $free, "M" );
&$convert( $total, "M" );
my $used = $total - $free;

$data = {
used => $used,
total => $total,
free => $free,
};
}
else {
$data = {
used => 0,
total => 0,
free => 0,
};
}
}
elsif ( $os eq "OpenBSD" ) {
my $mem_str = i_run "top -d1 | grep Memory:", fail_ok => 1;
Expand Down

0 comments on commit d39f8a8

Please sign in to comment.