1 2 12 package com.versant.core.storagemanager.logging; 13 14 import com.versant.core.storagemanager.StorageManagerFactory; 15 import com.versant.core.storagemanager.StorageManager; 16 import com.versant.core.metric.HasMetrics; 17 import com.versant.core.metadata.ModelMetaData; 18 import com.versant.core.server.DataStoreInfo; 19 import com.versant.core.server.CompiledQueryCache; 20 import com.versant.core.metric.BaseMetric; 21 import com.versant.core.metric.Metric; 22 import com.versant.core.metric.HasMetrics; 23 import com.versant.core.logging.LogEventStore; 24 25 import java.util.List ; 26 import java.util.Set ; 27 28 32 public final class LoggingStorageManagerFactory 33 implements StorageManagerFactory, HasMetrics { 34 35 private final StorageManagerFactory smf; 36 private final LogEventStore pes; 37 38 public int txCount; 39 public int txCommitCount; 40 public int txCommitErrorCount; 41 public int txRollbackCount; 42 public int txFlushCount; 43 public int txFlushErrorCount; 44 public int fetchCount; 45 public int fetchErrorCount; 46 public int queryCount; 47 public int queryErrorCount; 48 49 private static final String CAT_MEM = "Memory"; 50 51 private final BaseMetric metricMemoryFree = 52 new BaseMetric("MemFreeKB", "Mem Free KB", CAT_MEM, 53 "Available heap memory in KB", 0, Metric.CALC_AVERAGE); 54 private final BaseMetric metricMemoryTotal = 55 new BaseMetric("MemTotalKB", "Mem Total KB", CAT_MEM, 56 "Total heap memory in KB", 0, Metric.CALC_AVERAGE); 57 58 private static final String CAT_TX = "Transactions"; 59 60 private final BaseMetric metricTx = 61 new BaseMetric("Tx", "Tx", CAT_TX, 62 "Transactions started", 3, 63 Metric.CALC_DELTA_PER_SECOND); 64 private final BaseMetric metricTxCommit = 65 new BaseMetric("TxCommit", "Tx Commit", CAT_TX, 66 "Transactions committed", 3, 67 Metric.CALC_DELTA_PER_SECOND); 68 private final BaseMetric metricTxCommitError = 69 new BaseMetric("TxCommitError", "Tx Commit Error", CAT_TX, 70 "Transactions that failed with an error during commit", 3, 71 Metric.CALC_DELTA_PER_SECOND); 72 private final BaseMetric metricTxRollback = 73 new BaseMetric("TxRollback", "Tx Rollback", CAT_TX, 74 "Transactions rolled back", 3, 75 Metric.CALC_DELTA); 76 private final BaseMetric metricTxFlush = 77 new BaseMetric("TxFlush", "Tx Flush", CAT_TX, 78 "Flushes prior to transaction commit", 3, 79 Metric.CALC_DELTA_PER_SECOND); 80 private final BaseMetric metricTxFlushError = 81 new BaseMetric("TxFlushError", "Tx Flush Error", CAT_TX, 82 "Flushes that failed with an error", 3, 83 Metric.CALC_DELTA_PER_SECOND); 84 85 private static final String CAT_FETCH = "Fetches"; 86 87 private final BaseMetric metricFetch = 88 new BaseMetric("Fetch", "Fetch", CAT_FETCH, 89 "Number of calls to fetch data", 3, 90 Metric.CALC_DELTA_PER_SECOND); 91 private final BaseMetric metricFetchError = 92 new BaseMetric("FetchError", "Fetch Error", CAT_FETCH, 93 "Number of calls to fetch data that failed with an error", 3, 94 Metric.CALC_DELTA_PER_SECOND); 95 private final BaseMetric metricQuery = 96 new BaseMetric("Query", "Query", CAT_FETCH, 97 "Number of queries executed", 3, 98 Metric.CALC_DELTA_PER_SECOND); 99 private final BaseMetric metricQueryError = 100 new BaseMetric("QueryError", "Query Error", CAT_FETCH, 101 "Number of queries executed that failed with an error", 3, 102 Metric.CALC_DELTA_PER_SECOND); 103 104 public LoggingStorageManagerFactory(StorageManagerFactory smf, 105 LogEventStore pes) { 106 this.smf = smf; 107 this.pes = pes; 108 } 109 110 public LogEventStore getLogEventStore() { 111 return pes; 112 } 113 114 public void init(boolean full, ClassLoader loader) { 115 smf.init(full, loader); 116 } 117 118 public void destroy() { 119 smf.destroy(); 120 } 121 122 public StorageManager getStorageManager() { 123 StorageManager sm = smf.getStorageManager(); 124 return new LoggingStorageManager(this, sm); 125 } 126 127 public void returnStorageManager(StorageManager sm) { 128 smf.returnStorageManager(sm); 129 } 130 131 public ModelMetaData getModelMetaData() { 132 return smf.getModelMetaData(); 133 } 134 135 public Object getDatastoreConnection() { 136 return smf.getDatastoreConnection(); 137 } 138 139 public void closeIdleDatastoreConnections() { 140 smf.closeIdleDatastoreConnections(); 141 } 142 143 public DataStoreInfo getDataStoreInfo() { 144 return smf.getDataStoreInfo(); 145 } 146 147 public StorageManagerFactory getInnerStorageManagerFactory() { 148 return smf; 149 } 150 151 public void addMetrics(List list) { 152 list.add(metricMemoryFree); 153 list.add(metricMemoryTotal); 154 list.add(metricTx); 155 list.add(metricTxCommit); 156 list.add(metricTxCommitError); 157 list.add(metricTxRollback); 158 list.add(metricTxFlush); 159 list.add(metricTxFlushError); 160 list.add(metricFetch); 161 list.add(metricFetchError); 162 list.add(metricQuery); 163 list.add(metricQueryError); 164 if (smf instanceof HasMetrics) { 165 ((HasMetrics)smf).addMetrics(list); 166 } 167 } 168 169 public void sampleMetrics(int[][] buf, int pos) { 170 Runtime r = Runtime.getRuntime(); 171 buf[metricMemoryFree.getIndex()][pos] = (int)(r.freeMemory() >> 10); 172 buf[metricMemoryTotal.getIndex()][pos] = (int)(r.totalMemory() >> 10); 173 buf[metricTx.getIndex()][pos] = txCount; 174 buf[metricTxCommit.getIndex()][pos] = txCommitCount; 175 buf[metricTxCommitError.getIndex()][pos] = txCommitErrorCount; 176 buf[metricTxRollback.getIndex()][pos] = txRollbackCount; 177 buf[metricTxFlush.getIndex()][pos] = txFlushCount; 178 buf[metricTxFlushError.getIndex()][pos] = txFlushErrorCount; 179 buf[metricFetch.getIndex()][pos] = fetchCount; 180 buf[metricFetchError.getIndex()][pos] = fetchErrorCount; 181 buf[metricQuery.getIndex()][pos] = queryCount; 182 buf[metricQueryError.getIndex()][pos] = queryErrorCount; 183 if (smf instanceof HasMetrics) { 184 ((HasMetrics)smf).sampleMetrics(buf, pos); 185 } 186 } 187 188 public void supportedOptions(Set options) { 189 smf.supportedOptions(options); 190 } 191 192 public CompiledQueryCache getCompiledQueryCache() { 193 return smf.getCompiledQueryCache(); 194 } 195 196 } 197 198 | Popular Tags |