Refine search
public LockingRateLimiter(ReplicatedJedisPool cacheClient, String name, int bucketSize, double leakRatePerMinute) { super(cacheClient, name, bucketSize, leakRatePerMinute); MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME); this.meter = metricRegistry.meter(name(getClass(), name, "locked")); }
public static MetricRegistry getOrCreate(String name) { final MetricRegistry existing = REGISTRIES.get(name); if (existing == null) { final MetricRegistry created = new MetricRegistry(); final MetricRegistry raced = add(name, created); if (raced == null) { return created; } return raced; } return existing; }
@AfterClass public static void resetStagemonitor() { Stagemonitor.reset(); SharedMetricRegistries.clear(); }
/** * Creates a new registry and sets it as the default one under the provided name. * * @param name the registry name * @return the default registry * @throws IllegalStateException if the name has already been set */ public synchronized static MetricRegistry setDefault(String name) { final MetricRegistry registry = getOrCreate(name); return setDefault(name, registry); }
@Test public void timedMethodsNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that all the timers haven't been called yet assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(0L)))); }
@Test public void callExceptionMeteredStaticMethodsOnceWithoutThrowing() { Runnable runnableThatDoesNoThrowExceptions = new Runnable() { @Override public void run() { } }; // Call the metered methods and assert they haven't been marked MeteredStaticMethodWithExceptions.illegalArgumentExceptionMeteredStaticMethod(runnableThatDoesNoThrowExceptions); MeteredStaticMethodWithExceptions.exceptionMeteredStaticMethod(runnableThatDoesNoThrowExceptions); assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames()))); assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(0)).getCount(), is(equalTo(METER_COUNTS[0].get()))); assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(1)).getCount(), is(equalTo(METER_COUNTS[1].get()))); }
@Test public void timedMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Make sure that the timer hasn't been called yet assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(0L))); }
@Test public void metricsMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that the metrics haven't been called yet assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName("exception")).getCount(), is(equalTo(0L))); assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName("meter")).getCount(), is(equalTo(0L))); assertThat("Timer count is incorrect", registry.getTimers().get(absoluteMetricName("timer")).getCount(), is(equalTo(0L))); }
@Test public void gaugeCalledWithDefaultValue() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Gauge is not registered correctly", registry.getGauges(), hasKey(GAUGE_NAME)); @SuppressWarnings("unchecked") Gauge<Long> gauge = registry.getGauges().get(GAUGE_NAME); // Make sure that the gauge has the expected value assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(0L))); }
@Test public void meteredMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Meter is not registered correctly", registry.getMeters(), hasKey(METER_NAME)); Meter meter = registry.getMeters().get(METER_NAME); // Make sure that the meter hasn't been called yet assertThat("Meter count is incorrect", meter.getCount(), is(equalTo(0L))); }
private void copyIndexingMetrics3ToCounters(Context context) { for (String name : SharedMetricRegistries.names()) { MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(name); for (Map.Entry<String, com.codahale.metrics.Counter> entry : metricRegistry.getCounters().entrySet()) { addCounting(context, entry.getKey(), entry.getValue(), 1); } for (Map.Entry<String, com.codahale.metrics.Histogram> entry : metricRegistry.getHistograms().entrySet()) { addCounting(context, entry.getKey(), entry.getValue(), 1); } for (Map.Entry<String, com.codahale.metrics.Meter> entry : metricRegistry.getMeters().entrySet()) { addCounting(context, entry.getKey(), entry.getValue(), 1); } for (Map.Entry<String, com.codahale.metrics.Timer> entry : metricRegistry.getTimers().entrySet()) { long nanosPerMilliSec = 1000 * 1000; addCounting(context, entry.getKey(), entry.getValue(), nanosPerMilliSec); } } }
@Test public void metricMethodsWithDefaultNamingConvention() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(metricNames()))); } }
@Test public void testTimer() throws Exception { SharedMetricRegistries.clear(); //<1> MockApplication<File> application = application(InjectorProvider.GUICE, "examples.metrics");//<2> application.init(); MockClient client = application.client(); MockViewBridge view = client.render(); //<3> assertEquals("ok", view.assertStringResponse()); assertEquals(Collections.singleton("examples.metrics"), SharedMetricRegistries.names()); //<4> MetricRegistry registry = SharedMetricRegistries.getOrCreate("examples.metrics"); Timer timer = registry.getTimers().get("juzu.responses"); //<5> assertEquals(1, timer.getCount()); Meter meter = registry.getMeters().get("custom"); //<6> assertNotNull(meter); } // end::testTimer[]
private static long getCount(String name, long fallback) { MetricRegistry registry = SharedMetricRegistries.getOrCreate("mesh"); SortedMap<String, Counter> counters = registry.getCounters(); Counter counter = counters.get(name); if (counter == null) { return fallback; } else { return counter.getCount(); } }
.setMetricRegistry(SharedMetricRegistries.getOrCreate(morphlineFileAndId)) .build(); new File(morphlineFile), morphlineId, morphlineContext, finalChild, override); this.mappingTimer = morphlineContext.getMetricRegistry().timer( MetricRegistry.name("morphline.app", Metrics.ELAPSED_TIME)); this.numRecords = morphlineContext.getMetricRegistry().meter( MetricRegistry.name("morphline.app", Metrics.NUM_RECORDS)); this.numFailedRecords = morphlineContext.getMetricRegistry().meter(
public ElasticSearchIndexingImpl(ElasticSearchAdminImpl esa) { this.esa = esa; MetricRegistry registry = SharedMetricRegistries.getOrCreate(MetricsService.class.getName()); indexTimer = registry.timer(MetricRegistry.name("nuxeo", "elasticsearch", "service", "index")); deleteTimer = registry.timer(MetricRegistry.name("nuxeo", "elasticsearch", "service", "delete")); bulkIndexTimer = registry.timer(MetricRegistry.name("nuxeo", "elasticsearch", "service", "bulkIndex")); this.jsonESDocumentWriter = new JsonESDocumentWriter();// default writer this.useExternalVersion = esa.useExternalVersion(); }
public PushSender(ApnFallbackManager apnFallbackManager, GCMSender gcmSender, APNSender apnSender, WebsocketSender websocketSender, int queueSize) { this.apnFallbackManager = apnFallbackManager; this.gcmSender = gcmSender; this.apnSender = apnSender; this.webSocketSender = websocketSender; this.queueSize = queueSize; this.executor = new BlockingThreadPoolExecutor(50, queueSize); SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME) .register(name(PushSender.class, "send_queue_depth"), (Gauge<Integer>) executor::getSize); }
throws Exception SharedMetricRegistries.add(Constants.METRICS_NAME, environment.metrics()); environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); environment.getObjectMapper().setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); environment.jersey().register(new DeviceLimitExceededExceptionMapper()); environment.metrics().register(name(CpuUsageGauge.class, "cpu"), new CpuUsageGauge()); environment.metrics().register(name(FreeMemoryGauge.class, "free_memory"), new FreeMemoryGauge()); environment.metrics().register(name(NetworkSentGauge.class, "bytes_sent"), new NetworkSentGauge()); environment.metrics().register(name(NetworkReceivedGauge.class, "bytes_received"), new NetworkReceivedGauge());
public InstrumentedConnectionFactory(final ConnectionFactory connectionFactory) { super(connectionFactory, SharedMetricRegistries.getOrCreate("nexus").timer("connection-duration")); this.connectionFactory = connectionFactory; }
/** Constructor */ public CursorResolver() { final MetricRegistry registry = SharedMetricRegistries.getOrCreate("default"); this.siblingCounts = registry.histogram(name(CursorResolver.class, "sibling-counts")); }