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); model.addRow(rowModel);
} }
servlet.getMetrics().incrementSucessfulGetRequests(1);
return Response.ok(model).build(); return Response.ok(model).build();
} catch (IOException e) { } catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
throw new WebApplicationException(e, throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE); Response.Status.SERVICE_UNAVAILABLE);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,6 +37,19 @@ public class RESTMetrics implements Updater {
private final RESTStatistics restStatistics; private final RESTStatistics restStatistics;
private MetricsRate requests = new MetricsRate("requests", registry); 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() { public RESTMetrics() {
MetricsContext context = MetricsUtil.getContext("rest"); MetricsContext context = MetricsUtil.getContext("rest");
@ -64,6 +77,12 @@ public class RESTMetrics implements Updater {
public void doUpdates(MetricsContext unused) { public void doUpdates(MetricsContext unused) {
synchronized (this) { synchronized (this) {
requests.pushMetric(metricsRecord); requests.pushMetric(metricsRecord);
sucessfulGetCount.pushMetric(metricsRecord);
sucessfulPutCount.pushMetric(metricsRecord);
sucessfulDeleteCount.pushMetric(metricsRecord);
failedGetCount.pushMetric(metricsRecord);
failedPutCount.pushMetric(metricsRecord);
failedDeleteCount.pushMetric(metricsRecord);
} }
this.metricsRecord.update(); this.metricsRecord.update();
} }
@ -85,5 +104,89 @@ public class RESTMetrics implements Updater {
public void incrementRequests(final int inc) { public void incrementRequests(final int inc) {
requests.inc(inc); 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);
}
} }