@Test public void testListMetrics() { MetricManager.getIMetricManager().clear(); MetricManager.getCounter("product", MetricName.build("middleware.product.provider")); MetricManager.getMeter("test", MetricName.build("shared.carts.my_cart").level(MetricLevel.CRITICAL)).mark(); MetricManager.getMeter("test", MetricName.build("shared.carts.my_cart") .level(MetricLevel.CRITICAL).tagged("source", "taobao")).mark(); GenericType<Map<String, Object>> genericType = new GenericType<Map<String, Object>>(){}; Map<String, Object> result = target("metrics/list").request() .accept(MediaType.APPLICATION_JSON_TYPE).get(genericType); Assert.assertEquals("success should be true", true, result.get("success")); Assert.assertTrue("data should be a map", result.get("data") instanceof Map); ObjectMapper mapper = new ObjectMapper(); Map<String, Set<MetricObject>> data = mapper.convertValue(result.get("data"), new TypeReference<Map<String, Set<MetricObject>>>(){}); Assert.assertTrue(data.get("product").contains(MetricObject.named("middleware.product.provider.count") .withType(MetricObject.MetricType.COUNTER).withLevel(MetricLevel.NORMAL).build())); Assert.assertEquals(".count/.m1/.m5/.m15/.bucket_count/qps * 2 = 12", 12, data.get("test").size()); Assert.assertTrue("shared.carts.my_cart.m1 should be CRITICAL level", data.get("test").contains(MetricObject.named("shared.carts.my_cart.m1") .withLevel(MetricLevel.CRITICAL).withType(MetricObject.MetricType.GAUGE).build())); Map<String, String> tags = new HashMap<String, String>(); tags.put("source", "taobao"); Assert.assertTrue(data.get("test").contains(MetricObject.named("shared.carts.my_cart.m1").withTags(tags) .withLevel(MetricLevel.CRITICAL).withType(MetricObject.MetricType.GAUGE).build())); }
@Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) public Response listMetrics() { if (manager.isEnabled()) { Map<String, Set<MetricObject>> metrics = new LinkedHashMap<String, Set<MetricObject>>(); for (String groupName : manager.listMetricGroups()) { MetricRegistry registry = manager.getMetricRegistryByGroup(groupName); Set<MetricObject> metricsPerRegistry = new LinkedHashSet<MetricObject>(); metricsPerRegistry.addAll(buildMetricRegistry(registry)); metrics.put(groupName, metricsPerRegistry); } try { String data = JSON.toJSONString(buildResultPojo(metrics, true, ""), filter); return Response.ok(data).build(); } catch (Exception e) { return buildResult(null, false, e.toString()); } } else { return buildResult(null, false, "Metrics has been disabled explicitly!"); } }
MetricsResource { @Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) public Response listMetrics() { if (manager.isEnabled()) { Map<String, Set<MetricObject>> metrics = new LinkedHashMap<String, Set<MetricObject>>(); for (String groupName : manager.listMetricGroups()) { MetricRegistry registry = manager.getMetricRegistryByGroup(groupName); Set<MetricObject> metricsPerRegistry = new LinkedHashSet<MetricObject>(); metricsPerRegistry.addAll(buildMetricRegistry(registry)); metrics.put(groupName, metricsPerRegistry); } try { String data = JSON.toJSONString(buildResultPojo(metrics, true, ""), filter); return Response.ok(data).build(); } catch (Exception e) { return buildResult(null, false, e.toString()); } } else { return buildResult(null, false, "Metrics has been disabled explicitly!"); } } }
MetricsResource { @Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) public Response listMetrics() { if (manager.isEnabled()) { Map<String, Set<MetricObject>> metrics = new LinkedHashMap<String, Set<MetricObject>>(); for (String groupName : manager.listMetricGroups()) { MetricRegistry registry = manager.getMetricRegistryByGroup(groupName); Set<MetricObject> metricsPerRegistry = new LinkedHashSet<MetricObject>(); metricsPerRegistry.addAll(buildMetricRegistry(registry)); metrics.put(groupName, metricsPerRegistry); } try { String data = JSON.toJSONString(buildResultPojo(metrics, true, ""), filter); return Response.ok(data).build(); } catch (Exception e) { return buildResult(null, false, e.toString()); } } else { return buildResult(null, false, "Metrics has been disabled explicitly!"); } }  }
MetricsResource { @Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) public Response listMetrics() { if (manager.isEnabled()) { Map<String, Set<MetricObject>> metrics = new LinkedHashMap<String, Set<MetricObject>>(); for (String groupName : manager.listMetricGroups()) { MetricRegistry registry = manager.getMetricRegistryByGroup(groupName); Set<MetricObject> metricsPerRegistry = new LinkedHashSet<MetricObject>(); metricsPerRegistry.addAll(buildMetricRegistry(registry)); metrics.put(groupName, metricsPerRegistry); } try { String data = JSON.toJSONString(buildResultPojo(metrics, true, ""), filter); return Response.ok(data).build(); } catch (Exception e) { return buildResult(null, false, e.toString()); } } else { return buildResult(null, false, "Metrics has been disabled explicitly!"); } }  @Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) Response listMetrics(); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) Response getMetrics(); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}") Response getMetrics(@DefaultValue("all") @PathParam("group") String group); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/level/{level}") Response getMetricByLevel(final @PathParam("group") String group,
                                     final @PathParam("level") String level,
                                     final @QueryParam("above") boolean above); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") Response getMetric(final @PathParam("group") String group,
                              final @PathParam("metric") String metricName,
                              final @QueryParam("tagKey") List<String> tagKeys,
                              final @QueryParam("tagValue") List<String> tagValues); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/specific") Response getMetric(final @QueryParam("metric") Set<String> metricNames, @QueryParam("zeroIgnore") boolean zeroIgnore); @POST @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/specific") Response getMetricsByPost(MultivaluedMap<String, String> params, @QueryParam("zeroIgnore") boolean zeroIgnore); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/search") Response searchMetrics(String metricsSearch, @HeaderParam("REMOTE_ADDR") String remoteAddr,
            @HeaderParam("X-Forwarded-For") String xForwardedFor, @Context HttpServletRequest httpServletRequest); }
MetricsResource { @Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) public Response listMetrics() { if (manager.isEnabled()) { Map<String, Set<MetricObject>> metrics = new LinkedHashMap<String, Set<MetricObject>>(); for (String groupName : manager.listMetricGroups()) { MetricRegistry registry = manager.getMetricRegistryByGroup(groupName); Set<MetricObject> metricsPerRegistry = new LinkedHashSet<MetricObject>(); metricsPerRegistry.addAll(buildMetricRegistry(registry)); metrics.put(groupName, metricsPerRegistry); } try { String data = JSON.toJSONString(buildResultPojo(metrics, true, ""), filter); return Response.ok(data).build(); } catch (Exception e) { return buildResult(null, false, e.toString()); } } else { return buildResult(null, false, "Metrics has been disabled explicitly!"); } }  @Path("/list") @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) Response listMetrics(); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) Response getMetrics(); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}") Response getMetrics(@DefaultValue("all") @PathParam("group") String group); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/level/{level}") Response getMetricByLevel(final @PathParam("group") String group,
                                     final @PathParam("level") String level,
                                     final @QueryParam("above") boolean above); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") Response getMetric(final @PathParam("group") String group,
                              final @PathParam("metric") String metricName,
                              final @QueryParam("tagKey") List<String> tagKeys,
                              final @QueryParam("tagValue") List<String> tagValues); @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/specific") Response getMetric(final @QueryParam("metric") Set<String> metricNames, @QueryParam("zeroIgnore") boolean zeroIgnore); @POST @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/specific") Response getMetricsByPost(MultivaluedMap<String, String> params, @QueryParam("zeroIgnore") boolean zeroIgnore); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/search") Response searchMetrics(String metricsSearch, @HeaderParam("REMOTE_ADDR") String remoteAddr,
            @HeaderParam("X-Forwarded-For") String xForwardedFor, @Context HttpServletRequest httpServletRequest);  }