{"id":364,"date":"2009-06-06T03:37:08","date_gmt":"2009-06-05T21:37:08","guid":{"rendered":"http:\/\/techsatwork.com\/blog\/?p=364"},"modified":"2016-01-07T11:31:12","modified_gmt":"2016-01-07T05:31:12","slug":"track-db2s-memory-usage","status":"publish","type":"post","link":"https:\/\/techsatwork.com\/?p=364","title":{"rendered":"Track db2&#8217;s memory usage"},"content":{"rendered":"<p>Here is a script that displays the current memory usage and peak memory usage of an instance and its databases.\u00c2\u00a0 The script basically used db2pd -dbptnmem\u00c2\u00a0 and parses out data to make it easy to read and manage. You can upload the data into a spread sheet to do trending.\u00c2\u00a0 I intend to expand on this and get greater visibility and useability. if anybody has any suggestions or comments please let me know.<\/p>\n<p>Feel free to use the script at your own risk ! (sorry has to have that disclaimer) : <a href=\"https:\/\/techsatwork.com\/blog\/wp-content\/uploads\/2009\/06\/getmemoryusage.txt\" target=\"_blank\">getmemoryusage<\/a><\/p>\n<p>Here is the script if you want to view it before you download :<\/p>\n<pre><span style=\"color: #3366ff;\"><span style=\"font-size: xx-small;\">#!\/usr\/bin\/ksh\r\n#\r\n#------------------------------------------------------------------------------------\r\n# Program\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :\u00c2\u00a0 getmemoryusage.sh\r\n# Description\u00c2\u00a0 :\u00c2\u00a0 The script gets the following memory usage for the instance\r\n#\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :\u00c2\u00a0 Max Limit: The DB2 server's upper bound of memory that can be consumed.\r\n#\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :\u00c2\u00a0 Current usage: The amount of memory the server is currently consuming.\r\n#\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :\u00c2\u00a0 HWM : The peak memory usage that has been consumed since the activation of the database partition\r\n#\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :  Avail. in Current Cached memory: How much of the current usage is not currently being used.\r\n# Usage\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 : .\/getmemoryusage.sh\r\n#\r\n# Author\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :\u00c2\u00a0 Raju Pillai\r\n# Date\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 :\u00c2\u00a0 2009-06-05\r\n#-----------------------------------------------------------------------------------\r\n#\r\nmaximum=\"0\"\r\ncurrent=\"0\"\r\nhighest=\"0\"\r\ncached=\"0\"\r\nkeyword=\"\"\r\nOutputDir=\"\/home\/db2inst5\/report\"\r\nDatetime=\"`date +%Y-%m-%d-%H:%M:%S`\"\r\nif [ $(cat $OutputDir\/memory_usage.out|wc -l) -lt 1 ]\r\nthen\r\nprint \"==============================================\" &gt;&gt; $OutputDir\/memory_usage.out\r\nprint \"Total instance and database memory usage in KB\" &gt;&gt; $OutputDir\/memory_usage.out\r\nprint \"==============================================\" &gt;&gt; $OutputDir\/memory_usage.out\r\nprint \" \" &gt;&gt; $OutputDir\/memory_usage.out\r\nawk 'BEGIN { printf \"%-20s%20s%20s%20s%20s\\n\", \"Snapshot timestamp\", \"Max Limit\", <\/span><\/span><span style=\"color: #3366ff;\"><span style=\"font-size: xx-small;\">\"Current Usage\",\"High Water Mark\",\r\n\"Avail. in Current\"\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 printf \"%-20s%20s%20s%20s%20s\\n\", \"==================\", \"=========\", \"=============\",\"===============\",\"========\r\n==========\"}' print &gt;&gt; $OutputDir\/memory_usage.out\r\nfi\r\ndb2pd -dbptnmem |grep ' KB'| tr -s \" \" \" \" &gt; $OutputDir\/db2pd-memory.output\r\nwhile read currentline; do\r\n\u00c2\u00a0\u00c2\u00a0 keyword=`print \"$currentline\" |awk '{ print $1,$2 }'`\r\n\u00c2\u00a0 if [ \"$keyword\" = \"Memory Limit:\" ]\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 then\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 maximum=`print \"$currentline\" |awk '{ print $3 }'`\r\n\u00c2\u00a0 fi\r\n\u00c2\u00a0 if [ \"$keyword\" = \"Current usage:\" ]\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 then\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 current=`print \"$currentline\" |awk '{ print $3 }'`\r\n\u00c2\u00a0 fi\r\n\u00c2\u00a0 if [ \"$keyword\" = \"HWM usage:\" ]\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 then\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 highest=`print \"$currentline\" |awk '{ print $3 }'`\r\n\u00c2\u00a0 fi\r\n\u00c2\u00a0 if [ \"$keyword\" = \"Cached memory:\" ]\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 then\r\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 cached=`print \"$currentline\" |awk '{ print $3 }'`\r\n\u00c2\u00a0 fi\r\ndone &lt; $OutputDir\/db2pd-memory.output\r\nprint \"$Datetime\" \" \" \"$maximum\" \" \" \"$current\" \" \" \"$highest\" \" \" \"$cached\" &gt; $OutputDir\/tmp_memory_usage.out\r\nawk '{printf \"%-20s%20s%20s%20s%20s\\n\",$1,$2,$3,$4,$5}' $OutputDir\/tmp_memory_usage.out &gt;&gt; $OutputDir\/memory_usage.out\r\nrm $OutputDir\/db2pd-memory.output\r\nrm $OutputDir\/tmp_memory_usage.out\r\n<\/span><\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is a script that displays the current memory usage and peak memory usage of an instance and its databases.\u00c2\u00a0 The script basically used db2pd -dbptnmem\u00c2\u00a0 and parses out data to make it easy to read and manage. You can upload the data into a spread sheet to do trending.\u00c2\u00a0 I intend to expand on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[3],"tags":[943,227,186,226,225,228],"class_list":["post-364","post","type-post","status-publish","format-standard","hentry","category-db2","tag-db2","tag-db2-memory-usage","tag-db2pd","tag-db2pd-dbptnmem","tag-dbptnmen","tag-instance-memory"],"_links":{"self":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=364"}],"version-history":[{"count":5,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":1538,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/364\/revisions\/1538"}],"wp:attachment":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}