Perlistan has asked for the wisdom of the Perl Monks concerning the following question:
Desired outputDatabase Member 0 -- Active -- Up 26 days 13:26:26 -- Date 2020-07-10- +10.11.32.332869 Database Member Memory Controller Statistics Controller Automatic: N Controller License Limit: N Controller Limit Enforced: Y Memory Limit: 26597404 KB Current usage: 25768448 KB HWM usage: 26003008 KB Cached memory: 3352576 KB Individual Memory Consumers: Name Mem Used (KB) HWM Used (KB) Cached (KB) ======================================================== APPL-PB1 196352 601792 38272 DBMS-db2pb1 210752 210752 4736 FMP_RESOURCES 22528 22528 20736 PRIVATE 1377280 1424640 843968 DB-PB1 23961536 24333568 2444864
Here is my ugly code.>perl -nl db2mem.pl db2mem.PB1 Memory Limit : 25,974 MB Current usage : 25,164 MB HWM usage : 25,393 MB Name Mem Used (MB) HWM Used (MB) Cached (MB) ======================================================== APPL-PB1 191 587 37 FMP_RESOURCES 22 22 20 PRIVATE 1,345 1,391 824 DB-PB1 23,399 23,763 2,387
#use strict; #use warnings; #-- Format memory in MB from db2pd -dbptnmem #-- Run as db2pd -dbptnmem | perl -nl db2mem.pl #-- or perl -nl db2mem.pl db2mem.PB1 sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } print if ($. == 1); if (/Name|===/) { s/KB/MB/g; print; } if (/Memory Limit|Current usage:|HWM usage:| Cached memory:/ && length +($_) > 0 ){ ($name, $value) =split /:/; $value =~ s/KB//g; printf "%-14s: %10s MB\n", $name, commify(int $value/1024); if ($name eq "HWM usage") { printf "\n"; } } if (/APPL-|DB-|FMP|PRI/) { ($name, $used, $hwm, $free) =split /\s+/; printf "%-15s %10s %10s %10s\n", $name, commify(int $used/1024), c +ommify( int $hwm/1024), commify( int $free/1024); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memeory usage output KB to MB conversion
by Fletch (Bishop) on Jun 06, 2021 at 01:13 UTC | |
|
Re: Memeory usage output KB to MB conversion
by tomasz (Acolyte) on Jun 05, 2021 at 19:53 UTC | |
|
Re: Memeory usage output KB to MB conversion
by Marshall (Canon) on Jun 06, 2021 at 00:12 UTC | |
|
Re: Memeory usage output KB to MB conversion
by Perlistan (Initiate) on Jun 10, 2021 at 13:33 UTC |