use of org.apache.hadoop.hbase.metrics.Timer in project hbase by apache.
the class TestMetricRegistryImpl method testGetMetrics.
@Test
public void testGetMetrics() {
CounterImpl counter = new CounterImpl();
registry.register("mycounter", counter);
Gauge gauge = registry.register("mygauge", () -> 42L);
Timer timer = registry.timer("mytimer");
Map<String, Metric> metrics = registry.getMetrics();
assertEquals(3, metrics.size());
assertEquals(counter, metrics.get("mycounter"));
assertEquals(gauge, metrics.get("mygauge"));
assertEquals(timer, metrics.get("mytimer"));
}
use of org.apache.hadoop.hbase.metrics.Timer in project hbase by apache.
the class TestMetricRegistryImpl method testTimer.
@Test
public void testTimer() {
Timer timer = registry.timer("mytimer");
assertNotNull(timer);
timer.updateNanos(100);
}
use of org.apache.hadoop.hbase.metrics.Timer in project hbase by apache.
the class TestCoprocessorMetrics method testRegionObserverEndpoint.
@Test
public void testRegionObserverEndpoint() throws IOException, ServiceException {
final TableName tableName = TableName.valueOf(name.getMethodName());
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionEndpoint.class.getName()));
try (Table table = connection.getTable(tableName)) {
List<Mutation> mutations = Lists.newArrayList(new Put(foo), new Put(bar));
MutateRowsRequest.Builder mrmBuilder = MutateRowsRequest.newBuilder();
for (Mutation mutation : mutations) {
mrmBuilder.addMutationRequest(ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.PUT, mutation));
}
CoprocessorRpcChannel channel = table.coprocessorService(bar);
MultiRowMutationService.BlockingInterface service = MultiRowMutationService.newBlockingStub(channel);
MutateRowsRequest mrm = mrmBuilder.build();
service.mutateRows(null, mrm);
}
}
// Find out the MetricRegistry used by the CP using the global registries
MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(CustomRegionEndpoint.class.getName());
Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
assertTrue(registry.isPresent());
Optional<Metric> metric = registry.get().get("EndpointExecution");
assertTrue(metric.isPresent());
Timer endpointExecutions = (Timer) metric.get();
assertEquals(1, endpointExecutions.getHistogram().getCount());
}
use of org.apache.hadoop.hbase.metrics.Timer in project hbase by apache.
the class TestCoprocessorMetrics method testMasterObserver.
@Test
public void testMasterObserver() throws IOException {
// Find out the MetricRegistry used by the CP using the global registries
MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForMasterCoprocessor(CustomMasterObserver.class.getName());
Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
assertTrue(registry.isPresent());
Optional<Metric> metric = registry.get().get("CreateTable");
assertTrue(metric.isPresent());
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
Timer createTableTimer = (Timer) metric.get();
long prevCount = createTableTimer.getHistogram().getCount();
LOG.info("Creating table");
admin.createTable(new HTableDescriptor(TableName.valueOf(name.getMethodName())).addFamily(new HColumnDescriptor("foo")));
assertEquals(1, createTableTimer.getHistogram().getCount() - prevCount);
}
}
use of org.apache.hadoop.hbase.metrics.Timer in project hbase by apache.
the class HBaseMetrics2HadoopMetricsAdapter method snapshotAllMetrics.
/**
* Iterates over the MetricRegistry and adds them to the {@code builder}.
*
* @param builder A record builder
*/
public void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsRecordBuilder builder) {
Map<String, Metric> metrics = metricRegistry.getMetrics();
for (Map.Entry<String, Metric> e : metrics.entrySet()) {
// Always capitalize the name
String name = StringUtils.capitalize(e.getKey());
Metric metric = e.getValue();
if (metric instanceof Gauge) {
addGauge(name, (Gauge<?>) metric, builder);
} else if (metric instanceof Counter) {
addCounter(name, (Counter) metric, builder);
} else if (metric instanceof Histogram) {
addHistogram(name, (Histogram) metric, builder);
} else if (metric instanceof Meter) {
addMeter(name, (Meter) metric, builder);
} else if (metric instanceof Timer) {
addTimer(name, (Timer) metric, builder);
} else {
LOG.info("Ignoring unknown Metric class " + metric.getClass().getName());
}
}
}
Aggregations