@Override public boolean hasGroupName() { return handleConfig.hasGroupName(); }
private void recordSliceMetrics(StoreTransaction txh, List<Entry> row) { if (!txh.getConfiguration().hasGroupName()) return; String p = txh.getConfiguration().getGroupName(); final MetricManager mgr = MetricManager.INSTANCE; mgr.getCounter(p, metricsStoreName, M_GET_SLICE, M_ENTRIES_COUNT).inc(row.size()); mgr.getHistogram(p, metricsStoreName, M_GET_SLICE, M_ENTRIES_HISTO).update(row.size()); }
protected void incActionBy(int by, CacheMetricsAction action, StoreTransaction txh) { assert by>=1; if (metricsName!=null && txh.getConfiguration().hasGroupName()) { MetricManager.INSTANCE.getCounter(txh.getConfiguration().getGroupName(), metricsName, action.getName()).inc(by); } }
static <T> T runWithMetrics(StoreTransaction txh, String storeName, String name, StorageCallable<T> impl) throws BackendException { if (!txh.getConfiguration().hasGroupName()) { return impl.call(); } String prefix = txh.getConfiguration().getGroupName(); Preconditions.checkNotNull(name); Preconditions.checkNotNull(impl); final MetricManager mgr = MetricManager.INSTANCE; mgr.getCounter(prefix, storeName, name, M_CALLS).inc(); final Timer.Context tc = mgr.getTimer(prefix, storeName, name, M_TIME).time(); try { return impl.call(); } catch (BackendException | RuntimeException e) { mgr.getCounter(prefix, storeName, name, M_EXCEPTIONS).inc(); throw e; } finally { tc.stop(); } }
@Override public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException { if (!txh.getConfiguration().hasGroupName()) { backend.mutateMany(mutations,txh); } String prefix = txh.getConfiguration().getGroupName(); final MetricManager mgr = MetricManager.INSTANCE; mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_CALLS).inc(); final Timer.Context tc = mgr.getTimer(prefix, managerMetricsName, M_MUTATE, M_TIME).time(); try { backend.mutateMany(mutations,txh); } catch (BackendException | RuntimeException e) { mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_EXCEPTIONS).inc(); throw e; } finally { tc.stop(); } }
@Override public KeyIterator getKeys(final KeyRangeQuery query, final StoreTransaction txh) throws BackendException { return runWithMetrics(txh, metricsStoreName, M_GET_KEYS, () -> { final KeyIterator ki = backend.getKeys(query, txh); if (txh.getConfiguration().hasGroupName()) { return MetricInstrumentedIterator.of(ki, txh.getConfiguration().getGroupName(), metricsStoreName, M_GET_KEYS, M_ITERATOR); } else { return ki; } }); }
@Override public KeyIterator getKeys(final SliceQuery query, final StoreTransaction txh) throws BackendException { return runWithMetrics(txh, metricsStoreName, M_GET_KEYS, () -> { final KeyIterator ki = backend.getKeys(query, txh); if (txh.getConfiguration().hasGroupName()) { return MetricInstrumentedIterator.of(ki, txh.getConfiguration().getGroupName(), metricsStoreName, M_GET_KEYS, M_ITERATOR); } else { return ki; } }); }