use of com.codahale.metrics.Counter in project indy by Commonjava.
the class IndyZabbixReporter method report.
@SuppressWarnings("rawtypes")
@Override
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
final long clock = System.currentTimeMillis() / 1000;
List<DataObject> dataObjectList = new LinkedList<DataObject>();
for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getValue()), clock);
dataObjectList.add(dataObject);
}
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getCount()), clock);
dataObjectList.add(dataObject);
}
for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
Histogram histogram = entry.getValue();
Snapshot snapshot = histogram.getSnapshot();
addSnapshotDataObject(entry.getKey(), snapshot, clock, dataObjectList);
}
for (Map.Entry<String, Meter> entry : meters.entrySet()) {
Meter meter = entry.getValue();
addMeterDataObject(entry.getKey(), meter, clock, dataObjectList);
}
for (Map.Entry<String, Timer> entry : timers.entrySet()) {
Timer timer = entry.getValue();
addMeterDataObject(entry.getKey(), timer, clock, dataObjectList);
addSnapshotDataObjectWithConvertDuration(entry.getKey(), timer.getSnapshot(), clock, dataObjectList);
}
try {
SenderResult senderResult = indyZabbixSender.send(dataObjectList, clock);
if (!senderResult.success()) {
logger.warn("report metrics to zabbix not success!" + senderResult);
} else if (logger.isDebugEnabled()) {
logger.info("report metrics to zabbix success. " + senderResult);
}
} catch (IOException e) {
logger.error("report metrics to zabbix error! " + e);
e.printStackTrace();
} catch (IndyMetricsException e) {
logger.error("Indy metrics config error " + e);
e.printStackTrace();
} catch (IndyHttpException e) {
logger.error("Indy http client error " + e);
e.printStackTrace();
}
}
use of com.codahale.metrics.Counter in project opennms by OpenNMS.
the class StressCommand method execute.
@Override
public Object execute() throws Exception {
// Create the client
final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
// Create metrics to capture the results
final MetricRegistry metrics = new MetricRegistry();
final Histogram responseTimes = metrics.histogram("response-times");
final Counter successes = metrics.counter("successes");
final Counter failures = metrics.counter("failures");
// Build and issue the requests
System.out.printf("Executing %d requests.\n", count);
final String message = Strings.repeat("*", messageSize);
final CountDownLatch doneSignal = new CountDownLatch(count);
long beforeExec = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
client.execute(buildRequest(message)).whenComplete((r, e) -> {
if (e != null) {
failures.inc();
} else {
responseTimes.update(System.currentTimeMillis() - r.getId());
successes.inc();
}
doneSignal.countDown();
});
}
long afterExec = System.currentTimeMillis();
// Wait for the responses...
System.out.printf("Waiting for responses.\n");
while (true) {
try {
if (doneSignal.await(1, TimeUnit.SECONDS)) {
// Done!
System.out.printf("\nDone!\n");
break;
}
} catch (InterruptedException e) {
System.out.println("\nInterrupted!");
break;
}
System.out.print(".");
System.out.flush();
}
long afterResponse = System.currentTimeMillis();
System.out.println();
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.report();
reporter.close();
System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
return null;
}
use of com.codahale.metrics.Counter in project metrics by dropwizard.
the class CollectdReporterTest method sanitizesMetricName.
@Test
public void sanitizesMetricName() throws Exception {
Counter counter = registry.counter("dash-illegal.slash/illegal");
counter.inc();
reporter.report();
ValueList values = receiver.next();
assertThat(values.getPlugin()).isEqualTo("dash_illegal.slash_illegal");
}
use of com.codahale.metrics.Counter in project hive by apache.
the class TestObjectStore method testDirectSqlErrorMetrics.
@Test
public void testDirectSqlErrorMetrics() throws Exception {
Configuration conf = MetastoreConf.newMetastoreConf();
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.METRICS_ENABLED, true);
Metrics.initialize(conf);
MetastoreConf.setVar(conf, MetastoreConf.ConfVars.HIVE_CODAHALE_METRICS_REPORTER_CLASSES, "org.apache.hadoop.hive.common.metrics.metrics2.JsonFileMetricsReporter, " + "org.apache.hadoop.hive.common.metrics.metrics2.JmxMetricsReporter");
// recall setup so that we get an object store with the metrics initalized
setUp();
Counter directSqlErrors = Metrics.getRegistry().getCounters().get(MetricsConstants.DIRECTSQL_ERRORS);
objectStore.new GetDbHelper("foo", true, true) {
@Override
protected Database getSqlResult(ObjectStore.GetHelper<Database> ctx) throws MetaException {
return null;
}
@Override
protected Database getJdoResult(ObjectStore.GetHelper<Database> ctx) throws MetaException, NoSuchObjectException {
return null;
}
}.run(false);
Assert.assertEquals(0, directSqlErrors.getCount());
objectStore.new GetDbHelper("foo", true, true) {
@Override
protected Database getSqlResult(ObjectStore.GetHelper<Database> ctx) throws MetaException {
throw new RuntimeException();
}
@Override
protected Database getJdoResult(ObjectStore.GetHelper<Database> ctx) throws MetaException, NoSuchObjectException {
return null;
}
}.run(false);
Assert.assertEquals(1, directSqlErrors.getCount());
}
use of com.codahale.metrics.Counter in project riposte by Nike-Inc.
the class EndpointMetricsHandlerDefaultImplTest method setupMetricRegistryMock.
private void setupMetricRegistryMock() {
metricRegistryMock = mock(MetricRegistry.class);
registeredTimers = new HashMap<>();
doAnswer(invocation -> {
Timer originalTimer = (Timer) invocation.callRealMethod();
return spy(originalTimer);
}).when(instance).createAndRegisterRequestTimer(anyString(), any(MetricRegistry.class));
doThrow(new RuntimeException("All timer creation should go through createAndRegisterRequestTimer(), *not* metricRegistry.timer(...).")).when(metricRegistryMock).timer(anyString());
registeredMeterMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Meter meterMock = mock(Meter.class);
registeredMeterMocks.put(name, meterMock);
return meterMock;
}).when(metricRegistryMock).meter(anyString());
registeredCounterMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Counter counterMock = mock(Counter.class);
registeredCounterMocks.put(name, counterMock);
return counterMock;
}).when(metricRegistryMock).counter(anyString());
registeredHistogramMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Histogram histogramMock = mock(Histogram.class);
registeredHistogramMocks.put(name, histogramMock);
return histogramMock;
}).when(metricRegistryMock).histogram(anyString());
registeredGauges = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Metric metric = invocation.getArgumentAt(1, Metric.class);
if (metric instanceof Gauge)
registeredGauges.put(name, (Gauge) metric);
else if (metric instanceof Timer)
registeredTimers.put(name, (Timer) metric);
else
throw new RuntimeException("Expected Gauge or Timer, but received: " + metric.getClass().getName());
return metric;
}).when(metricRegistryMock).register(anyString(), any(Metric.class));
}
Aggregations