本文整理匯總了Java中com.codahale.metrics.Counter.inc方法的典型用法代碼示例。如果您正苦於以下問題:Java Counter.inc方法的具體用法?Java Counter.inc怎麽用?Java Counter.inc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.codahale.metrics.Counter
的用法示例。
在下文中一共展示了Counter.inc方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testMetricEncode
import com.codahale.metrics.Counter; //導入方法依賴的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: invoke
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
EnableMetricCounter annotation = methodInvocation.getThis().getClass().getAnnotation(EnableMetricCounter.class);
String name = StringUtils.isBlank(annotation.value())
? methodInvocation.getThis().getClass().getName() + "." + methodInvocation.getMethod().getName()
: annotation.value();
Counter counter = Jboot.me().getMetric().counter(name);
try {
counter.inc();
return methodInvocation.proceed();
} finally {
counter.dec();
}
}
示例3: reportCounter
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
/**
* A counter is just a gauge for an AtomicLong instance. You can increment or decrement its
* value. We want a more efficient way of measuring the pending job in a queue
*/
private static void reportCounter() {
// Create or fetch (if it is already created) the metric.
final Counter counter = registry.counter(APP_PREFIX.tagged("what", "job-count"));
// Somewhere in your code where you are adding new jobs to the queue you increment the
// counter as well
counter.inc();
// Oh look! Another job!
counter.inc();
// Somewhere in your code the job is going to be removed from the queue you decrement the
// counter
counter.dec();
// That's it! The rest will be automatically done inside semantic metrics library. The
// reported measurements will be kept in the registry.
// Every time the reporter wants to report, the current value of the counter will be read
// and
// a datapoint will be created and reported.
}
示例4: shouldReportCounter
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Test
public void shouldReportCounter() throws IOException {
String metricName = randomName();
HawkularReporter reporter = HawkularReporter.builder(registry, defaultTenant)
.basicAuth(USERNAME, PASSWORD)
.build();
final Counter counter = registry.counter(metricName);
counter.inc(5);
reporter.report();
HawkularHttpResponse response = defaultClient.readMetric("counters", metricName);
assertThat(response.getResponseCode()).isEqualTo(200);
JSONArray result = new JSONArray(response.getContent());
assertThat(result).extracting(intExtractor).containsExactly(5);
counter.inc(8);
reporter.report();
response = defaultClient.readMetric("counters", metricName);
assertThat(response.getResponseCode()).isEqualTo(200);
result = new JSONArray(response.getContent());
assertThat(result).extracting(intExtractor).containsExactly(13, 5);
}
示例5: doProcess
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Override
protected void doProcess(Exchange exchange, MetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
Message in = exchange.getIn();
Counter counter = registry.counter(metricsName);
Long increment = endpoint.getIncrement();
Long decrement = endpoint.getDecrement();
Long finalIncrement = getLongHeader(in, HEADER_COUNTER_INCREMENT, increment);
Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
if (finalIncrement != null) {
counter.inc(finalIncrement);
} else if (finalDecrement != null) {
counter.dec(finalDecrement);
} else {
counter.inc();
}
}
示例6: shouldReportSimpleCounterWithoutTag
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Test
public void shouldReportSimpleCounterWithoutTag() {
HawkularReporter reporter = HawkularReporter.builder(registry, "unit-test").useHttpClient(uri -> client).build();
final Counter counter = registry.counter("my.counter");
counter.inc();
reporter.report();
assertThat(client.getMetricsRestCalls()).hasSize(1);
JSONObject metrics = new JSONObject(client.getMetricsRestCalls().get(0));
assertThat(metrics.keySet()).containsExactly("counters");
JSONArray json = metrics.getJSONArray("counters");
assertThat(json).extracting(idFromRoot).containsExactly("my.counter");
assertThat(json).extracting(valueFromRoot).containsExactly(1);
assertThat(client.getTagsRestCalls()).isEmpty();
}
示例7: testReporter
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Test
public void testReporter() throws Exception {
UUID uuid = UUID.randomUUID();
String metricName = "ApptuitReporterTest.testReporter." + uuid.toString();
int expectedCount=2;
AtomicBoolean foundMetric = new AtomicBoolean(false);
AtomicInteger lastSeenCount = new AtomicInteger(-1);
PutListener listener = dataPoints -> {
dataPoints.forEach(dataPoint -> {
if (!metricName.equals(dataPoint.getMetric()))
return;
int i = dataPoint.getValue().intValue();
lastSeenCount.set(i);
if (i != 2)
return;
foundMetric.set(true);
});
};
putClient.addPutListener(listener);
Counter counter = registry.counter(metricName);
counter.inc();
counter.inc();
await().atMost(period*3, TimeUnit.SECONDS).untilTrue(foundMetric);
putClient.removePutListener(listener);
assertEquals(expectedCount, lastSeenCount.intValue());
}
示例8: testCounterResumeFromLast
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Test
public void testCounterResumeFromLast() throws Exception {
String name = UUID.randomUUID().toString();
Counter c = registry.counter(name);
c.inc(2);
report(name, c);
// simulate restart
reporter.close();
registry.remove(name);
c = registry.counter(name);
c.inc(1);
Thread.sleep(1000);
report(name, c);
File f = new File(basepath, name + ".rrd");
assertTrue(f.exists());
RrdDb db = new RrdDb(f.getAbsolutePath());
assertEquals(3.0, db.getLastDatasourceValue("data"), 0.0);
db.close();
c.inc(1);
Thread.sleep(1000);
report(name, c);
db = new RrdDb(f.getAbsolutePath());
assertEquals(4.0, db.getLastDatasourceValue("data"), 0.0);
db.close();
}
示例9: testSimpleCounter
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Test
public void testSimpleCounter() throws Exception {
String name = UUID.randomUUID().toString();
Counter c = registry.counter(name);
c.inc();
report(name, c);
File f = new File(basepath, name + ".rrd");
assertTrue(f.exists());
RrdDb db = new RrdDb(f.getAbsolutePath());
assertEquals(1.0, db.getLastDatasourceValue("data"), 0.0);
db.close();
}
示例10: testGetAllMetrics
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
/**
* Tests GetAllMetrics method.
*/
@Test
public void testGetAllMetrics() {
Counter onosCounter = new Counter();
onosCounter.inc();
Meter onosMeter = new Meter();
onosMeter.mark();
Timer onosTimer = new Timer();
onosTimer.update(1, TimeUnit.MILLISECONDS);
ImmutableMap<String, Metric> metrics =
new ImmutableMap.Builder<String, Metric>()
.put("onosCounter", onosCounter)
.put("onosMeter", onosMeter)
.put("onosTimer", onosTimer)
.build();
expect(mockMetricsService.getMetrics())
.andReturn(metrics)
.anyTimes();
replay(mockMetricsService);
WebTarget wt = target();
String response = wt.path("metrics").request().get(String.class);
assertThat(response, containsString("{\"metrics\":["));
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
JsonArray jsonMetrics = result.get("metrics").asArray();
assertThat(jsonMetrics, notNullValue());
assertThat(jsonMetrics.size(), is(3));
assertTrue(matchesMetric(metrics.get("onosCounter")).matchesSafely(jsonMetrics.get(0).asObject()));
assertTrue(matchesMetric(metrics.get("onosMeter")).matchesSafely(jsonMetrics.get(1).asObject()));
assertTrue(matchesMetric(metrics.get("onosTimer")).matchesSafely(jsonMetrics.get(2).asObject()));
}
示例11: buildErrorMessageForLogs
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Override
public String buildErrorMessageForLogs(StringBuilder sb, RequestInfoForLogging request,
Collection<ApiError> contributingErrors, Integer httpStatusCode,
Throwable cause,
List<Pair<String, String>> extraDetailsForLogging) {
try {
// Do the normal logging thing.
return super.buildErrorMessageForLogs(
sb, request, contributingErrors, httpStatusCode, cause, extraDetailsForLogging
);
}
finally {
// Update SignalFx metrics around API Errors.
String contributingErrorsString = contributingErrors == null
? "[NONE]"
: concatenateErrorCollection(contributingErrors);
Counter apiErrorsCounterMetric = sfxMetricMetadata
.forBuilder(MetricBuilder.COUNTERS)
.withMetricName(API_ERRORS_METRIC_NAME)
.withDimension(RESPONSE_CODE_DIM_KEY, String.valueOf(httpStatusCode))
.withDimension(CONTRIBUTING_ERRORS_DIM_KEY, contributingErrorsString)
.withDimension(EXCEPTION_CLASS_DIM_KEY, cause.getClass().getName())
.createOrGet(metricRegistry);
apiErrorsCounterMetric.inc();
}
}
示例12: MetricsResourceTest
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
public MetricsResourceTest() {
final Module metricsModule = binder -> {
final MetricRegistry registry = new MetricRegistry();
final Counter counter = registry.counter("test.counter");
counter.inc(42L);
binder.bind(MetricRegistry.class).toInstance(registry);
};
GuiceInjectorHolder.createInjector(ImmutableList.of(new MetricsPrometheusReporterModule(), metricsModule));
}
示例13: count
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
protected Object count(Executable executable, Counted annotation, Invocation invocation) throws Throwable {
Counter counter = getCounter(executable);
try {
counter.inc();
return invocation.proceed();
} finally {
if (!annotation.monotonic()) {
counter.dec();
}
}
}
示例14: incrementInternal
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
private void incrementInternal(String name, long value) {
if (name.startsWith("meter")) {
Meter meter = this.registry.meter(name);
meter.mark(value);
}
else {
name = wrapCounterName(name);
Counter counter = this.registry.counter(name);
counter.inc(value);
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:DropwizardMetricServices.java
示例15: CounterResource
import com.codahale.metrics.Counter; //導入方法依賴的package包/類
@Inject
public CounterResource(
Counter unnamedCounter,
@Metric(name = "com.metric") Counter metricCounter,
@Metric(name = "com.absoluteMetric", absolute = true) Counter absoluteMetricCounter
) {
unnamedCounter.inc();
metricCounter.inc(2);
absoluteMetricCounter.inc(3);
}