private List < Metric > checkCache ( final Connection c , final ICommandLine cl ) throws BadThresholdException , SQLException { List < Metric > metricList = new ArrayList < Metric > ( ) ; // Metrics cache_buf, cache_lib String sQry1 = "select (1-(pr.value/(dbg.value+cg.value)))*100" + " from v$sysstat pr, v$sysstat dbg, v$sysstat cg" + " where pr.name='physical reads'" + " and dbg.name='db block gets'" + " and cg.name='consistent gets'" ; String sQry2 = "select sum(lc.pins)/(sum(lc.pins)" + "+sum(lc.reloads))*100 from v$librarycache lc" ; Statement stmt = null ; ResultSet rs = null ; try { stmt = c . createStatement ( ) ; rs = stmt . executeQuery ( sQry1 ) ; rs . next ( ) ; BigDecimal buf_hr = rs . getBigDecimal ( 1 ) ; rs = stmt . executeQuery ( sQry2 ) ; rs . next ( ) ; BigDecimal lib_hr = rs . getBigDecimal ( 1 ) ; String libHitRate = "Cache Hit Rate {1,number,0.#}% Lib" ; String buffHitRate = "Cache Hit Rate {1,number,0.#}% Buff" ; metricList . add ( new Metric ( "cache_buf" , MessageFormat . format ( buffHitRate , buf_hr ) , buf_hr , new BigDecimal ( 0 ) , new BigDecimal ( 100 ) ) ) ; metricList . add ( new Metric ( "cache_lib" , MessageFormat . format ( libHitRate , lib_hr ) , lib_hr , new BigDecimal ( 0 ) , new BigDecimal ( 100 ) ) ) ; return metricList ; } finally { DBUtils . closeQuietly ( rs ) ; DBUtils . closeQuietly ( stmt ) ; } }
Checks cache hit rates .