监控

  • 应用状态
  • 系统状态

Metrics

  1. dependencies {
  2. compile 'org.springframework:spring-context:4.2.4.RELEASE'
  3. compile 'org.springframework.data:spring-data-mongodb:1.8.4.RELEASE'
  4. compile 'io.dropwizard.metrics:metrics-core:3.1.2'
  5. compile 'io.dropwizard.metrics:metrics-jvm:3.1.2'
  6. compile 'io.dropwizard.metrics:metrics-graphite:3.1.2'
  7. compile 'com.ryantenney.metrics:metrics-spring:3.1.3'
  8. }
  1. @Configuration
  2. @EnableMetrics
  3. public class MetricsConfig extends MetricsConfigurerAdapter {
  4. @Override
  5. public void configureReporters(MetricRegistry metricRegistry) {
  6. Graphite graphite = new Graphite(new InetSocketAddress("192.168.99.100", 2003));
  7. GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
  8. .prefixedWith("juntao-laptop")
  9. .convertRatesTo(TimeUnit.SECONDS)
  10. .convertDurationsTo(TimeUnit.MILLISECONDS)
  11. .filter(MetricFilter.ALL)
  12. .build(graphite);
  13. registerReporter(graphiteReporter);
  14. graphiteReporter.start(1, TimeUnit.MINUTES);
  15. metricRegistry.registerAll(new MemoryUsageGaugeSet());
  16. metricRegistry.registerAll(new ThreadStatesGaugeSet());
  17. }
  18. }
  1. @RestController
  2. public class PersonController {
  3. @Autowired
  4. private PersonRepository personRepository;
  5. @Metered(absolute = true, name = "metered.people.get.all")
  6. @Timed(absolute = true, name = "people.get.all")
  7. @RequestMapping(value ="/people", method = RequestMethod.GET)
  8. public List<Person> findAll() {
  9. return personRepository.findAll();
  10. }
  11. }

Graphite

Grafana

collectd