use of net.sf.ehcache.Statistics in project Gemma by PavlidisLab.
the class CacheMonitorImpl method getStats.
@Override
public String getStats() {
StringBuilder buf = new StringBuilder();
String[] cacheNames = cacheManager.getCacheNames();
Arrays.sort(cacheNames);
// Terracotta clustered?
TerracottaClientConfiguration terracottaConfig = cacheManager.getConfiguration().getTerracottaConfiguration();
buf.append("Distributed caching is ");
buf.append(terracottaConfig != null ? "enabled" : "disabled");
buf.append(" in the configuration file");
buf.append(terracottaConfig != null ? ". The cache server's configuration URL is at [" + terracottaConfig.getUrl() + "]" : "");
buf.append(".<br/>");
buf.append(cacheNames.length).append(" caches; only non-empty caches listed below.");
// FIXME make these sortable.
buf.append("<br/> To clear all caches click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"clearAllCaches()\" alt='Flush caches' title='Clear caches' /> ");
buf.append("<br/> To start statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"enableStatistics()\" alt='Enable stats' title='Enable stats' /> ");
buf.append("<br/> To stop statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"disableStatistics()\" alt='Disable stats' title='Disable stats' /> ");
buf.append("<table style='font-size:small' ><tr>");
String header = "<th>Name</th><th>HitRate</th><th>Hits</th><th>Misses</th><th>Count</th><th>MemHits</th><th>MemMiss</th><th>DiskHits</th><th>Evicted</th> <th>Eternal?</th><th>UseDisk?</th> <th>MaxInMem</th><th>LifeTime</th><th>IdleTime</th>";
buf.append(header);
buf.append("</tr>");
int count = 0;
for (String rawCacheName : cacheNames) {
Cache cache = cacheManager.getCache(rawCacheName);
Statistics statistics = cache.getStatistics();
long objectCount = statistics.getObjectCount();
if (objectCount == 0) {
continue;
}
// a little shorter...
String cacheName = rawCacheName.replaceFirst("ubic.gemma.model.", "u.g.m.");
buf.append("<tr><td>").append(this.getClearCacheHtml(rawCacheName)).append(cacheName).append("</td>");
long hits = statistics.getCacheHits();
long misses = statistics.getCacheMisses();
long inMemoryHits = statistics.getInMemoryHits();
long inMemoryMisses = statistics.getInMemoryMisses();
long onDiskHits = statistics.getOnDiskHits();
long evictions = statistics.getEvictionCount();
if (hits + misses > 0) {
buf.append(this.makeTableCellForStat(String.format("%.2f", (double) hits / (hits + misses))));
} else {
buf.append("<td></td>");
}
buf.append(this.makeTableCellForStat(hits));
buf.append(this.makeTableCellForStat(misses));
buf.append(this.makeTableCellForStat(objectCount));
buf.append(this.makeTableCellForStat(inMemoryHits));
buf.append(this.makeTableCellForStat(inMemoryMisses));
buf.append(this.makeTableCellForStat(onDiskHits));
buf.append(this.makeTableCellForStat(evictions));
CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
boolean eternal = cacheConfiguration.isEternal();
buf.append("<td>").append(eternal ? "•" : "").append("</td>");
Strategy strategy;
strategy = cacheConfiguration.getPersistenceConfiguration() == null ? null : cacheConfiguration.getPersistenceConfiguration().getStrategy();
buf.append("<td>").append(strategy == null || strategy.equals(Strategy.NONE) ? "" : "•").append("</td>");
buf.append("<td>").append(cacheConfiguration.getMaxEntriesLocalHeap()).append("</td>");
if (eternal) {
// timeouts are irrelevant.
buf.append("<td>-</td>");
buf.append("<td>-</td>");
} else {
buf.append("<td>").append(cacheConfiguration.getTimeToIdleSeconds()).append("</td>");
buf.append("<td>").append(cacheConfiguration.getTimeToLiveSeconds()).append("</td>");
}
buf.append("</tr>");
if (++count % 25 == 0) {
buf.append("<tr>").append(header).append("</tr>");
}
}
buf.append("</table>");
return buf.toString();
}
use of net.sf.ehcache.Statistics in project JMPjct by MPjct.
the class Eh method read_query.
@SuppressWarnings("unchecked")
public void read_query(Engine context) {
if (Eh.cache == null)
return;
String query = context.query;
String command = "";
String value = "";
// Reset all values on a new query
this.TTL = 0;
this.key = "";
if (!query.startsWith("/* "))
return;
// Extract out the command
command = query.substring(3, query.indexOf("*/")).trim();
if (command.indexOf(":") != -1) {
value = command.substring(command.indexOf(":") + 1).trim();
command = command.substring(0, command.indexOf(":")).trim();
}
query = query.substring(query.indexOf("*/") + 2).trim();
this.key = context.schema + ":" + query;
this.logger.info("Cache Key: '" + this.key + "'");
this.logger.trace("Command: '" + command + "'" + " value: '" + value + "'");
if (command.equalsIgnoreCase("CACHE")) {
this.logger.trace("CACHE");
this.TTL = Integer.parseInt(value);
context.buffer_result_set();
Eh.cache.acquireWriteLockOnKey(this.key);
Element element = Eh.cache.get(this.key);
if (element != null) {
this.logger.trace("Cache Hit!");
Eh.cache.releaseWriteLockOnKey(this.key);
context.clear_buffer();
context.buffer = (ArrayList<byte[]>) element.getValue();
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
if (context.buffer.size() == 0) {
ERR err = new ERR();
err.sequenceId = context.sequenceId + 1;
err.errorCode = 1032;
err.sqlState = "HY000";
err.errorMessage = "Can't find record in ehcache";
context.clear_buffer();
context.buffer.add(err.toPacket());
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
this.logger.fatal("Cache hit but invalid result!");
}
}
} else if (command.equalsIgnoreCase("FLUSH")) {
this.logger.trace("FLUSH");
OK ok = new OK();
boolean removed = Eh.cache.remove(this.key);
if (removed)
ok.affectedRows = 1;
ok.sequenceId = context.sequenceId + 1;
context.clear_buffer();
context.buffer.add(ok.toPacket());
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
} else if (command.equalsIgnoreCase("FLUSHALL")) {
this.logger.trace("FLUSHALL");
OK ok = new OK();
Eh.cache.removeAll();
ok.sequenceId = context.sequenceId + 1;
context.clear_buffer();
context.buffer.add(ok.toPacket());
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
} else if (command.equalsIgnoreCase("REFRESH")) {
this.logger.trace("REFRESH");
Eh.cache.remove(this.key);
this.TTL = Integer.parseInt(value);
context.buffer_result_set();
} else if (command.equalsIgnoreCase("STATS")) {
this.logger.trace("STATS");
ResultSet rs = new ResultSet();
Row row = null;
rs.addColumn(new Column("Key"));
rs.addColumn(new Column("Value"));
Statistics stats = Eh.cache.getStatistics();
rs.addRow(new Row("AverageGetTime", stats.getAverageGetTime()));
rs.addRow(new Row("AverageSearchTime", stats.getAverageSearchTime()));
rs.addRow(new Row("ObjectCount", stats.getObjectCount()));
rs.addRow(new Row("MemoryStoreObjectCount", stats.getMemoryStoreObjectCount()));
rs.addRow(new Row("OffHeapStoreObjectCount", stats.getOffHeapStoreObjectCount()));
rs.addRow(new Row("DiskStoreObjectCount", stats.getDiskStoreObjectCount()));
rs.addRow(new Row("CacheHits", stats.getCacheHits()));
rs.addRow(new Row("CacheMisses", stats.getCacheMisses()));
rs.addRow(new Row("InMemoryHits", stats.getInMemoryHits()));
rs.addRow(new Row("InMemoryMisses", stats.getInMemoryMisses()));
rs.addRow(new Row("OffHeapHits", stats.getOffHeapHits()));
rs.addRow(new Row("OffHeapMisses", stats.getOffHeapMisses()));
rs.addRow(new Row("OnDiskHits", stats.getOnDiskHits()));
rs.addRow(new Row("OnDiskMisses", stats.getOnDiskMisses()));
rs.addRow(new Row("EvictionCount", stats.getEvictionCount()));
rs.addRow(new Row("SearchesPerSecond", stats.getSearchesPerSecond()));
rs.addRow(new Row("WriterQueueSize", stats.getWriterQueueSize()));
context.clear_buffer();
context.buffer = rs.toPackets();
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
} else if (command.equalsIgnoreCase("INFO")) {
this.logger.trace("INFO");
ResultSet rs = new ResultSet();
Row row = null;
rs.addColumn(new Column("Key"));
rs.addColumn(new Column("Value"));
rs.addRow(new Row("getGuid", Eh.cache.getGuid()));
rs.addRow(new Row("getName", Eh.cache.getName()));
rs.addRow(new Row("getStatus", Eh.cache.getStatus().toString()));
rs.addRow(new Row("isDisabled", Eh.cache.isDisabled()));
rs.addRow(new Row("isSearchable", Eh.cache.isSearchable()));
try {
rs.addRow(new Row("isNodeBulkLoadEnabled", Eh.cache.isNodeBulkLoadEnabled()));
rs.addRow(new Row("isClusterBulkLoadEnabled", Eh.cache.isClusterBulkLoadEnabled()));
} catch (UnsupportedOperationException e) {
} catch (TerracottaNotRunningException e) {
}
rs.addRow(new Row("isStatisticsEnabled", Eh.cache.isStatisticsEnabled()));
rs.addRow(new Row("isSampledStatisticsEnabled", Eh.cache.isSampledStatisticsEnabled()));
switch(Eh.cache.getStatisticsAccuracy()) {
case Statistics.STATISTICS_ACCURACY_BEST_EFFORT:
rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_BEST_EFFORT"));
break;
case Statistics.STATISTICS_ACCURACY_GUARANTEED:
rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_GUARANTEED"));
break;
case Statistics.STATISTICS_ACCURACY_NONE:
rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_NONE"));
break;
default:
rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_UNKNOWN"));
break;
}
rs.addRow(new Row("hasAbortedSizeOf", Eh.cache.hasAbortedSizeOf()));
context.clear_buffer();
context.buffer = rs.toPackets();
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
} else if (command.equalsIgnoreCase("DUMP KEYS")) {
this.logger.trace("DUMP KEYS");
List keys = this.cache.getKeysWithExpiryCheck();
ResultSet rs = new ResultSet();
rs.addColumn(new Column("Key"));
for (Object k : keys) {
this.logger.trace("Key: '" + k + "'");
rs.addRow(new Row(k.toString()));
}
context.clear_buffer();
context.buffer = rs.toPackets();
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
} else {
this.logger.trace("FAIL");
ERR err = new ERR();
err.sequenceId = context.sequenceId + 1;
err.errorCode = 1047;
err.sqlState = "08S01";
err.errorMessage = "Unknown command '" + command + "'";
context.clear_buffer();
context.buffer.add(err.toPacket());
context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
this.logger.fatal(command + " is unknown!");
}
}
Aggregations