HBASE-5433 [REST] Add metrics to keep track of success/failure count (Mubarak Seyed)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1303536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2012-03-21 19:48:11 +00:00
parent 865b14133b
commit 4ba5a9d29e
11 changed files with 165 additions and 4 deletions

View File

@ -91,8 +91,10 @@ public class MultiRowResource extends ResourceBase {
model.addRow(rowModel);
}
servlet.getMetrics().incrementSucessfulGetRequests(1);
return Response.ok(model).build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}

View File

@ -102,10 +102,13 @@ public class RegionsResource extends ResourceBase {
}
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (TableNotFoundException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(Response.Status.NOT_FOUND);
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}

View File

@ -82,8 +82,10 @@ public class RootResource extends ResourceBase {
try {
ResponseBuilder response = Response.ok(getTableList());
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}

View File

@ -107,8 +107,10 @@ public class RowResource extends ResourceBase {
value = generator.next();
} while (value != null);
model.addRow(rowModel);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return Response.ok(model).build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}
@ -135,8 +137,10 @@ public class RowResource extends ResourceBase {
KeyValue value = generator.next();
ResponseBuilder response = Response.ok(value.getValue());
response.header("X-Timestamp", value.getTimestamp());
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}
@ -188,8 +192,10 @@ public class RowResource extends ResourceBase {
table.put(puts);
table.flushCommits();
ResponseBuilder response = Response.ok();
servlet.getMetrics().incrementSucessfulPutRequests(1);
return response.build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedPutRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
} finally {
@ -248,8 +254,10 @@ public class RowResource extends ResourceBase {
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + put.toString());
}
servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.ok().build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedPutRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
} finally {
@ -340,10 +348,12 @@ public class RowResource extends ResourceBase {
try {
table = pool.getTable(tableResource.getName());
table.delete(delete);
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
if (LOG.isDebugEnabled()) {
LOG.debug("DELETE " + delete.toString());
}
} catch (IOException e) {
servlet.getMetrics().incrementFailedDeleteRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
} finally {

View File

@ -88,7 +88,12 @@ public class ScannerInstanceResource extends ResourceBase {
try {
value = generator.next();
} catch (IllegalStateException e) {
ScannerResource.delete(id);
if (ScannerResource.delete(id)) {
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
} else {
servlet.getMetrics().incrementFailedDeleteRequests(1);
}
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(Response.Status.GONE);
}
if (value == null) {
@ -124,6 +129,7 @@ public class ScannerInstanceResource extends ResourceBase {
model.addRow(rowModel);
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
}
@ -148,9 +154,15 @@ public class ScannerInstanceResource extends ResourceBase {
Base64.encodeBytes(
KeyValue.makeColumn(value.getFamily(), value.getQualifier())));
response.header("X-Timestamp", value.getTimestamp());
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (IllegalStateException e) {
ScannerResource.delete(id);
if (ScannerResource.delete(id)) {
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
} else {
servlet.getMetrics().incrementFailedDeleteRequests(1);
}
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(Response.Status.GONE);
}
}
@ -164,7 +176,11 @@ public class ScannerInstanceResource extends ResourceBase {
if (servlet.isReadOnly()) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
ScannerResource.delete(id);
if (ScannerResource.delete(id)) {
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
} else {
servlet.getMetrics().incrementFailedDeleteRequests(1);
}
return Response.ok().build();
}
}

View File

@ -65,10 +65,13 @@ public class ScannerResource extends ResourceBase {
this.tableResource = tableResource;
}
static void delete(final String id) {
static boolean delete(final String id) {
ScannerInstanceResource instance = scanners.remove(id);
if (instance != null) {
instance.generator.close();
return true;
} else {
return false;
}
}
@ -96,16 +99,20 @@ public class ScannerResource extends ResourceBase {
}
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
URI uri = builder.path(id).build();
servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.created(uri).build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedPutRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
} catch (RuntimeException e) {
servlet.getMetrics().incrementFailedPutRequests(1);
if (e.getCause() instanceof TableNotFoundException) {
throw new WebApplicationException(e, Response.Status.NOT_FOUND);
}
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
} catch (Exception e) {
servlet.getMetrics().incrementFailedPutRequests(1);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
}
@ -135,7 +142,10 @@ public class ScannerResource extends ResourceBase {
final @PathParam("scanner") String id) {
ScannerInstanceResource instance = scanners.get(id);
if (instance == null) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(Response.Status.NOT_FOUND);
} else {
servlet.getMetrics().incrementSucessfulGetRequests(1);
}
return instance;
}

View File

@ -98,10 +98,13 @@ public class SchemaResource extends ResourceBase {
ResponseBuilder response =
Response.ok(new TableSchemaModel(getTableSchema()));
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (TableNotFoundException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(Response.Status.NOT_FOUND);
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}
@ -128,8 +131,10 @@ public class SchemaResource extends ResourceBase {
admin.disableTable(name);
admin.modifyTable(name, htd);
admin.enableTable(name);
servlet.getMetrics().incrementSucessfulPutRequests(1);
} else try {
admin.createTable(htd);
servlet.getMetrics().incrementSucessfulPutRequests(1);
} catch (TableExistsException e) {
// race, someone else created a table with the same name
throw new WebApplicationException(e, Response.Status.NOT_MODIFIED);
@ -167,6 +172,7 @@ public class SchemaResource extends ResourceBase {
} finally {
admin.enableTable(tableResource.getName());
}
servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.ok().build();
} catch (IOException e) {
throw new WebApplicationException(e,
@ -185,6 +191,7 @@ public class SchemaResource extends ResourceBase {
return update(name, model, uriInfo, admin);
}
} catch (IOException e) {
servlet.getMetrics().incrementFailedPutRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}
@ -231,10 +238,13 @@ public class SchemaResource extends ResourceBase {
throw new IOException("could not disable table");
}
admin.deleteTable(tableResource.getName());
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
return Response.ok().build();
} catch (TableNotFoundException e) {
servlet.getMetrics().incrementFailedDeleteRequests(1);
throw new WebApplicationException(Response.Status.NOT_FOUND);
} catch (IOException e) {
servlet.getMetrics().incrementFailedDeleteRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}

View File

@ -95,8 +95,10 @@ public class StorageClusterStatusResource extends ResourceBase {
}
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}

View File

@ -71,8 +71,10 @@ public class StorageClusterVersionResource extends ResourceBase {
model.setVersion(admin.getClusterStatus().getHBaseVersion());
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
}

View File

@ -81,6 +81,7 @@ public class VersionResource extends ResourceBase {
servlet.getMetrics().incrementRequests(1);
ResponseBuilder response = Response.ok(new VersionModel(context));
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
}

View File

@ -37,6 +37,19 @@ public class RESTMetrics implements Updater {
private final RESTStatistics restStatistics;
private MetricsRate requests = new MetricsRate("requests", registry);
private MetricsRate sucessfulGetCount =
new MetricsRate("sucessful.get.count", registry);
private MetricsRate sucessfulPutCount =
new MetricsRate("sucessful.put.count", registry);
private MetricsRate sucessfulDeleteCount =
new MetricsRate("sucessful.delete.count", registry);
private MetricsRate failedGetCount =
new MetricsRate("failed.get.count", registry);
private MetricsRate failedPutCount =
new MetricsRate("failed.put.count", registry);
private MetricsRate failedDeleteCount =
new MetricsRate("failed.delete.count", registry);
public RESTMetrics() {
MetricsContext context = MetricsUtil.getContext("rest");
@ -64,6 +77,12 @@ public class RESTMetrics implements Updater {
public void doUpdates(MetricsContext unused) {
synchronized (this) {
requests.pushMetric(metricsRecord);
sucessfulGetCount.pushMetric(metricsRecord);
sucessfulPutCount.pushMetric(metricsRecord);
sucessfulDeleteCount.pushMetric(metricsRecord);
failedGetCount.pushMetric(metricsRecord);
failedPutCount.pushMetric(metricsRecord);
failedDeleteCount.pushMetric(metricsRecord);
}
this.metricsRecord.update();
}
@ -86,4 +105,88 @@ public class RESTMetrics implements Updater {
requests.inc(inc);
}
/**
* @return Count of sucessfulGetCount.
*/
public float getSucessfulGetCount() {
return sucessfulGetCount.getPreviousIntervalValue();
}
/**
* @param inc How much to add to sucessfulGetCount.
*/
public void incrementSucessfulGetRequests(final int inc) {
sucessfulGetCount.inc(inc);
}
/**
* @return Count of sucessfulGetCount.
*/
public float getSucessfulPutCount() {
return sucessfulPutCount.getPreviousIntervalValue();
}
/**
* @param inc How much to add to sucessfulPutCount.
*/
public void incrementSucessfulPutRequests(final int inc) {
sucessfulPutCount.inc(inc);
}
/**
* @return Count of failedPutCount.
*/
public float getFailedPutCount() {
return failedPutCount.getPreviousIntervalValue();
}
/**
* @param inc How much to add to failedPutCount.
*/
public void incrementFailedPutRequests(final int inc) {
failedPutCount.inc(inc);
}
/**
* @return Count of failedGetCount.
*/
public float getFailedGetCount() {
return failedGetCount.getPreviousIntervalValue();
}
/**
* @param inc How much to add to failedGetCount.
*/
public void incrementFailedGetRequests(final int inc) {
failedGetCount.inc(inc);
}
/**
* @return Count of sucessfulGetCount.
*/
public float getSucessfulDeleteCount() {
return sucessfulDeleteCount.getPreviousIntervalValue();
}
/**
* @param inc How much to add to sucessfulDeleteCount.
*/
public void incrementSucessfulDeleteRequests(final int inc) {
sucessfulDeleteCount.inc(inc);
}
/**
* @return Count of failedDeleteCount.
*/
public float getFailedDeleteCount() {
return failedDeleteCount.getPreviousIntervalValue();
}
/**
* @param inc How much to add to failedDeleteCount.
*/
public void incrementFailedDeleteRequests(final int inc) {
failedDeleteCount.inc(inc);
}
}