A SolrInfoBean that provides metrics on block cache operations. @lucene.experimental
| 28 | * @lucene.experimental |
| 29 | */ |
| 30 | public class Metrics extends SolrCacheBase implements SolrInfoBean { |
| 31 | |
| 32 | public AtomicLong blockCacheSize = new AtomicLong(0); |
| 33 | public AtomicLong blockCacheHit = new AtomicLong(0); |
| 34 | public AtomicLong blockCacheMiss = new AtomicLong(0); |
| 35 | public AtomicLong blockCacheEviction = new AtomicLong(0); |
| 36 | public AtomicLong blockCacheStoreFail = new AtomicLong(0); |
| 37 | |
| 38 | // since the last call |
| 39 | private AtomicLong blockCacheHit_last = new AtomicLong(0); |
| 40 | private AtomicLong blockCacheMiss_last = new AtomicLong(0); |
| 41 | private AtomicLong blockCacheEviction_last = new AtomicLong(0); |
| 42 | public AtomicLong blockCacheStoreFail_last = new AtomicLong(0); |
| 43 | |
| 44 | // These are used by the BufferStore (just a generic cache of byte[]). |
| 45 | // TODO: If this (the Store) is a good idea, we should make it more general and use it across more |
| 46 | // places in Solr. |
| 47 | public AtomicLong shardBuffercacheAllocate = new AtomicLong(0); |
| 48 | public AtomicLong shardBuffercacheLost = new AtomicLong(0); |
| 49 | |
| 50 | private SolrMetricsContext solrMetricsContext; |
| 51 | private long previous = System.nanoTime(); |
| 52 | |
| 53 | @Override |
| 54 | public void initializeMetrics(SolrMetricsContext parentContext, Attributes attributes) { |
| 55 | solrMetricsContext = parentContext.getChildContext(this); |
| 56 | var baseAttributes = |
| 57 | attributes.toBuilder().put(CATEGORY_ATTR, getCategory().toString()).build(); |
| 58 | var blockcacheStats = |
| 59 | solrMetricsContext.longGaugeMeasurement("solr_block_cache_stats", "Block cache stats"); |
| 60 | var hitRatio = |
| 61 | solrMetricsContext.doubleGaugeMeasurement( |
| 62 | "solr_block_cache_hit_ratio", "Block cache hit ratio"); |
| 63 | var perSecStats = |
| 64 | solrMetricsContext.doubleGaugeMeasurement( |
| 65 | "solr_block_cache_stats_per_second", "Block cache per second stats"); |
| 66 | var bufferCacheStats = |
| 67 | solrMetricsContext.doubleGaugeMeasurement( |
| 68 | "solr_buffer_cache_stats", "Buffer cache per second stats"); |
| 69 | |
| 70 | solrMetricsContext.batchCallback( |
| 71 | () -> { |
| 72 | long now = System.nanoTime(); |
| 73 | long delta = Math.max(now - previous, 1); |
| 74 | double seconds = delta / 1000000000.0; |
| 75 | |
| 76 | long hits_total = blockCacheHit.get(); |
| 77 | long hits_delta = hits_total - blockCacheHit_last.get(); |
| 78 | blockCacheHit_last.set(hits_total); |
| 79 | |
| 80 | long miss_total = blockCacheMiss.get(); |
| 81 | long miss_delta = miss_total - blockCacheMiss_last.get(); |
| 82 | blockCacheMiss_last.set(miss_total); |
| 83 | |
| 84 | long evict_total = blockCacheEviction.get(); |
| 85 | long evict_delta = evict_total - blockCacheEviction_last.get(); |
| 86 | blockCacheEviction_last.set(evict_total); |
| 87 |
nothing calls this directly
no test coverage detected
searching dependent graphs…