本文整理汇总了Java中com.nike.riposte.metrics.codahale.CodahaleMetricsListener类的典型用法代码示例。如果您正苦于以下问题:Java CodahaleMetricsListener类的具体用法?Java CodahaleMetricsListener怎么用?Java CodahaleMetricsListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodahaleMetricsListener类属于com.nike.riposte.metrics.codahale包,在下文中一共展示了CodahaleMetricsListener类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: metricsListener
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
/**
* Note: The CodahaleMetricsEngine is not required in this provider, but is passed here to ensure the engine
* is created and started
*/
@Provides
@Singleton
public CodahaleMetricsListener metricsListener(@Nullable CodahaleMetricsCollector metricsCollector,
@Nullable CodahaleMetricsEngine engine,
@Nullable SignalFxReporterFactory signalFxReporterFactory,
MetricsConfigurationHelper metricsConfigurationHelper) {
if (metricsCollector == null)
return null;
if (signalFxReporterFactory == null) {
// No SignalFx - just use the default.
return new CodahaleMetricsListener(metricsCollector);
}
else {
// SignalFx is being used - make sure we use a CodahaleMetricsListener that sets everything up
// properly for SignalFx.
return metricsConfigurationHelper.generateCodahaleMetricsListenerWithSignalFxSupport(
signalFxReporterFactory, metricsCollector, null, null
);
}
}
示例2: setUp
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
executor = Executors.newCachedThreadPool();
serverConfig = new MetricsTestConfig();
metricsListener = (CodahaleMetricsListener) serverConfig.metricsListener();
endpointMetricsHandler = (EndpointMetricsHandlerDefaultImpl) metricsListener.getEndpointMetricsHandler();
assertTrue(serverConfig.endpointsPort() > 0);
logger.info("Dynamically chose server port {}", serverConfig.endpointsPort());
nonblockingEndpointUrl = "http://127.0.0.1:" + serverConfig.endpointsPort() + NON_BLOCKING_MATCHING_PATH;
server = new Server(serverConfig);
server.startup();
// Perform a "warmup" to get the Server ready to go - the first call is always slower than normal.
List<Future<?>> warmupCalls = new ArrayList<>();
warmupCalls.add(sendServerRequest(nonblockingEndpointUrl));
for (Future f : warmupCalls) {
f.get();
}
}
示例3: MetricsTestConfig
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
public MetricsTestConfig() {
try {
port = ComponentTestUtils.findFreePort();
}
catch (IOException e) {
throw new RuntimeException("Couldn't allocate port", e);
}
CodahaleMetricsEngine metricsEngine = new CodahaleMetricsEngine()
.addReporter(new DefaultSLF4jReporterFactory())
.addReporter(new RiposteGraphiteReporterFactory("test.metrics.stuff", "doesnotexist.nikecloud.com", 2003))
.reportJvmMetrics()
.start();
metricsListener = new CodahaleMetricsListener(metricsEngine.getMetricsCollector());
metricsListener.initEndpointAndServerConfigMetrics(this);
}
示例4: metrics_related_objects_are_null_if_all_reporters_are_disabled
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Test
public void metrics_related_objects_are_null_if_all_reporters_are_disabled() {
// given
configForTesting = generateAppConfigWithMetricsEnabledOrDisabled(false, false, false);
appGuiceModule = new AppGuiceModule(configForTesting);
injector = generateInjector(appGuiceModule, configForTesting);
// when
List<ReporterFactory> reporters = injector.getInstance(Key.get(new TypeLiteral<List<ReporterFactory>>() {}));
CodahaleMetricsCollector cmc = injector.getInstance(CodahaleMetricsCollector.class);
CodahaleMetricsEngine engine = injector.getInstance(CodahaleMetricsEngine.class);
CodahaleMetricsListener listener = injector.getInstance(CodahaleMetricsListener.class);
// then
assertThat(reporters).isNull();
assertThat(cmc).isNull();
assertThat(engine).isNull();
assertThat(listener).isNull();
}
示例5: constructor_does_not_blow_up_if_metricsListener_is_null
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Test
public void constructor_does_not_blow_up_if_metricsListener_is_null() {
// given
AppServerConfig asc = new AppServerConfig(configForTesting) {
@Override
protected List<Module> getAppGuiceModules(Config appConfig) {
return Arrays.asList(
Modules.override(new AppGuiceModule(appConfig)).with(
binder -> binder
.bind(new TypeLiteral<CodahaleMetricsListener>() {})
.toProvider(Providers.of(null))),
new BackstopperRiposteConfigGuiceModule()
);
}
};
// expect
assertThat(asc.metricsListener()).isNull();
}
示例6: GuiceProvidedServerConfigValues
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Inject
public GuiceProvidedServerConfigValues(@Named("endpoints.port") Integer endpointsPort,
@Named("endpoints.sslPort") Integer endpointsSslPort,
@Named("endpoints.useSsl") Boolean endpointsUseSsl,
@Named("netty.bossThreadCount") Integer numBossThreads,
@Named("netty.workerThreadCount") Integer numWorkerThreads,
@Named("netty.maxRequestSizeInBytes") Integer maxRequestSizeInBytes,
@Named("appEndpoints") Set<Endpoint<?>> appEndpoints,
@Named("debugActionsEnabled") Boolean debugActionsEnabled,
@Named("debugChannelLifecycleLoggingEnabled") Boolean debugChannelLifecycleLoggingEnabled,
RiposteErrorHandler riposteErrorHandler,
RiposteUnhandledErrorHandler riposteUnhandledErrorHandler,
RequestValidator validationService,
@Nullable CodahaleMetricsListener metricsListener,
@Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture,
CmsRequestSecurityValidator cmsRequestSecurityValidator,
HystrixRequestAndResponseFilter hystrixRequestAndResponseFilter
) {
super(endpointsPort, endpointsSslPort, endpointsUseSsl, numBossThreads, numWorkerThreads, maxRequestSizeInBytes, appEndpoints,
debugActionsEnabled, debugChannelLifecycleLoggingEnabled);
this.riposteErrorHandler = riposteErrorHandler;
this.riposteUnhandledErrorHandler = riposteUnhandledErrorHandler;
this.validationService = validationService;
this.metricsListener = metricsListener;
this.appInfoFuture = appInfoFuture;
this.cmsRequestSecurityValidator = cmsRequestSecurityValidator;
this.requestAndResponseFilters = Lists.newArrayList(hystrixRequestAndResponseFilter);
}
示例7: GuiceProvidedServerConfigValues
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Inject
public GuiceProvidedServerConfigValues(
@Named("endpoints.port") Integer endpointsPort,
@Named("endpoints.sslPort") Integer endpointsSslPort,
@Named("endpoints.useSsl") Boolean endpointsUseSsl,
@Named("netty.bossThreadCount") Integer numBossThreads,
@Named("netty.workerThreadCount") Integer numWorkerThreads,
@Named("netty.maxRequestSizeInBytes") Integer maxRequestSizeInBytes,
@Named("appEndpoints") Set<Endpoint<?>> appEndpoints,
@Named("debugActionsEnabled") Boolean debugActionsEnabled,
@Named("debugChannelLifecycleLoggingEnabled") Boolean debugChannelLifecycleLoggingEnabled,
RiposteErrorHandler riposteErrorHandler,
RiposteUnhandledErrorHandler riposteUnhandledErrorHandler,
RequestValidator validationService,
@Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture,
@Nullable CodahaleMetricsListener metricsListener,
EurekaServerHook eurekaServerHook,
BasicAuthSecurityValidator basicAuthSecurityValidator
) {
super(
endpointsPort, endpointsSslPort, endpointsUseSsl, numBossThreads, numWorkerThreads, maxRequestSizeInBytes,
appEndpoints, debugActionsEnabled, debugChannelLifecycleLoggingEnabled
);
this.riposteErrorHandler = riposteErrorHandler;
this.riposteUnhandledErrorHandler = riposteUnhandledErrorHandler;
this.validationService = validationService;
this.eurekaServerHook = eurekaServerHook;
this.metricsListener = metricsListener;
this.appInfoFuture = appInfoFuture;
this.basicAuthSecurityValidator = basicAuthSecurityValidator;
}
示例8: metricsListener
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Provides
@Singleton
public CodahaleMetricsListener metricsListener(@Nullable CodahaleMetricsCollector metricsCollector,
@Nullable CodahaleMetricsEngine engine) {
if (metricsCollector == null)
return null;
// We don't actually need the CodahaleMetricsEngine, but we ask for it here to guarantee that it is created and
// started.
return new CodahaleMetricsListener(metricsCollector);
}
示例9: metrics_related_objects_are_non_null_and_related_to_each_other_as_expected
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Test
public void metrics_related_objects_are_non_null_and_related_to_each_other_as_expected() {
// when
List<ReporterFactory> reporters = injector.getInstance(Key.get(new TypeLiteral<List<ReporterFactory>>() {}));
CodahaleMetricsCollector cmc = injector.getInstance(CodahaleMetricsCollector.class);
CodahaleMetricsEngine engine = injector.getInstance(CodahaleMetricsEngine.class);
CodahaleMetricsListener listener = injector.getInstance(CodahaleMetricsListener.class);
// then
// ReporterFactory list is not empty
assertThat(reporters).isNotNull();
assertThat(reporters).isNotEmpty();
// CodahaleMetricsCollector exists
assertThat(cmc).isNotNull();
// CodahaleMetricsEngine uses the same CodahaleMetricsCollector and ReporterFactory list, and has been started
assertThat(engine).isNotNull();
assertThat(Whitebox.getInternalState(engine, "metricsCollector")).isSameAs(cmc);
assertThat((Collection<ReporterFactory>)Whitebox.getInternalState(engine, "reporters"))
.containsOnlyElementsOf(reporters);
assertThat(Whitebox.getInternalState(engine, "started")).isEqualTo(true);
// CodahaleMetricsListener uses the same CodahaleMetricsCollector
assertThat(listener).isNotNull();
assertThat(Whitebox.getInternalState(listener, "metricsCollector")).isSameAs(cmc);
}
示例10: constructor_calls_initEndpointAndServerConfigMetrics_on_metricsListener
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Test
public void constructor_calls_initEndpointAndServerConfigMetrics_on_metricsListener() {
// given
AppServerConfig asc = new AppServerConfig(configForTesting);
// expect
EndpointMetricsHandler emh = ((CodahaleMetricsListener) asc.metricsListener()).getEndpointMetricsHandler();
assertThat(emh).isInstanceOf(EndpointMetricsHandlerDefaultImpl.class);
assertThat(((EndpointMetricsHandlerDefaultImpl)emh).getEndpointRequestsTimers()).isNotEmpty();
}
示例11: generateCodahaleMetricsListenerWithSignalFxSupport
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
public CodahaleMetricsListener generateCodahaleMetricsListenerWithSignalFxSupport(
SignalFxReporterFactory signalFxReporterFactory,
CodahaleMetricsCollector metricsCollector,
MetricDimensionConfigurator<Timer> customRequestTimerDimensionConfigurator,
ExtraRequestLogicHandler extraRequestLogicHandler
) {
MetricRegistry metricRegistry = metricsCollector.getMetricRegistry();
// Use the identity function if customRequestTimerDimensionConfigurator is null.
if (customRequestTimerDimensionConfigurator == null)
customRequestTimerDimensionConfigurator = METRIC_DIMENSION_CONFIGURATOR_IDENTITY;
// Create the SignalFxEndpointMetricsHandler with the customRequestTimerDimensionConfigurator and
// extraRequestLogicHandler specifics.
EndpointMetricsHandler endpointMetricsHandler = new SignalFxEndpointMetricsHandler(
signalFxReporterFactory.getReporter(metricRegistry).getMetricMetadata(),
metricRegistry,
// Use a rolling window reservoir with the same window as the reporting frequency,
// to prevent the dashboards from producing false or misleading data.
new SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder(signalFxReporterFactory.getInterval(),
signalFxReporterFactory.getTimeUnit()),
// Do the default request latency timer dimensions, chained with customRequestTimerDimensionConfigurator
// for any custom logic desired.
DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR
.chainedWith(customRequestTimerDimensionConfigurator)
) {
@Override
public void handleRequest(RequestInfo<?> requestInfo, ResponseInfo<?> responseInfo,
HttpProcessingState httpState,
int responseHttpStatusCode, int responseHttpStatusCodeXXValue,
long requestElapsedTimeMillis) {
// Do the normal endpoint stuff.
super.handleRequest(requestInfo, responseInfo, httpState, responseHttpStatusCode,
responseHttpStatusCodeXXValue,
requestElapsedTimeMillis);
// Do any extra logic (if desired).
if (extraRequestLogicHandler != null) {
extraRequestLogicHandler.handleExtraRequestLogic(
requestInfo, responseInfo, httpState, responseHttpStatusCode, responseHttpStatusCodeXXValue,
requestElapsedTimeMillis
);
}
}
};
return CodahaleMetricsListener
.newBuilder(metricsCollector)
.withEndpointMetricsHandler(endpointMetricsHandler)
// The metric names should be basic with no prefix - SignalFx dimensions do the job normally covered
// by metric name prefixes.
.withServerStatsMetricNamingStrategy(CodahaleMetricsListener.MetricNamingStrategy.defaultNoPrefixImpl())
.withServerConfigMetricNamingStrategy(CodahaleMetricsListener.MetricNamingStrategy.defaultNoPrefixImpl())
// Histograms should use a rolling window reservoir with the same window as the reporting frequency,
// otherwise the dashboards will produce false or misleading data.
.withRequestAndResponseSizeHistogramSupplier(
() -> new Histogram(
new SlidingTimeWindowReservoir(signalFxReporterFactory.getInterval(),
signalFxReporterFactory.getTimeUnit())
)
)
.build();
}
示例12: serverShouldProcessNonblockingEndpointsAsynchronouslyReturns500
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Test
public void serverShouldProcessNonblockingEndpointsAsynchronouslyReturns500() throws Exception {
logger.warn("serverShouldProcessNonblockingEndpointsAsynchronouslyReturns500 start " + new Date().toString());
CodahaleMetricsListener metricsListener = (CodahaleMetricsListener) serverConfig.metricsListener();
long prevFailedCount = metricsListener.getFailedRequests().getCount();
long prevProcessedCount = metricsListener.getProcessedRequests().getCount();
long prevRequestsCount = endpointMetricsHandler.getRequests().getCount();
long prevGetRequestsCount = endpointMetricsHandler.getGetRequests().getCount();
long prevResponsesCount = endpointMetricsHandler.getResponses()[5 - 1].getCount();
long prevRequestCount = ((Timer) endpointMetricsHandler.getEndpointRequestsTimers()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))
.getCount();
long prevResponseCount = ((Meter[]) endpointMetricsHandler.getEndpointResponsesMeters()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))[5
- 1]
.getCount();
doServerAsyncProcessingVerificationTestForUrl(nonblockingEndpointUrl + "?error=500", true);
long countFailed = metricsListener.getFailedRequests().getCount();
long processedCount = metricsListener.getProcessedRequests().getCount();
long requestsCount = endpointMetricsHandler.getRequests().getCount();
long requestSize = metricsListener.getRequestSizes().getSnapshot().getMax();
long responseSize = metricsListener.getResponseSizes().getSnapshot().getMax();
long getRequestsCount = endpointMetricsHandler.getGetRequests().getCount();
long responsesCount = endpointMetricsHandler.getResponses()[5 - 1].getCount();
long requestCount = ((Timer) endpointMetricsHandler.getEndpointRequestsTimers()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))
.getCount();
long responseCount = ((Meter[]) endpointMetricsHandler.getEndpointResponsesMeters()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))[5 - 1]
.getCount();
long inflight = metricsListener.getInflightRequests().getCount();
long responseWriteFailed = metricsListener.getResponseWriteFailed().getCount();
long postRequests = endpointMetricsHandler.getPostRequests().getCount();
long putRequests = endpointMetricsHandler.getPutRequests().getCount();
long deleteRequests = endpointMetricsHandler.getDeleteRequests().getCount();
long otherRequests = endpointMetricsHandler.getOtherRequests().getCount();
assertTrue(countFailed > prevFailedCount);// + NUMBER_OF_REQUESTS);
assertTrue(processedCount > prevProcessedCount);// + NUMBER_OF_REQUESTS);
assertTrue(requestsCount > prevRequestsCount);// + NUMBER_OF_REQUESTS);
assertTrue(requestSize == 0);
assertTrue(responseSize < 200);
assertTrue(getRequestsCount > prevGetRequestsCount);// + NUMBER_OF_REQUESTS);
assertTrue(responsesCount > prevResponsesCount);// + NUMBER_OF_REQUESTS);
assertTrue(requestCount > prevRequestCount);// + NUMBER_OF_REQUESTS);
assertTrue(responseCount > prevResponseCount);// + NUMBER_OF_REQUESTS);
assertEquals(inflight, 0);
assertEquals(responseWriteFailed, 0);
assertEquals(postRequests, 0);
assertEquals(putRequests, 0);
assertEquals(deleteRequests, 0);
assertEquals(otherRequests, 0);
logger.warn("serverShouldProcessNonblockingEndpointsAsynchronouslyReturns500 end " + new Date().toString());
}
示例13: serverShouldProcessNonblockingEndpointsAsynchronously
import com.nike.riposte.metrics.codahale.CodahaleMetricsListener; //导入依赖的package包/类
@Test
public void serverShouldProcessNonblockingEndpointsAsynchronously() throws Exception {
logger.warn("serverShouldProcessNonblockingEndpointsAsynchronously start " + new Date().toString());
CodahaleMetricsListener metricsListener = (CodahaleMetricsListener) serverConfig.metricsListener();
long prevFailedCount = metricsListener.getFailedRequests().getCount();
long prevProcessedCount = metricsListener.getProcessedRequests().getCount();
long prevRequestsCount = endpointMetricsHandler.getRequests().getCount();
long prevGetRequestsCount = endpointMetricsHandler.getGetRequests().getCount();
long prevResponsesCount = endpointMetricsHandler.getResponses()[4 - 1].getCount();
long prevRequestCount = ((Timer) endpointMetricsHandler.getEndpointRequestsTimers()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))
.getCount();
long prevResponseCount = ((Meter[]) endpointMetricsHandler.getEndpointResponsesMeters()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))[4
- 1]
.getCount();
doServerAsyncProcessingVerificationTestForUrl(nonblockingEndpointUrl, true);
long countFailed = metricsListener.getFailedRequests().getCount();
long processedCount = metricsListener.getProcessedRequests().getCount();
long requestsCount = endpointMetricsHandler.getRequests().getCount();
long requestSize = metricsListener.getRequestSizes().getSnapshot().getMax();
long responseSize = metricsListener.getResponseSizes().getSnapshot().getMax();
long getRequestsCount = endpointMetricsHandler.getGetRequests().getCount();
long responsesCount = endpointMetricsHandler.getResponses()[4 - 1].getCount();
long requestCount = ((Timer) endpointMetricsHandler.getEndpointRequestsTimers()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))
.getCount();
long responseCount = ((Meter[]) endpointMetricsHandler.getEndpointResponsesMeters()
.get(NON_BLOCKING_ENDPOINT_METRICS_LISTENER_MAP_KEY))[4 - 1]
.getCount();
long inflight = metricsListener.getInflightRequests().getCount();
long responseWriteFailed = metricsListener.getResponseWriteFailed().getCount();
long postRequests = endpointMetricsHandler.getPostRequests().getCount();
long putRequests = endpointMetricsHandler.getPutRequests().getCount();
long deleteRequests = endpointMetricsHandler.getDeleteRequests().getCount();
long otherRequests = endpointMetricsHandler.getOtherRequests().getCount();
assertEquals(countFailed, prevFailedCount);
assertTrue(processedCount > prevProcessedCount);// + NUMBER_OF_REQUESTS);
assertTrue(requestsCount > prevRequestsCount);// + NUMBER_OF_REQUESTS);
assertTrue(requestSize == 0);
assertTrue(responseSize < 200);
assertTrue(getRequestsCount > prevGetRequestsCount);// + NUMBER_OF_REQUESTS);
assertEquals(responsesCount, prevResponsesCount);
assertTrue(requestCount > prevRequestCount);// + NUMBER_OF_REQUESTS);
assertEquals(responseCount, prevResponseCount);
assertEquals(inflight, 0);
assertEquals(responseWriteFailed, 0);
assertEquals(postRequests, 0);
assertEquals(putRequests, 0);
assertEquals(deleteRequests, 0);
assertEquals(otherRequests, 0);
logger.warn("serverShouldProcessNonblockingEndpointsAsynchronously end " + new Date().toString());
}