ryantenney / metrics-spring

Spring integration for Metrics
http://www.ryantenney.com/metrics-spring/
Apache License 2.0
701 stars 226 forks source link

Sorting metrics #183

Closed YLombardi closed 8 years ago

YLombardi commented 8 years ago

Hi.

I just begin to use metrics-spring and follow "basic usage" tutorial (add the dependency and create a MetricsConfigurationClass). I add @Timed(name = "methodX", absolute = true) on some methods.

After starting my application, I use the metrics endpoint to read the metrics and I see that each time I refresh, the custom metrics are in a different order.

Is it possible to sort the metrics by keys ?

shakuzen commented 8 years ago

Are you referring to the Spring Boot Actuator /metrics endpoint? If so, I believe this is a Spring Boot Actuator enhancement request and it has been discussed before. Please check the issues there.

YLombardi commented 8 years ago

Yes I'm referring to this endpoint. I found a solution by creating a new endpoint that call the MetricsEndpoint and sort the result.

@Component
public class CustomMetricsEndpoint extends AbstractEndpoint<Map<String, Object>> {

    private MetricsEndpoint metricsEndpoint;

    @Autowired
    public CustomMetricsEndpoint(MetricsEndpoint metricsEndpoint) {
        super("custommetrics");
        this.metricsEndpoint = metricsEndpoint;
    }

    public Map<String, Object> invoke() {
        SortedMap<String, Object> metricsMap =
                new TreeMap<String, Object>(this.metricsEndpoint.invoke());
        return metricsMap;
    }
}
ryantenney commented 8 years ago

I'm not familiar with the Spring Boot Actuator /metrics endpoint, but it would appear @shakuzen is correct.