@SuppressWarnings("unchecked") @Test public void testFastCompassCustomizedMetric() { FastCompass c1 = MetricManager.getFastCompass("zzz", MetricName.build("test.abc.fc")); c1.record(10, "pushSuccess"); c1.record(20, "fail"); MetricsResource resource = new MetricsResource(); Set<String> metrics = new HashSet<String>(); metrics.add("test.abc.fc.pushSuccess_bucket_count"); Response response = resource.getMetric(metrics, false); Object dataList = ((Map<String, Object>)response.getEntity()).get("data"); Assert.assertEquals(1, ((List<Object>)dataList).size()); }
@GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") public Response getMetric(final @PathParam("group") String group, final @PathParam("metric") String metricName, final @QueryParam("tagKey") List<String> tagKeys, final @QueryParam("tagValue") List<String> tagValues) { if (!manager.isEnabled()) { return Response.status(Response.Status.FORBIDDEN).build(); } List<String> groups = manager.listMetricGroups(); if (!groups.contains(group)) { return buildResult(null, false, "The specified group is not found!"); } MetricRegistry registry = manager.getMetricRegistryByGroup(group); List<MetricObject> metricObjects = buildMetricRegistry(registry, new MetricNameSetFilter(metricName)); if (metricObjects.isEmpty()) { return buildResult(null, false, "The specified metric is not found!"); } return buildResult(metricObjects); }
MetricsResource { @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") public Response getMetric(final @PathParam("group") String group, final @PathParam("metric") String metricName, final @QueryParam("tagKey") List<String> tagKeys, final @QueryParam("tagValue") List<String> tagValues) { if (!manager.isEnabled()) { return Response.status(Response.Status.FORBIDDEN).build(); } List<String> groups = manager.listMetricGroups(); if (!groups.contains(group)) { return buildResult(null, false, "The specified group is not found!"); } MetricRegistry registry = manager.getMetricRegistryByGroup(group); List<MetricObject> metricObjects = buildMetricRegistry(registry, new MetricNameSetFilter(metricName)); if (metricObjects.isEmpty()) { return buildResult(null, false, "The specified metric is not found!"); } return buildResult(metricObjects); } }
MetricsResource { @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") public Response getMetric(final @PathParam("group") String group, final @PathParam("metric") String metricName, final @QueryParam("tagKey") List<String> tagKeys, final @QueryParam("tagValue") List<String> tagValues) { if (!manager.isEnabled()) { return Response.status(Response.Status.FORBIDDEN).build(); } List<String> groups = manager.listMetricGroups(); if (!groups.contains(group)) { return buildResult(null, false, "The specified group is not found!"); } MetricRegistry registry = manager.getMetricRegistryByGroup(group); List<MetricObject> metricObjects = buildMetricRegistry(registry, new MetricNameSetFilter(metricName)); if (metricObjects.isEmpty()) { return buildResult(null, false, "The specified metric is not found!"); } return buildResult(metricObjects); }  }
MetricsResource { @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") public Response getMetric(final @PathParam("group") String group, final @PathParam("metric") String metricName, final @QueryParam("tagKey") List<String> tagKeys, final @QueryParam("tagValue") List<String> tagValues) { if (!manager.isEnabled()) { return Response.status(Response.Status.FORBIDDEN).build(); } List<String> groups = manager.listMetricGroups(); if (!groups.contains(group)) { return buildResult(null, false, "The specified group is not found!"); } MetricRegistry registry = manager.getMetricRegistryByGroup(group); List<MetricObject> metricObjects = buildMetricRegistry(registry, new MetricNameSetFilter(metricName)); if (metricObjects.isEmpty()) { return buildResult(null, false, "The specified metric is not found!"); } return buildResult(metricObjects); }  @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 { @GET @Produces({Constants.PRODUCE_JSON_WITH_QUALITY_SOURCE, MediaType.TEXT_HTML}) @Path("/{group}/{metric}") public Response getMetric(final @PathParam("group") String group, final @PathParam("metric") String metricName, final @QueryParam("tagKey") List<String> tagKeys, final @QueryParam("tagValue") List<String> tagValues) { if (!manager.isEnabled()) { return Response.status(Response.Status.FORBIDDEN).build(); } List<String> groups = manager.listMetricGroups(); if (!groups.contains(group)) { return buildResult(null, false, "The specified group is not found!"); } MetricRegistry registry = manager.getMetricRegistryByGroup(group); List<MetricObject> metricObjects = buildMetricRegistry(registry, new MetricNameSetFilter(metricName)); if (metricObjects.isEmpty()) { return buildResult(null, false, "The specified metric is not found!"); } return buildResult(metricObjects); }  @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);  }