Skip to content

Commit

Permalink
Clean up MetricsServlet a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Nov 16, 2011
1 parent 769e179 commit c1e19fd
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public MetricsServlet(MetricsRegistry metricsRegistry, HealthCheckRegistry healt
public void init(ServletConfig config) throws ServletException {
super.init(config);

ServletContext context = config.getServletContext();
final ServletContext context = config.getServletContext();

this.contextPath = context.getContextPath();
this.metricsRegistry = putAttrIfAbsent(context, ATTR_NAME_METRICS_REGISTRY, this.metricsRegistry);
Expand Down Expand Up @@ -170,6 +170,7 @@ private void handleHome(String path, HttpServletResponse resp) throws IOExceptio
writer.close();
}

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void handleHealthCheck(HttpServletResponse resp) throws IOException {
boolean allHealthy = true;
final Map<String, Result> results = healthCheckRegistry.runHealthChecks();
Expand Down Expand Up @@ -202,9 +203,10 @@ private void handleHealthCheck(HttpServletResponse resp) throws IOException {
writer.format("! %s: ERROR\n! %s\n", entry.getKey(), result.getMessage());
}

if (result.getError() != null) {
final Throwable error = result.getError();
if (error != null) {
writer.println();
result.getError().printStackTrace(writer);
error.printStackTrace(writer);
writer.println();
}
}
Expand Down Expand Up @@ -241,7 +243,7 @@ private void handleMetrics(String classPrefix, boolean showFullSamples, boolean
json.writeStartObject();
{
if (showJvmMetrics && ("jvm".equals(classPrefix) || classPrefix == null)) {
writeVmMetrics(json, showFullSamples);
writeVmMetrics(json);
}

writeRegularMetrics(json, classPrefix, showFullSamples);
Expand Down Expand Up @@ -334,7 +336,7 @@ private Object evaluateGauge(GaugeMetric<?> gauge) {
}
}

private void writeVmMetrics(JsonGenerator json, boolean showFullSamples) throws IOException {
private void writeVmMetrics(JsonGenerator json) throws IOException {
json.writeFieldName("jvm");
json.writeStartObject();
{
Expand Down

0 comments on commit c1e19fd

Please sign in to comment.