本文整理汇总了Java中com.codahale.metrics.SlidingTimeWindowReservoir类的典型用法代码示例。如果您正苦于以下问题:Java SlidingTimeWindowReservoir类的具体用法?Java SlidingTimeWindowReservoir怎么用?Java SlidingTimeWindowReservoir使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SlidingTimeWindowReservoir类属于com.codahale.metrics包,在下文中一共展示了SlidingTimeWindowReservoir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RollingWindowTimerBuilder
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@DataProvider(value = {
"42 | DAYS",
"123 | SECONDS",
"999 | MILLISECONDS",
"3 | HOURS"
}, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values(
long amount, TimeUnit timeUnit
) {
// given
RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
// when
Timer timer = rwtb.newMetric();
// then
Histogram histogram = (Histogram) getInternalState(timer, "histogram");
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
示例2: RollingWindowHistogramBuilder
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@DataProvider(value = {
"42 | DAYS",
"123 | SECONDS",
"999 | MILLISECONDS",
"3 | HOURS"
}, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values(
long amount, TimeUnit timeUnit
) {
// given
RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
// when
Histogram histogram = rwhb.newMetric();
// then
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
示例3: testCreateTimer
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@Test
public void testCreateTimer() throws ReflectiveOperationException {
final SlidingTimeWindowTimingStrategy strategy = new SlidingTimeWindowTimingStrategy();
final Timer timer = strategy.createTimer(new MapConfig());
SlidingTimeWindowReservoir reservoir = reservoir(timer);
assertNotNull(reservoir);
assertEquals("timeWindow", strategy.name());
}
示例4: addStatElement
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
/** add a metric (time) to a specific resource - for example
* type = PostgresClient.get
* time = single operation time in nanoseconds
*/
public static void addStatElement(String type, long time){
if(!registeredStatRequesters.contains(type)){
METRICS.register(type, new Histogram(new SlidingTimeWindowReservoir(60,
TimeUnit.SECONDS)));
registeredStatRequesters.add(type);
}
METRICS.histogram(type).update(time/1000000);
}
示例5: getReservoir
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
/**
* Get reservoir implementation based on the reservoir type
*
* @return The {@link Reservoir} implementation
*/
private Reservoir getReservoir() {
// The Reservoir implementation is selected using a switch statement.
// The ReservoirType enum is a part of YAML configuration
// and foreign imports are not supported by Carbon Configuration Maven Plugin.
// Therefore, the Reservoir class cannot be imported and the Reservoir
// creation logic cannot be written inside ReservoirType enum.
switch (reservoirType) {
case EXPONENTIALLY_DECAYING:
return new ExponentiallyDecayingReservoir();
case UNIFORM:
return new UniformReservoir(reservoirParametersConfig.getSize());
case SLIDING_WINDOW:
return new SlidingWindowReservoir(reservoirParametersConfig.getSize());
case SLIDING_TIME_WINDOW:
return new SlidingTimeWindowReservoir(reservoirParametersConfig.getWindow(),
reservoirParametersConfig.getWindowUnit());
case HDR_HISTOGRAM:
Recorder recorder = new Recorder(reservoirParametersConfig.getNumberOfSignificantValueDigits());
if (reservoirParametersConfig.isResetOnSnapshot()) {
return new HdrHistogramResetOnSnapshotReservoir(recorder);
} else {
return new HdrHistogramReservoir(recorder);
}
default:
throw new RuntimeException("Invalid Reservoir Type");
}
}
示例6: createTimer
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
public static Timer createTimer(MetricRegistry metrics, String name, final String pipelineName, final String pipelineRev) {
return create(
metrics,
new Timer(new SlidingTimeWindowReservoir(60, TimeUnit.SECONDS)),
metricName(name, TIMER_SUFFIX),
pipelineName,
pipelineRev
);
}
示例7: ReducerStateBackupComponent
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
/**
* Constructor.
* @param metricRegistry Metrics registry used to log various metrics.
* @param flakeId Flake's id to which this component belongs.
* @param componentName Unique name of the component.
* @param ctx Shared zmq context.
* @param fieldName The fieldName used by the reducer for grouping.
*/
public ReducerStateBackupComponent(final MetricRegistry metricRegistry,
final String flakeId,
final String componentName,
final ZMQ.Context ctx,
final String fieldName) {
super(metricRegistry, flakeId, componentName, ctx);
this.messageBackup = new HashMap<>();
this.tupleSerializer = SerializerFactory.getSerializer();
this.keyFieldName = fieldName;
this.stateBackup = new HashMap<>();
this.recoveringFlakes = new HashMap<>();
Gauge<Integer> lenMonitor = metricRegistry.register("BACkUPLEN",
new Gauge<Integer>() {
@Override
public Integer getValue() {
Integer sum = 0;
for (String key : messageBackup.keySet()) {
sum += messageBackup.get(key).size();
}
return sum;
}
});
Histogram qhist
= getMetricRegistry() .register(
MetricRegistry.name(QueueLenMonitor.class, "bkp.len.histo"),
new Histogram(new SlidingTimeWindowReservoir(2,
TimeUnit.SECONDS)));
BackupLenMonitor mon = new BackupLenMonitor(lenMonitor, qhist);
mon.start();
//metricRegistry.meter(MetricRegistry.name
// (ReducerStateBackupComponent.class,
// "msg-q-len"));
}
示例8: testJsonMetricsTypes
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@Test
public void testJsonMetricsTypes() {
assertMetricType("counter", new Counter());
assertMetricType("histogram", new Histogram(new SlidingTimeWindowReservoir(10, TimeUnit.SECONDS)));
assertMetricType("gauge", (Gauge<String>) () -> "whatever");
assertMetricType("meter", new Meter());
assertMetricType("timer", new Timer());
}
示例9: InnerHistogram
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
InnerHistogram(MetricContext context, String name, ContextAwareHistogram contextAwareHistogram, long windowSize, TimeUnit unit) {
super(new SlidingTimeWindowReservoir(windowSize, unit));
this.name = name;
Optional<MetricContext> parentContext = context.getParent();
if (parentContext.isPresent()) {
this.parentHistogram = Optional.fromNullable(parentContext.get().contextAwareHistogram(name, windowSize, unit));
} else {
this.parentHistogram = Optional.absent();
}
this.contextAwareHistogram = new WeakReference<>(contextAwareHistogram);
}
示例10: InnerTimer
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
InnerTimer(MetricContext context, String name, ContextAwareTimer contextAwareTimer, long windowSize, TimeUnit unit) {
super(new SlidingTimeWindowReservoir(windowSize, unit));
this.name = name;
Optional<MetricContext> parentContext = context.getParent();
if (parentContext.isPresent()) {
this.parentTimer = Optional.fromNullable(parentContext.get().contextAwareTimer(name, windowSize, unit));
} else {
this.parentTimer = Optional.absent();
}
this.timer = new WeakReference<>(contextAwareTimer);
}
示例11: markUsage
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@Override
public void markUsage(Table table)
{
Histogram window = usageMap.get(table);
if (window == null) {
final SlidingTimeWindowReservoir reservoir = new SlidingTimeWindowReservoir(
usageTrackTime.getQuantity(),
usageTrackTime.getUnit());
window = new Histogram(reservoir);
usageMap.put(table, window);
}
window.update(1);
}
示例12: generateCodahaleMetricsListenerWithSignalFxSupport
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的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();
}
示例13: newMetric
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@Override
public Timer newMetric() {
return new Timer(new SlidingTimeWindowReservoir(amount, timeUnit));
}
示例14: createTimer
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
@Override
public Timer createTimer(Config config) {
return new Timer(new SlidingTimeWindowReservoir(
config.longValue(WINDOW_PROP).orElse(DEFAULT_WINDOW),
config.enumValue(WINDOW_UNIT_PROP, TimeUnit.class).orElse(DEFAULT_WINDOW_UNIT)));
}
示例15: TryThisOut
import com.codahale.metrics.SlidingTimeWindowReservoir; //导入依赖的package包/类
public TryThisOut() {
registry = new MetricRegistry();
gauge = new Gauge<Integer>() {
@Override
public Integer getValue() {
return gaugeValue;
}
};
registry.register("gauge", gauge);
counter = new Counter();
registry.register("counter", counter);
histogram = new Histogram(new SlidingTimeWindowReservoir(10, TimeUnit.SECONDS));
registry.register("histogram", histogram);
meter = new Meter();
registry.register("meter", meter);
timer = new Timer();
registry.register("timer", timer);
String instanceId = EC2MetadataUtils.getInstanceId();
// try out the default constructor.
AmazonCloudWatchClient client = new AmazonCloudWatchClient();
reporter = new CloudWatchReporter.Builder(registry, client)
.dimension("instanceId", instanceId)
.namespace("some-namespace")
.build();
reporter.start(5, TimeUnit.SECONDS);
executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(new Runnable() {
private int counterVal;
private Random random = new Random();
@Override
public void run() {
gaugeValue = counterVal++;
counter.inc();
Timer.Context context = timer.time();
meter.mark();
histogram.update((int)(random.nextGaussian() * 10));
context.stop();
}
}, 0, 1, TimeUnit.SECONDS);
}