#!/usr/bin/perl #============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE #------------------------------------------------------------------------------ # Author: jhalbig@perforce.com # Date: November 10, 2020 # After several years of successful implementation my plan is to render this # ready for prime-time usage by cleaning up and fully documenting the settings # with an internal KB that will one day be presentable to a wider audience; for # now this will be useful for support engineers for cases where the server loads # don't appear to be utilizing all Linux OS hardware, networking resources in # particular. # # Usage: ./parse_sysctl.pl {-a} {/path to/}sysctl.out # # -a: # # Check rarely tweaked kernel settings. # # {/path to/}sysctl.out: # # The 'sysctl -a' output file to parse. # # Or change this sysctl_file value to a file containing "sysctl -a" output: my $sysctl_file = "sysctl.out"; # List of recommended kernel values: my $rec_k_vals = < $1, 'old_val' => "none", 'new_val' => $2}; $a++; } # Parse the sysctl output file to determine if there are any values that need to # be changed or added: open (SYSCTL, "< " . $sysctl_file) or die $usage_txt . "ERROR: Can't read file " . $sysctl_file .":\n" . $!; while () { chomp; foreach my $val (keys %k_vals) { if (/^.*?$k_vals{$val}{'name'}\s+?=\s+?(.*)$/) { $k_vals{$val}{'old_val'} = $1; } } } close SYSCTL; ## Create the pretty table with comparison values print $txt_1; foreach my $val (sort keys %k_vals) { $k_vals{$val}{'old_val'} =~ s/\t/\x20/g; # normalize tabs to spaces unless ($k_vals{$val}{'old_val'} =~ $k_vals{$val}{'new_val'}) { if ($k_vals{$val}{'old_val'} =~ "none") { next; } if ( $k_vals{$val}{old_val} == 0 || $k_vals{$val}{old_val } ) { print "\t" . $k_vals{$val}{'name'} . "\t\t" . $k_vals{$val}{new_val} . "\t" . "(" . $k_vals{$val}{old_val} . ")\n"; } } } ## Create the ready to paste OS commands to change those settings: print $txt_2; foreach my $val (sort keys %k_vals) { unless ($k_vals{$val}{old_val} =~ $k_vals{$val}{new_val}) { if ($k_vals{$val}{'old_val'} =~ "none") { next; } unless ($k_vals{$val}{old_val}) { next; } if ($k_vals{$val}{new_val} =~ m/\s/g) { $q = "\""; } print "\t" . $sysctl_cmd . " " . $k_vals{$val}{'name'} . "=" . $q . $k_vals{$val}{new_val} . $q . "\n"; $q = ""; } } print $txt_3; print $txt_4; ## Create the ready to paste Perforce server commands: foreach my $val (keys %p4d_vals) { print "\t" . $p4_cmd . " " . $val . "=" . $p4d_vals{$val} . "\n"; } ## Print "p4 admin restart" command: print $txt_5; ## Closing text. print $txt_6; # WARNING: While this detects differences in values, the original values might # already have been tweaked! Remember to remove those lines that are already # at good values, taking care to remove the associated "sysctl -w" entry.