@Test @SuppressWarnings("squid:S2925") public void testThatMappingFromTemplateIsApplied() throws Exception { registry.counter(name("test", "cache-evictions")).inc(); reportAndRefresh(); // somehow the cluster state is not immediately updated... need to check Thread.sleep(200); ClusterStateResponse clusterStateResponse = client() .admin() .cluster() .prepareState() .setRoutingTable(false) .setLocal(false) .setNodes(true) .setIndices(indexWithDate) .execute() .actionGet(); org.assertj.core.api.Assertions.assertThat( clusterStateResponse.getState().getMetaData().getIndices().containsKey(indexWithDate)) .isTrue(); IndexMetaData indexMetaData = clusterStateResponse.getState().getMetaData().getIndices().get(indexWithDate); org.assertj.core.api.Assertions.assertThat(indexMetaData.getMappings().containsKey("counter")) .isTrue(); Map<String, Object> properties = getAsMap(indexMetaData.mapping("counter").sourceAsMap(), "properties"); Map<String, Object> mapping = getAsMap(properties, "name"); org.assertj.core.api.Assertions.assertThat(mapping).containsKey("index"); org.assertj.core.api.Assertions.assertThat(mapping.get("index").toString()) .isEqualTo("not_analyzed"); }
@Override protected void onComplete(Request request, Response response) { activeRequestsCounter.dec(); Long duration = computeDurationMillis(START_TIMES_BY_CORRELATION_ID.remove(request.getCorrelationId())); if (duration != null && duration.longValue() > 0) { allTimesTimer.update(duration, TimeUnit.MILLISECONDS); String name = getRouteName(request); if (name == null || name.isEmpty()) return; ROUTE_TIMERS.get(name).update(duration, TimeUnit.MILLISECONDS); } Counter responseCounter = COUNTERS_BY_RESPONSE.get(response.getResponseStatus().getCode()); if (responseCounter == null) { responseCounter = metrics.counter(getResponseCounterName(response.getResponseStatus())); COUNTERS_BY_RESPONSE.putIfAbsent(response.getResponseStatus().getCode(), responseCounter); } responseCounter.inc(); publish(request, response, duration); }
private void registerSchedulerMetrics() { samplerLock.lock(); try { // counters for scheduler operations schedulerAllocateCounter = metrics.counter("counter.scheduler.operation.allocate"); schedulerHandleCounter = metrics.counter("counter.scheduler.operation.handle"); schedulerHandleCounterMap = new HashMap<SchedulerEventType, Counter>(); for (SchedulerEventType e : SchedulerEventType.values()) { Counter counter = metrics.counter("counter.scheduler.operation.handle." + e); schedulerHandleCounterMap.put(e, counter); } // timers for scheduler operations int timeWindowSize = conf.getInt( SLSConfiguration.METRICS_TIMER_WINDOW_SIZE, SLSConfiguration.METRICS_TIMER_WINDOW_SIZE_DEFAULT); schedulerAllocateTimer = new Timer(new SlidingWindowReservoir(timeWindowSize)); schedulerHandleTimer = new Timer(new SlidingWindowReservoir(timeWindowSize)); schedulerHandleTimerMap = new HashMap<SchedulerEventType, Timer>(); for (SchedulerEventType e : SchedulerEventType.values()) { Timer timer = new Timer(new SlidingWindowReservoir(timeWindowSize)); schedulerHandleTimerMap.put(e, timer); } // histogram for scheduler operations (Samplers) schedulerHistogramList = new ArrayList<Histogram>(); histogramTimerMap = new HashMap<Histogram, Timer>(); Histogram schedulerAllocateHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE)); metrics.register("sampler.scheduler.operation.allocate.timecost", schedulerAllocateHistogram); schedulerHistogramList.add(schedulerAllocateHistogram); histogramTimerMap.put(schedulerAllocateHistogram, schedulerAllocateTimer); Histogram schedulerHandleHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE)); metrics.register("sampler.scheduler.operation.handle.timecost", schedulerHandleHistogram); schedulerHistogramList.add(schedulerHandleHistogram); histogramTimerMap.put(schedulerHandleHistogram, schedulerHandleTimer); for (SchedulerEventType e : SchedulerEventType.values()) { Histogram histogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE)); metrics.register("sampler.scheduler.operation.handle." + e + ".timecost", histogram); schedulerHistogramList.add(histogram); histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e)); } } finally { samplerLock.unlock(); } }
public static void main(String[] args) { // create some various metrics and update them MetricRegistry registry = new MetricRegistry(); final AtomicInteger gaugeInteger = new AtomicInteger(); registry.register( name("gauge"), new Gauge<Integer>() { @Override public Integer getValue() { return gaugeInteger.get(); } }); final Counter counter = registry.counter(name("counter")); final Histogram histogram = registry.histogram(name("histogram")); final Meter meter = registry.meter(name("meter")); final Timer timer = registry.timer(name("timer")); NewRelicReporter reporter = new NewRelicReporter( registry, "new relic reporter", MetricFilter.ALL, new AllEnabledMetricAttributeFilter(), TimeUnit.SECONDS, TimeUnit.MILLISECONDS, "foo/"); reporter.start(60, TimeUnit.SECONDS); ScheduledExecutorService svc = Executors.newScheduledThreadPool(1); final Random random = new Random(); svc.scheduleAtFixedRate( new Runnable() { @Override public void run() { System.out.println("Updating"); gaugeInteger.incrementAndGet(); counter.inc(); histogram.update(random.nextInt(10)); meter.mark(); timer.update(random.nextInt(10), TimeUnit.MILLISECONDS); } }, 0, 1, TimeUnit.SECONDS); }
public GlobalTimeoutClient( Client in, long timeout, TimeUnit unit, MetricRegistry metricRegistry) { super(in); checkArgument(timeout > 0); this.timeout = timeout; this.unit = checkNotNull(unit); this.searchRequests = metricRegistry.counter(name(GlobalTimeoutClient.class, "search-requests")); }
private void updateQueueMetrics(String queue, int releasedMemory, int releasedVCores) { // update queue counters SortedMap<String, Counter> counterMap = metrics.getCounters(); if (releasedMemory != 0) { String name = "counter.queue." + queue + ".allocated.memory"; if (!counterMap.containsKey(name)) { metrics.counter(name); counterMap = metrics.getCounters(); } counterMap.get(name).inc(-releasedMemory); } if (releasedVCores != 0) { String name = "counter.queue." + queue + ".allocated.cores"; if (!counterMap.containsKey(name)) { metrics.counter(name); counterMap = metrics.getCounters(); } counterMap.get(name).inc(-releasedVCores); } }
public void init(FilterConfig filterConfig) throws ServletException { final MetricRegistry metricsRegistry = Metrics.metricRegistry(); this.metersByStatusCode = new ConcurrentHashMap<Integer, Meter>(meterNamesByStatusCode.size()); for (Map.Entry<Integer, String> entry : meterNamesByStatusCode.entrySet()) { metersByStatusCode.put(entry.getKey(), metricsRegistry.meter(name("http", entry.getValue()))); } this.otherMeter = metricsRegistry.meter(name("http", otherMetricName)); this.activeRequests = metricsRegistry.counter(name("http", "activeRequests")); this.requestTimer = metricsRegistry.timer(name("http", "requests")); }
@Test public void testThatTimeBasedIndicesCanBeDisabled() throws Exception { elasticsearchReporter = createElasticsearchReporterBuilder().indexDateFormat("").build(); indexWithDate = index; registry.counter(name("test", "cache-evictions")).inc(); reportAndRefresh(); SearchResponse searchResponse = client().prepareSearch(index).setTypes("counter").execute().actionGet(); org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()).isEqualTo(1L); }
@Test public void testThatPercolationNotificationWorks() throws IOException, InterruptedException { SimpleNotifier notifier = new SimpleNotifier(); MetricFilter percolationFilter = new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return name.startsWith(prefix + ".foo"); } }; elasticsearchReporter = createElasticsearchReporterBuilder() .percolationFilter(percolationFilter) .percolationNotifier(notifier) .build(); final Counter evictions = registry.counter("foo"); evictions.inc(18); reportAndRefresh(); QueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.matchAllQuery()) .filter( QueryBuilders.boolQuery() .must(QueryBuilders.rangeQuery("count").gte(20)) .must(QueryBuilders.termQuery("name", prefix + ".foo"))); String json = String.format("{ \"query\" : %s }", queryBuilder.buildAsBytes().toUtf8()); client() .prepareIndex(indexWithDate, ".percolator", "myName") .setRefresh(true) .setSource(json) .execute() .actionGet(); evictions.inc(1); reportAndRefresh(); assertThat(notifier.metrics.size(), is(0)); evictions.inc(2); reportAndRefresh(); org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(1); org.assertj.core.api.Assertions.assertThat(notifier.metrics).containsKey("myName"); org.assertj.core.api.Assertions.assertThat(notifier.metrics.get("myName").name()) .isEqualTo(prefix + ".foo"); notifier.metrics.clear(); evictions.dec(2); reportAndRefresh(); org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(0); }
@Test public void testThatBulkIndexingWorks() { for (int i = 0; i < 2020; i++) { final Counter evictions = registry.counter(name("foo", "bar", String.valueOf(i))); evictions.inc(i); } reportAndRefresh(); SearchResponse searchResponse = client().prepareSearch(indexWithDate).setTypes("counter").execute().actionGet(); org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()) .isEqualTo(2020L); }
@Override public void process(Request request) { String name = getRouteName(request); if (name == null || name.isEmpty()) return; if (!ROUTE_TIMERS.containsKey(name)) { ROUTE_TIMERS.putIfAbsent(name, metrics.timer(getTimerName(name))); } if (!EXCEPTION_COUNTERS_BY_ROUTE.containsKey(name)) { EXCEPTION_COUNTERS_BY_ROUTE.putIfAbsent(name, metrics.counter(getExceptionCounterName(name))); } }
@Test public void testCounter() { System.out.println("******************************* COUNTER *******************************"); counter = registry.counter("counter"); try { for (int i = 0; i < ITER_COUNT; i++) { counter.inc(i); Thread.sleep(SLEEP_MS); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } }
@Test public void testThatTimestampFieldnameCanBeConfigured() throws Exception { elasticsearchReporter = createElasticsearchReporterBuilder().timestampFieldname("myTimeStampField").build(); registry.counter(name("myMetrics", "cache-evictions")).inc(); reportAndRefresh(); SearchResponse searchResponse = client().prepareSearch(indexWithDate).setTypes("counter").execute().actionGet(); org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()).isEqualTo(1); Map<String, Object> hit = searchResponse.getHits().getAt(0).sourceAsMap(); org.assertj.core.api.Assertions.assertThat(hit).containsKey("myTimeStampField"); }
@Test public void testThatSpecifyingSeveralHostsWork() throws Exception { elasticsearchReporter = createElasticsearchReporterBuilder() .hosts("localhost:10000", "localhost:" + getPortOfRunningNode()) .build(); registry.counter(name("test", "cache-evictions")).inc(); reportAndRefresh(); SearchResponse searchResponse = client().prepareSearch(indexWithDate).setTypes("counter").execute().actionGet(); org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()).isEqualTo(1L); }
@Test public void testCounter() throws Exception { final Counter evictions = registry.counter(name("test", "cache-evictions")); evictions.inc(25); reportAndRefresh(); SearchResponse searchResponse = client().prepareSearch(indexWithDate).setTypes("counter").execute().actionGet(); org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()).isEqualTo(1L); Map<String, Object> hit = searchResponse.getHits().getAt(0).sourceAsMap(); assertTimestamp(hit); assertKey(hit, "count", 25); assertKey(hit, "name", prefix + ".test.cache-evictions"); assertKey(hit, "host", "localhost"); }
public static void main(String[] args) { ReporterV08 reporter = null; try { final MetricRegistry registry = new MetricRegistry(); reporter = getInfluxdbReporter(registry); reporter.start(3, TimeUnit.SECONDS); final Counter counter = registry.counter(MetricRegistry.name("test", "counter")); for (int i = 0; i < 1; ++i) { counter.inc(); Thread.sleep(Math.round(Math.random()) * 1000); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { if (reporter != null) { reporter.report(); reporter.stop(); } } }
@PostConstruct public void init() { matchesSuccess = metricRegistry.counter( MetricRegistry.name(FootballMatchService.class, "matches-successes")); matchesFailures = metricRegistry.counter(MetricRegistry.name(FootballMatchService.class, "matches-failures")); metadataSuccess = metricRegistry.counter( MetricRegistry.name(FootballMatchService.class, "meta-data-successes")); metadataFailures = metricRegistry.counter( MetricRegistry.name(FootballMatchService.class, "meta-data-failures")); predictionsSuccess = metricRegistry.counter( MetricRegistry.name(FootballMatchService.class, "predictions-successes")); predictionsFailures = metricRegistry.counter( MetricRegistry.name(FootballMatchService.class, "predictions-failures")); }
@Override protected void doStart() throws Exception { super.doStart(); final String prefix = name(getHandler().getClass(), name); this.requests = timer(name(prefix, "requests")); this.dispatches = timer(name(prefix, "dispatches")); this.activeRequests = metricRegistry.counter(name(prefix, "active-requests")); this.activeDispatches = metricRegistry.counter(name(prefix, "active-dispatches")); this.activeSuspended = metricRegistry.counter(name(prefix, "active-suspended")); this.asyncDispatches = metricRegistry.meter(name(prefix, "async-dispatches")); this.asyncTimeouts = metricRegistry.meter(name(prefix, "async-timeouts")); this.responses = new Meter[] { metricRegistry.meter(name(prefix, "1xx-responses")), // 1xx metricRegistry.meter(name(prefix, "2xx-responses")), // 2xx metricRegistry.meter(name(prefix, "3xx-responses")), // 3xx metricRegistry.meter(name(prefix, "4xx-responses")), // 4xx metricRegistry.meter(name(prefix, "5xx-responses")) // 5xx }; this.getRequests = timer(name(prefix, "get-requests")); this.postRequests = timer(name(prefix, "post-requests")); this.headRequests = timer(name(prefix, "head-requests")); this.putRequests = timer(name(prefix, "put-requests")); this.deleteRequests = timer(name(prefix, "delete-requests")); this.optionsRequests = timer(name(prefix, "options-requests")); this.traceRequests = timer(name(prefix, "trace-requests")); this.connectRequests = timer(name(prefix, "connect-requests")); this.moveRequests = timer(name(prefix, "move-requests")); this.otherRequests = timer(name(prefix, "other-requests")); this.listener = new AsyncListener() { @Override public void onTimeout(AsyncEvent event) throws IOException { asyncTimeouts.mark(); } @Override public void onStartAsync(AsyncEvent event) throws IOException { event.getAsyncContext().addListener(this); } @Override public void onError(AsyncEvent event) throws IOException {} @Override public void onComplete(AsyncEvent event) throws IOException { final AsyncContextState state = (AsyncContextState) event.getAsyncContext(); final Request request = (Request) state.getRequest(); updateResponses(request); if (!(state.getHttpChannelState().getState() == State.DISPATCHED)) { activeSuspended.dec(); } } }; }
/** * @param availableServerStats the server instances to choose from * @return the nearest, less loaded server instance * @see {@link LoadBalancer#choose(java.util.List)} */ @Override public ServerStats choose(List<ServerStats> availableServerStats) { // cache properties to speed up loop double maxRequestsPerSecond = propMaxRequestsPerSecond.get(); double escapeAreaThreshold = propEscapeAreaThreshold.get(); double escapeRegionThreshold = propEscapeRegionThreshold.get(); double escapeAvailabilityThreshold = propEscapeAvailabilityThreshold.get(); // find the best available server MetaData max = null; for (ServerStats stat : availableServerStats) { ServerStats s = (ServerStats) stat; ServerInstance instance = s.getServerInstance(); MetaData meta = new MetaData(); meta.location = locations.getUnchecked(s); meta.server = s; meta.load = s.getSentMessagesPerSecond() / maxRequestsPerSecond; meta.sessionCount = s.getOpenSessionsCount(); meta.locationBits = 0; if (myLocation.getAvailabilityZone().equals(meta.location.getAvailabilityZone())) { // same availability zone meta.locationBits = 7; } else if (myLocation.getRegion().equals(meta.location.getRegion())) { // same region meta.locationBits = 3; } else if (myLocation.getArea().equals(meta.location.getArea())) { // same area meta.locationBits = 1; } // keep the best server instance if (max == null) { max = meta; } else if (meta.isBetterThan( max, escapeAreaThreshold, escapeRegionThreshold, escapeAvailabilityThreshold)) { max = meta; } } if (max != null) { if (metricRegistry != null) { Counter counter = availabilityZoneToCounter.get(max.location.getAvailabilityZone()); if (counter == null) { counter = metricRegistry.counter( name(serviceName, "az-requests", max.location.getAvailabilityZone())); Counter prevCount = availabilityZoneToCounter.putIfAbsent(max.location.getAvailabilityZone(), counter); if (prevCount != null) { // another thread snuck in their counter during a race condition so use it instead. counter = prevCount; } } counter.inc(); } return max.server; } else { return null; } }
public static Counter counter(String name) { return metrics.counter(name); }
private void updateQueueWithAllocateRequest( Allocation allocation, ApplicationAttemptId attemptId, List<ResourceRequest> resourceRequests, List<ContainerId> containerIds) throws IOException { // update queue information Resource pendingResource = Resources.createResource(0, 0); Resource allocatedResource = Resources.createResource(0, 0); String queueName = appQueueMap.get(attemptId.getApplicationId()); // container requested for (ResourceRequest request : resourceRequests) { if (request.getResourceName().equals(ResourceRequest.ANY)) { Resources.addTo( pendingResource, Resources.multiply(request.getCapability(), request.getNumContainers())); } } // container allocated for (Container container : allocation.getContainers()) { Resources.addTo(allocatedResource, container.getResource()); Resources.subtractFrom(pendingResource, container.getResource()); } // container released from AM SchedulerAppReport report = scheduler.getSchedulerAppInfo(attemptId); for (ContainerId containerId : containerIds) { Container container = null; for (RMContainer c : report.getLiveContainers()) { if (c.getContainerId().equals(containerId)) { container = c.getContainer(); break; } } if (container != null) { // released allocated containers Resources.subtractFrom(allocatedResource, container.getResource()); } else { for (RMContainer c : report.getReservedContainers()) { if (c.getContainerId().equals(containerId)) { container = c.getContainer(); break; } } if (container != null) { // released reserved containers Resources.subtractFrom(pendingResource, container.getResource()); } } } // containers released/preemption from scheduler Set<ContainerId> preemptionContainers = new HashSet<ContainerId>(); if (allocation.getContainerPreemptions() != null) { preemptionContainers.addAll(allocation.getContainerPreemptions()); } if (allocation.getStrictContainerPreemptions() != null) { preemptionContainers.addAll(allocation.getStrictContainerPreemptions()); } if (!preemptionContainers.isEmpty()) { for (ContainerId containerId : preemptionContainers) { if (!preemptionContainerMap.containsKey(containerId)) { Container container = null; for (RMContainer c : report.getLiveContainers()) { if (c.getContainerId().equals(containerId)) { container = c.getContainer(); break; } } if (container != null) { preemptionContainerMap.put(containerId, container.getResource()); } } } } // update metrics SortedMap<String, Counter> counterMap = metrics.getCounters(); String names[] = new String[] { "counter.queue." + queueName + ".pending.memory", "counter.queue." + queueName + ".pending.cores", "counter.queue." + queueName + ".allocated.memory", "counter.queue." + queueName + ".allocated.cores" }; int values[] = new int[] { pendingResource.getMemory(), pendingResource.getVirtualCores(), allocatedResource.getMemory(), allocatedResource.getVirtualCores() }; for (int i = names.length - 1; i >= 0; i--) { if (!counterMap.containsKey(names[i])) { metrics.counter(names[i]); counterMap = metrics.getCounters(); } counterMap.get(names[i]).inc(values[i]); } queueLock.lock(); try { if (!schedulerMetrics.isTracked(queueName)) { schedulerMetrics.trackQueue(queueName); } } finally { queueLock.unlock(); } }
private ExtensionResponse tryExecuteGremlinScript( final RexsterResourceContext rexsterResourceContext, final Graph graph, final Vertex vertex, final Edge edge, final String script) { final MetricRegistry metricRegistry = rexsterResourceContext.getMetricRegistry(); final Timer scriptTimer = metricRegistry.timer(MetricRegistry.name("http", "script-engine")); final Counter successfulExecutions = metricRegistry.counter(MetricRegistry.name("http", "script-engine", "success")); final Counter failedExecutions = metricRegistry.counter(MetricRegistry.name("http", "script-engine", "fail")); ExtensionResponse extensionResponse; final JSONObject requestObject = rexsterResourceContext.getRequestObject(); // can't initialize this statically because the configure() method won't get called before it. // need to think a bit on how to best initialized the controller. final EngineController engineController = EngineController.getInstance(); final boolean showTypes = RequestObjectHelper.getShowTypes(requestObject); final long offsetStart = RequestObjectHelper.getStartOffset(requestObject); final long offsetEnd = RequestObjectHelper.getEndOffset(requestObject); final GraphSONMode mode = showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL; final Set<String> returnKeys = RequestObjectHelper.getReturnKeys(requestObject, WILDCARD); final String languageToExecuteWith = getLanguageToExecuteWith(requestObject); final EngineHolder engineHolder; final ScriptEngine scriptEngine; try { if (!engineController.isEngineAvailable(languageToExecuteWith)) { return ExtensionResponse.error("language requested is not available on the server"); } engineHolder = engineController.getEngineByLanguageName(languageToExecuteWith); scriptEngine = engineHolder.getEngine(); } catch (ScriptException se) { return ExtensionResponse.error("could not get request script engine"); } final Bindings bindings = createBindings(graph, vertex, edge, scriptEngine); // add all keys not defined by this request as bindings to the script engine placeParametersOnBinding(requestObject, bindings, showTypes); // get the list of "stored procedures" to run final RexsterApplicationGraph rag = rexsterResourceContext.getRexsterApplicationGraph(); final ExtensionMethod extensionMethod = rexsterResourceContext.getExtensionMethod(); Map configurationMap = null; Iterator<String> scriptsToRun = null; try { final ExtensionConfiguration extensionConfiguration = rag != null ? rag.findExtensionConfiguration(EXTENSION_NAMESPACE, EXTENSION_NAME) : null; if (extensionConfiguration != null) { configurationMap = extensionConfiguration.tryGetMapFromConfiguration(); scriptsToRun = getScriptsToRun(requestObject, configurationMap); } } catch (IOException ioe) { return ExtensionResponse.error( ioe, generateErrorJson(extensionMethod.getExtensionApiAsJson())); } if ((script == null || script.isEmpty()) && scriptsToRun == null) { return ExtensionResponse.badRequest( "no scripts provided", generateErrorJson(extensionMethod.getExtensionApiAsJson())); } final Timer.Context context = scriptTimer.time(); try { // result is either the ad-hoc script on the query string or the last "stored procedure" Object result = null; if (scriptsToRun != null) { while (scriptsToRun.hasNext()) { result = engineHolder.getEngine().eval(scriptsToRun.next(), bindings); } } if (isClientScriptAllowed(configurationMap) && script != null && !script.isEmpty()) { result = engineHolder.getEngine().eval(script, bindings); } final JSONArray results = new JSONResultConverter(mode, offsetStart, offsetEnd, returnKeys).convert(result); final HashMap<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(Tokens.SUCCESS, true); resultMap.put(Tokens.RESULTS, results); final JSONObject resultObject = new JSONObject(resultMap); extensionResponse = ExtensionResponse.ok(resultObject); successfulExecutions.inc(); } catch (Exception e) { logger.error(String.format("Gremlin Extension: %s", e.getMessage()), e); extensionResponse = ExtensionResponse.error(e, generateErrorJson(extensionMethod.getExtensionApiAsJson())); failedExecutions.inc(); } finally { context.stop(); } return extensionResponse; }
/** * @param name the metric name * @return the counter */ public static Counter workerCounter(String name) { return METRIC_REGISTRY.counter((getWorkerMetricName(name))); }
/** * This is called by RestExpress during it's bind() operation--right before it starts listening. */ @Override public void bind(RestExpress server) { this.activeRequestsCounter = metrics.counter("active-requests"); this.allExceptionsCounter = metrics.counter("all-exceptions"); this.allTimesTimer = metrics.timer("all-times"); }
private void init() { MetricRegistry registry = metricsService.getMetricRegistry(); hitCounter = registry.counter("ninja.cache.hits"); missCounter = registry.counter("ninja.cache.miss"); }
/** * @param name the metric name * @return the counter */ public static Counter clientCounter(String name) { return METRIC_REGISTRY.counter(getClientMetricName(name)); }
/** A WorkerSource collects a Worker's internal state. */ public class WorkerSource implements Source { private static final String WORKER_SOURCE_NAME = "worker"; private final MetricRegistry mMetricRegistry = new MetricRegistry(); private final Counter mBlocksAccessed = mMetricRegistry.counter(MetricRegistry.name("BlocksAccessed")); private final Counter mBlocksCanceled = mMetricRegistry.counter(MetricRegistry.name("BlocksCanceled")); private final Counter mBlocksDeleted = mMetricRegistry.counter(MetricRegistry.name("BlocksDeleted")); private final Counter mBlocksEvicted = mMetricRegistry.counter(MetricRegistry.name("BlocksEvicted")); private final Counter mBlocksPromoted = mMetricRegistry.counter(MetricRegistry.name("BlocksPromoted")); // metrics from client private final Counter mBlocksReadLocal = mMetricRegistry.counter(MetricRegistry.name("BlocksReadLocal")); private final Counter mBlocksReadRemote = mMetricRegistry.counter(MetricRegistry.name("BlocksReadRemote")); private final Counter mBlocksWrittenLocal = mMetricRegistry.counter(MetricRegistry.name("BlocksWrittenLocal")); private final Counter mBytesReadLocal = mMetricRegistry.counter(MetricRegistry.name("BytesReadLocal")); private final Counter mBytesReadRemote = mMetricRegistry.counter(MetricRegistry.name("BytesReadRemote")); private final Counter mBytesReadUfs = mMetricRegistry.counter(MetricRegistry.name("BytesReadUfs")); private final Counter mBytesWrittenLocal = mMetricRegistry.counter(MetricRegistry.name("BytesWrittenLocal")); private final Counter mBytesWrittenUfs = mMetricRegistry.counter(MetricRegistry.name("BytesWrittenUfs")); @Override public String getName() { return WORKER_SOURCE_NAME; } @Override public MetricRegistry getMetricRegistry() { return mMetricRegistry; } public void incBlocksAccessed() { mBlocksAccessed.inc(); } public void incBlocksCanceled() { mBlocksCanceled.inc(); } public void incBlocksDeleted() { mBlocksDeleted.inc(); } public void incBlocksEvicted() { mBlocksEvicted.inc(); } public void incBlocksPromoted() { mBlocksPromoted.inc(); } public void incBlocksReadLocal(long n) { mBlocksReadLocal.inc(n); } public void incBlocksReadRemote(long n) { mBlocksReadRemote.inc(n); } public void incBlocksWrittenLocal(long n) { mBlocksWrittenLocal.inc(n); } public void incBytesReadLocal(long n) { mBytesReadLocal.inc(n); } public void incBytesReadRemote(long n) { mBytesReadRemote.inc(n); } public void incBytesReadUfs(long n) { mBytesReadUfs.inc(n); } public void incBytesWrittenLocal(long n) { mBytesWrittenLocal.inc(n); } public void incBytesWrittenUfs(long n) { mBytesWrittenUfs.inc(n); } public void registerGauges(final BlockWorker worker) { mMetricRegistry.register( MetricRegistry.name("CapacityTotal"), new Gauge<Long>() { @Override public Long getValue() { return worker.getStoreMeta().getCapacityBytes(); } }); mMetricRegistry.register( MetricRegistry.name("CapacityUsed"), new Gauge<Long>() { @Override public Long getValue() { return worker.getStoreMeta().getUsedBytes(); } }); mMetricRegistry.register( MetricRegistry.name("CapacityFree"), new Gauge<Long>() { @Override public Long getValue() { return worker.getStoreMeta().getCapacityBytes() - worker.getStoreMeta().getUsedBytes(); } }); mMetricRegistry.register( MetricRegistry.name("BlocksCached"), new Gauge<Integer>() { @Override public Integer getValue() { return worker.getStoreMeta().getNumberOfBlocks(); } }); } }