loadmon and parse loadmon gain thread counts, fixes for output and reading input

Signed-off-by: Jed Reynolds <jed@bitratchet.com>
This commit is contained in:
Jed Reynolds
2022-05-24 14:34:38 -07:00
committed by shivam
parent e71c2b2c30
commit 290b83e592
2 changed files with 20 additions and 7 deletions

View File

@@ -39,11 +39,13 @@ our @prog_names = (
"dnsmasq",
"hostapd",
"httpd",
"iw",
"java",
"l4helper",
# "logchopper",
"nginx",
"perl",
"php-fpm",
"pipe_helper",
"vsftpd",
"wget",
@@ -62,6 +64,7 @@ sub new {
ra_pid_list => [],
total_mem => 0,
total_fh => 0,
total_thr => 0,
};
bless $self, $class;
return $self;
@@ -71,6 +74,7 @@ sub monitor {
my $self = shift;
$self->{total_mem} = 0;
$self->{total_fh} = 0;
$self->{total_threads} = 0;
my $cmd = qq(pgrep -f $self->{basename});
# print "CMD[$cmd]\n";
@@ -102,6 +106,10 @@ sub monitor {
if (@lines > 0 ) {
$self->{total_fh} += int($lines[0]);
}
$cmd = "ls /proc/$pid/task/ | wc -l";
my $threads = `$cmd`;
chomp $threads;
$self->{total_threads} += int($threads);
}
#die("testing");
@@ -122,7 +130,8 @@ sub report {
print $fh qq(${LC}"basename":"$self->{basename}",);
print $fh qq("num_pids":$num_pids,);
print $fh qq("total_mem_KB":$self->{total_mem},);
print $fh qq("total_fh":$self->{total_fh}${RC});
print $fh qq("total_fh":$self->{total_fh},);
print $fh qq("total_threads":$self->{total_threads}${RC});
}
1;
## - - - End loadmon - - - ##
@@ -138,6 +147,7 @@ sub print_totals {
my $tt_num_pids = 0;
my $tt_mem_kb = 0;
my $tt_fh = 0;
my $tt_threads = 0;
for my $name (@main::prog_names) {
my $monitor = $main::monitor_map{$name};
#print Data::Dumper->Dump(["mm_name", $monitor ]);
@@ -148,8 +158,9 @@ sub print_totals {
$tt_mem_kb += $main::monitor_map{$name}->{total_mem};
}
$tt_fh += $main::monitor_map{$name}->{total_fh};
$tt_threads += $main::monitor_map{$name}->{total_threads};
}
print $fh qq(${LC}"tt_num_pids":$tt_num_pids, "tt_mem_kb":$tt_mem_kb, "tt_fh":$tt_fh${RC});
print $fh qq(${LC}"tt_num_pids":$tt_num_pids, "tt_mem_kb":$tt_mem_kb, "tt_fh":$tt_fh, "tt_threads":$tt_threads${RC});
}
## - - -

View File

@@ -21,12 +21,12 @@ sub mb {
return "${kb}KB";
}
my $mb = $kb / 1024;
return sprintf("%0.1fMB", $mb);
return sprintf("%0.1f MB", $mb);
}
foreach my $line (<>) {
while (my $line=<STDIN>) {
chomp $line;
#print "line[$line]\n";
print "line[$line]\n";
my $lc_pos = index($line, '[{');
# print "lc at $lc_pos\n";
next if ($lc_pos < 0);
@@ -37,14 +37,16 @@ foreach my $line (<>) {
for my $rh_item ( @$ra_loadmon) {
next if ($rh_item == 0);
if (defined($rh_item->{basename})) {
printf("%-15s: %3d pids use %9s memory\n",
printf("%-15s: %3d pids (%4d thr) use %9s memory\n",
$rh_item->{basename},
$rh_item->{num_pids},
$rh_item->{total_threads},
mb($rh_item->{total_mem_KB}));
}
else {
printf("TT pids: %5d use %9s ram and %-7d FH\n\n",
printf("TOTALS : %11d pids (%4d thr) use %9s ram and %7d FH\n\n",
$rh_item->{tt_num_pids},
$rh_item->{tt_threads},
mb($rh_item->{tt_mem_kb}),
$rh_item->{tt_fh});
}