1

Is there a way to measure CPU usage and Utilization of different aspects (CPU, Thread, Memory etc) using dropwizard in spring-boot?

Divs
  • 1,578
  • 2
  • 24
  • 51

1 Answers1

2

Use spring-boot-actuator for that. There is already a /metrics endpoint for the data you are asking for.

Check systemload.average, mem, mem.free, threads etc for the exact information.

For more information check:

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-dropwizard-metrics

A default MetricRegistry Spring bean will be created when you declare a dependency to the io.dropwizard.metrics:metrics-core library; you can also register you own @Bean instance if you need customizations. Users of the Dropwizard ‘Metrics’ library will find that Spring Boot metrics are automatically published to com.codahale.metrics.MetricRegistry. Metrics from the MetricRegistry are also automatically exposed via the /metrics endpoint

When Dropwizard metrics are in use, the default CounterService and GaugeService are replaced with a DropwizardMetricServices, which is a wrapper around the MetricRegistry (so you can @Autowired one of those services and use it as normal). You can also create “special” Dropwizard metrics by prefixing your metric names with the appropriate type (i.e. timer., histogram. for gauges, and meter.* for counters).

Lakatos Gyula
  • 3,949
  • 7
  • 35
  • 56
  • Thanks. Yes, I am using `metrics` endpoint, but how do I arrive at the % values for utilization? can I assess the system by seeing just the number for threads.* unless I can tally the numbers with max possible values? I can't find them. I always get `"systemload.average": -1` – Divs May 18 '17 at 13:19
  • Also, how to find `cpu` utilization? – Divs May 18 '17 at 13:32
  • Check this for the -1 systemload.average: http://stackoverflow.com/questions/39654056/java-spring-boot-actuator-metrics-system-load-average-returning-1 I don't think you can see the max possible value for threads. I think you can only get percentages for the memory and heap information and even then you should calculate it out for yourself.The systemload.average should be responsible for the cpu utilization. – Lakatos Gyula May 18 '17 at 13:33