本文整理汇总了Java中com.codahale.metrics.Meter类的典型用法代码示例。如果您正苦于以下问题:Java Meter类的具体用法?Java Meter怎么用?Java Meter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Meter类属于com.codahale.metrics包,在下文中一共展示了Meter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMetricEncode
import com.codahale.metrics.Meter; //导入依赖的package包/类
/**
* Tests encoding of a Metric object.
*/
@Test
public void testMetricEncode() {
Counter counter = new Counter();
Meter meter = new Meter();
Timer timer = new Timer();
counter.inc();
meter.mark();
timer.update(1, TimeUnit.MILLISECONDS);
ObjectNode counterJson = metricCodec.encode(counter, context);
assertThat(counterJson.get("counter"), matchesMetric(counter));
ObjectNode meterJson = metricCodec.encode(meter, context);
assertThat(meterJson.get("meter"), matchesMetric(meter));
ObjectNode timerJson = metricCodec.encode(timer, context);
assertThat(timerJson.get("timer"), matchesMetric(timer));
}
示例2: AnomalyDetector
import com.codahale.metrics.Meter; //导入依赖的package包/类
/**
* Package private constructor for unit test.
*/
AnomalyDetector(LinkedBlockingDeque<Anomaly> anomalies,
long anomalyDetectionIntervalMs,
KafkaCruiseControl kafkaCruiseControl,
AnomalyNotifier anomalyNotifier,
GoalViolationDetector goalViolationDetector,
BrokerFailureDetector brokerFailureDetector,
ScheduledExecutorService detectorScheduler) {
_anomalies = anomalies;
_anomalyDetectionIntervalMs = anomalyDetectionIntervalMs;
_anomalyNotifier = anomalyNotifier;
_goalViolationDetector = goalViolationDetector;
_brokerFailureDetector = brokerFailureDetector;
_kafkaCruiseControl = kafkaCruiseControl;
_detectorScheduler = detectorScheduler;
_shutdown = false;
_brokerFailureRate = new Meter();
_goalViolationRate = new Meter();
}
示例3: TrainingFetcher
import com.codahale.metrics.Meter; //导入依赖的package包/类
TrainingFetcher(MetricSampler metricSampler,
Cluster cluster,
SampleStore sampleStore,
Set<TopicPartition> assignedPartitions,
long startTimeMs,
long endTimeMs,
Timer fetcherTimer,
Meter fetcherFailureRate) {
_cluster = cluster;
_sampleStore = sampleStore;
_metricSampler = metricSampler;
_startTimeMs = startTimeMs;
_endTimeMs = endTimeMs;
_assignedPartitions = assignedPartitions;
_fetcherTimer = fetcherTimer;
_fetcherFailureRate = fetcherFailureRate;
}
示例4: SamplingFetcher
import com.codahale.metrics.Meter; //导入依赖的package包/类
SamplingFetcher(MetricSampler metricSampler,
Cluster cluster,
MetricSampleAggregator metricSampleAggregator,
SampleStore sampleStore,
Set<TopicPartition> assignedPartitions,
long startTimeMs,
long endTimeMs,
boolean leaderValidation,
boolean useLinearRegressionModel,
Timer fetchTimer,
Meter fetchFailureRate) {
_metricSampler = metricSampler;
_cluster = cluster;
_metricSampleAggregator = metricSampleAggregator;
_sampleStore = sampleStore;
_assignedPartitions = assignedPartitions;
_startTimeMs = startTimeMs;
_endTimeMs = endTimeMs;
_leaderValidation = leaderValidation;
_useLinearRegressionModel = useLinearRegressionModel;
_fetchTimer = fetchTimer;
_fetchFailureRate = fetchFailureRate;
}
示例5: testMetersRetrievedAndMarkIsDelegated
import com.codahale.metrics.Meter; //导入依赖的package包/类
@Test
public void testMetersRetrievedAndMarkIsDelegated() throws Exception {
// ARRANGE
SystemStatus systemStatus = mock(SystemStatus.class);
Meter meter = mock(Meter.class);
doReturn(meter).when(systemStatus).meter(anyString(), any());
AbstractMeteredLoadProcessorImpl processor = spy(new AbstractMeteredLoadProcessorImpl(0, null, 0, null));
processor.setSystemStatus(systemStatus);
// ACT
processor.succeeded();
processor.failed();
processor.authenticationFailure();
// ASSERT
verify(processor, times(3)).meterName(); // FindBugs: RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT - IGNORE
verify(systemStatus, times(3)).meter(anyString(), any());
verify(meter, times(3)).mark();
}
示例6: testMetersRetrievedAndMarkIsDelegated
import com.codahale.metrics.Meter; //导入依赖的package包/类
@Test
public void testMetersRetrievedAndMarkIsDelegated() throws Exception {
// ARRANGE
SystemStatus systemStatus = mock(SystemStatus.class);
Meter meter = mock(Meter.class);
doReturn(meter).when(systemStatus).meter(anyString(), any());
processor.setSystemStatus(systemStatus);
// ACT
processor.succeeded();
processor.failed();
processor.noData();
processor.authenticationFailure();
// ASSERT
verify(processor, times(4)).meterName(); // FindBugs: RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT - IGNORE
verify(systemStatus, times(4)).meter(anyString(), any());
verify(meter, times(4)).mark();
}
示例7: exception
import com.codahale.metrics.Meter; //导入依赖的package包/类
@Test(expected = FeignException.class)
public void exception() {
stubFor(post(anyUrl()).willReturn(aResponse().withStatus(400)));
MyClientWithAnnotationOnMethodLevel target = Feign.builder().invocationHandlerFactory(
new FeignOutboundMetricsDecorator(new InvocationHandlerFactory.Default(), metricRegistry))
.target(MyClientWithAnnotationOnMethodLevel.class,
String.format("http://localhost:%d", wireMockRule.port()));
try {
target.myMethod();
} finally {
assertMetrics();
Set<Map.Entry<String, Meter>> entries = metricRegistry.getMeters().entrySet();
entries.forEach(entry -> {
if (entry.getKey().endsWith(ExceptionMetered.DEFAULT_NAME_SUFFIX)) {
assertEquals(String.format("wrong number of invocations in metric %s", entry.getKey()), 1,
entry.getValue().getCount());
}
});
}
}
示例8: assertMetrics
import com.codahale.metrics.Meter; //导入依赖的package包/类
private void assertMetrics() {
Timer timer = metricRegistry.getTimers().values().iterator().next();
assertEquals("wrong number of invocations in metric.", 1, timer.getCount());
assertTrue("wrong value of mean in metric.", timer.getMeanRate() > 0);
assertEquals("wrong number of meter metrics.", 2, metricRegistry.getMeters().values().size());
Set<Map.Entry<String, Meter>> entries = metricRegistry.getMeters().entrySet();
entries.forEach(entry -> {
if (entry.getKey().endsWith("Metered")) {
assertEquals(String.format("wrong number of invocations in metric %s", entry.getKey()), 1,
entry.getValue().getCount());
}
});
}
示例9: report
import com.codahale.metrics.Meter; //导入依赖的package包/类
@Override
public void report(final SortedMap<String, Gauge> gauges,
final SortedMap<String, Counter> counters,
final SortedMap<String, Histogram> histograms,
final SortedMap<String, Meter> meters,
final SortedMap<String, Timer> timers) {
final long timestamp = clock.instant().toEpochMilli();
final ImmutableList<InfluxDbMeasurement> influxDbMeasurements = ImmutableList.<InfluxDbMeasurement>builder()
.addAll(transformer.fromGauges(gauges, timestamp))
.addAll(transformer.fromCounters(counters, timestamp))
.addAll(transformer.fromHistograms(histograms, timestamp))
.addAll(transformer.fromMeters(meters, timestamp))
.addAll(transformer.fromTimers(timers, timestamp))
.build();
sender.send(influxDbMeasurements);
}
示例10: fromMeter
import com.codahale.metrics.Meter; //导入依赖的package包/类
/**
* Build an {@link InfluxDbMeasurement} from a meter.
*/
@VisibleForTesting InfluxDbMeasurement fromMeter(final String metricName, final Meter mt, final long timestamp) {
final DropwizardMeasurement measurement = parser.parse(metricName);
final Map<String, String> tags = new HashMap<>(baseTags);
tags.putAll(measurement.tags());
return new InfluxDbMeasurement.Builder(measurement.name(), timestamp)
.putTags(tags)
.putField("count", mt.getCount())
.putField("one-minute", convertRate(mt.getOneMinuteRate()))
.putField("five-minute", convertRate(mt.getFiveMinuteRate()))
.putField("fifteen-minute", convertRate(mt.getFifteenMinuteRate()))
.putField("mean-minute", convertRate(mt.getMeanRate()))
.build();
}
示例11: serialize
import com.codahale.metrics.Meter; //导入依赖的package包/类
@Override
public void serialize(JsonMeter jsonMeter,
JsonGenerator json,
SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField("name", jsonMeter.name());
json.writeObjectField(timestampFieldname, jsonMeter.timestampAsDate());
Meter meter = jsonMeter.value();
json.writeNumberField("count", meter.getCount());
json.writeNumberField("m1_rate", meter.getOneMinuteRate() * rateFactor);
json.writeNumberField("m5_rate", meter.getFiveMinuteRate() * rateFactor);
json.writeNumberField("m15_rate", meter.getFifteenMinuteRate() * rateFactor);
json.writeNumberField("mean_rate", meter.getMeanRate() * rateFactor);
json.writeStringField("units", rateUnit);
addOneOpsMetadata(json);
json.writeEndObject();
}
示例12: interceptCall
import com.codahale.metrics.Meter; //导入依赖的package包/类
/**
* Intercept all GRPC calls
* @param serverCall
* @param metadata
* @param serverCallHandler
* @param <ReqT>
* @param <RespT>
* @return
*/
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
Timer.Context timer = metricRegistry.timer(metricName(M_REQ_TIME, serverCall.getMethodDescriptor().getFullMethodName().replace("/", "."))).time();
Histogram histogram = metricRegistry.histogram(metricName(M_RESPONSE_SIZE, serverCall.getMethodDescriptor().getFullMethodName().replace("/", ".")));
SimpleForwardingServerCall<ReqT, RespT> nextCall = new SimpleForwardingServerCall<ReqT, RespT>(serverCall) {
@Override
public void close(Status status, Metadata trailers) {
Meter errorMeter = metricRegistry.meter(metricName(ERROR_METRIC, getMethodDescriptor().getFullMethodName().replace("/", ".")));
if (!status.isOk()) {
errorMeter.mark();
log.error("An error occured with {}", serverCall.getMethodDescriptor());
}
timer.stop();
super.close(status, trailers);
}
@Override
public void sendMessage(RespT message) {
super.sendMessage(message);
if (message instanceof MessageLite) {
histogram.update(((MessageLite) message).getSerializedSize());
log.info("Message sent size = {}", ((MessageLite) message).getSerializedSize());
}
}
};
return serverCallHandler.startCall(nextCall, metadata);
}
示例13: OpenFlowControlMessageAggregator
import com.codahale.metrics.Meter; //导入依赖的package包/类
/**
* Generates an OpenFlow message aggregator instance.
* The instance is for aggregating a specific OpenFlow message
* type of an OpenFlow switch.
*
* @param metricsService metrics service reference object
* @param providerService control message provider service reference object
* @param deviceId device identification
*/
public OpenFlowControlMessageAggregator(MetricsService metricsService,
ControlMessageProviderService providerService,
DeviceId deviceId) {
MetricsComponent mc = metricsService.registerComponent(deviceId.toString());
OF_TYPE_SET.forEach(type -> {
MetricsFeature metricsFeature = mc.registerFeature(type.toString());
Meter rateMeter = metricsService.createMeter(mc, metricsFeature, RATE_NAME);
Meter countMeter = metricsService.createMeter(mc, metricsFeature, COUNT_NAME);
rateMeterMap.put(type, rateMeter);
countMeterMap.put(type, countMeter);
});
this.deviceId = deviceId;
this.providerService = providerService;
metricsService.notifyReporters();
}
示例14: printEventMetric
import com.codahale.metrics.Meter; //导入依赖的package包/类
/**
* Prints an Event Metric.
*
* @param operationStr the string with the intent operation to print
* @param eventMetric the Event Metric to print
*/
private void printEventMetric(String operationStr,
EventMetric eventMetric) {
Gauge<Long> gauge = eventMetric.lastEventTimestampGauge();
Meter meter = eventMetric.eventRateMeter();
TimeUnit rateUnit = TimeUnit.SECONDS;
double rateFactor = rateUnit.toSeconds(1);
// Print the Gauge
print(FORMAT_GAUGE, operationStr, gauge.getValue());
// Print the Meter
print(FORMAT_METER, operationStr, meter.getCount(),
meter.getMeanRate() * rateFactor,
meter.getOneMinuteRate() * rateFactor,
meter.getFiveMinuteRate() * rateFactor,
meter.getFifteenMinuteRate() * rateFactor);
}
示例15: defaultCleanupExecutor
import com.codahale.metrics.Meter; //导入依赖的package包/类
private static ExecutorService defaultCleanupExecutor(String metricsGroup, LifeCycleRegistry lifeCycle, MetricRegistry metricRegistry) {
final Meter meter = metricRegistry.meter(MetricRegistry.name(metricsGroup, "AstyanaxEventReaderDAO", "discarded_slab_cleanup"));
String nameFormat = "Events Slab Reader Cleanup-" + metricsGroup.substring(metricsGroup.lastIndexOf('.') + 1) + "-%d";
ExecutorService executor = new ThreadPoolExecutor(
NUM_CLEANUP_THREADS, NUM_CLEANUP_THREADS,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(MAX_CLEANUP_QUEUE_LENGTH),
new ThreadFactoryBuilder().setNameFormat(nameFormat).build(),
new ThreadPoolExecutor.DiscardPolicy() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
meter.mark();
}
});
lifeCycle.manage(new ExecutorServiceManager(executor, Duration.seconds(5), nameFormat));
return executor;
}