hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1303536 - in /hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest: ./ metrics/
Date Wed, 21 Mar 2012 19:48:11 GMT
Author: larsh
Date: Wed Mar 21 19:48:11 2012
New Revision: 1303536

URL: http://svn.apache.org/viewvc?rev=1303536&view=rev
Log:
HBASE-5433 [REST] Add metrics to keep track of success/failure count (Mubarak Seyed)

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterVersionResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetrics.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java Wed Mar 21
19:48:11 2012
@@ -91,8 +91,10 @@ public class MultiRowResource extends Re
 
         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);
     }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java Wed Mar 21
19:48:11 2012
@@ -102,10 +102,13 @@ public class RegionsResource extends Res
       }
       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);
     }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java Wed Mar 21 19:48:11
2012
@@ -82,8 +82,10 @@ public class RootResource extends Resour
     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);
     }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java Wed Mar 21 19:48:11
2012
@@ -107,8 +107,10 @@ public class RowResource extends Resourc
         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 Resourc
       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 Resourc
       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 Resourc
       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 Resourc
     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 {

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java Wed
Mar 21 19:48:11 2012
@@ -88,7 +88,12 @@ public class ScannerInstanceResource ext
       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 ext
     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 ext
         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 ext
     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();
   }
 }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java Wed Mar 21
19:48:11 2012
@@ -65,10 +65,13 @@ public class ScannerResource extends Res
     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 Res
       }
       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 Res
       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;
   }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java Wed Mar 21
19:48:11 2012
@@ -98,10 +98,13 @@ public class SchemaResource extends Reso
       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 Reso
         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 Reso
       } 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 Reso
         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 Reso
         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);
     }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java
Wed Mar 21 19:48:11 2012
@@ -95,8 +95,10 @@ public class StorageClusterStatusResourc
       }
       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);
     }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterVersionResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterVersionResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterVersionResource.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterVersionResource.java
Wed Mar 21 19:48:11 2012
@@ -71,8 +71,10 @@ public class StorageClusterVersionResour
       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);
     }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java Wed Mar 21
19:48:11 2012
@@ -81,6 +81,7 @@ public class VersionResource extends Res
     servlet.getMetrics().incrementRequests(1);
     ResponseBuilder response = Response.ok(new VersionModel(context));
     response.cacheControl(cacheControl);
+    servlet.getMetrics().incrementSucessfulGetRequests(1);
     return response.build();
   }
 

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetrics.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetrics.java?rev=1303536&r1=1303535&r2=1303536&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetrics.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetrics.java Wed Mar
21 19:48:11 2012
@@ -37,6 +37,19 @@ public class RESTMetrics implements Upda
   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 Upda
   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();
   }
@@ -85,5 +104,89 @@ public class RESTMetrics implements Upda
   public void incrementRequests(final int 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);
+  }
+  
 }



Mime
View raw message