#!/usr/bin/ksh # dbspace-pages.sh # Similar in purpose to dpspace-space.sh: Display the number of free # pages and the percentage used for each dbspace. Since this uses # the output of onstat -d, it should execute far faster than # dbspace-space.sh. # # Author: Jacob Salomon # JakeSalomon@yahoo.com # Date: 1999-Sep-09 # Release: 1.0 # --------------------------------- # Revision history (A very slim history) # Date: 2006-05-23 # Release: 1.1 # - Added totals at the end of the list # - Added check for which flavor of awk to use. #---------------------------------------------------------------------- # Date: 2006-09-05 # Release 1.2 # - Discovered that not all hex address are 8 hex digits and changed # the variable, hex_pattern to some hex digit patterns, followed by + #---------------------------------------------------------------------- # # Decide which AWK program to use: gawk, nawk, or awk # if whence gawk >/dev/null then AWK=gawk elif whence nawk >/dev/null then AWK=nawk else AWK=awk fi onstat -d | $AWK ' BEGIN { hex_pattern = "^[0-9a-f]+$" } $1 == "address" {next} # Skip informational lines that might /active,/ {next} # otherwise sneak past other filters /Dbspaces/ { dbspace_section = 1 next } /Chunks/ { dbspace_section = 0 chunk_section = 1 next } dbspace_section == 1 { if ($1 ~ hex_pattern) { dbspnum = $2 # dbspace number high_dbsnum = dbspnum # Limit my looping at END dbspname[dbspnum] = $NF # Keep the dbspace name as well } } # chunk_section == 1 { if ((NF == 0) || !($1 ~ hex_pattern)) next # If not on a real data line, skip this dbspnum = $3 # Again, index by dbspace number chunk_pages = $5 # Number of pages in chunk chunk_count[dbspnum]++ # Tally number of chunks in this dbspace dbsp_pages[dbspnum] += chunk_pages # Tally pages in dbspace # Add up number of pages to this dbspace chunk_freepg = $6 # Free page count for chunk. If blob, will # be proceeded by a ~ ; get rid of it! if (substr(chunk_freepg,1,1) == "~") # If this is the case, { chunk_freepg = substr(chunk_freepg,2) # then lose the tilde # But wait! Theres more! Since this is a blob chunk, the free-page # count is the number of free blob pages, not a true indicator of # free space because blob pages may be much bigger. # In that case, determine the page size and multiply the number # of free [blob] pages by the blob page size. # blob_pages = $7 # For blob chunks, 7th field is BPage count blob_pgsize = chunk_pages / blob_pages # Calculate size of blob pg chunk_freepg *= blob_pgsize # Calculate truer free page count } dbsp_freepg[dbspnum] += chunk_freepg # NOW I can tally free pages in dbspace } END { out_format = "%s|%d|%d|%d|%d|%6.2f|\n" printf("DB-Space |DBS-Num|NumChunks|TotPages|FreePages|%%-Full|\n") total_freepg = 0 # Initialize some totals counts total_dbsp_pages = 0 # as we display the rows. total_dbsp_freepg = 0 # (Not necessary in AWK, of course) for (lc=1; lc<= high_dbsnum; lc++) { # There may be a gap in the sequence of dbspace numbers if a # dbspace has been dropped. There is no info for that array index # so skip that array index. # if (chunk_count[lc] == 0) # Good bet that dbspace[lc] aint there continue ratio_full = ((dbsp_pages[lc] - dbsp_freepg[lc])/dbsp_pages[lc]) percent_full[lc] = ratio_full * 100 printf(out_format, dbspname[lc], lc, chunk_count[lc], dbsp_pages[lc], dbsp_freepg[lc], percent_full[lc]) total_chunk_count += chunk_count[lc] total_dbsp_pages += dbsp_pages[lc] total_dbsp_freepg += dbsp_freepg[lc] } total_ratio_full = ((total_dbsp_pages - total_dbsp_freepg)/total_dbsp_pages) total_percent_full = total_ratio_full * 100 printf ("Totals:|0|%d|%d|%d|%6.2f|\n", total_chunk_count, total_dbsp_pages, total_dbsp_freepg, total_percent_full ) } ' | beautify-unl.sh