官术网_书友最值得收藏!

Metering your services

Instrumentation is important for cloud applications. Your service should expose health check and metrics so that it can be monitored better. Spring Boot allows for easier instrumentation through the actuator module.

Include the following in your POM:

    <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency> 

Run the service. During startup, you will see a number of mappings being created.

You can access these URLs (such as http://localhost:8080/env) directly and see the information displayed:

{ 
  "profiles": [], 
  "server.ports": { 
    "local.server.port": 8082 
  }, 
  "commandLineArgs": { 
    "env": "dev/" 
  }, 
  "servletContextInitParams": {}, 
  "systemProperties": { 
    "java.runtime.name": "Java(TM) SE Runtime Environment", 
    "sun.boot.library.path": "C:\Program Files\Java\jdk1.8.0_73\jrebin", 
    "java.vm.version": "25.73-b02", 
    "java.vm.vendor": "Oracle Corporation", 
    "java.vendor.url": "http://java.oracle.com/", 
    "path.separator": ";", 
    "java.vm.name": "Java HotSpot(TM) 64-Bit Server VM", 
    "file.encoding.pkg": "sun.io", 
    "user.country": "IN", 
    "user.script": "", 
    "sun.java.launcher": "SUN_STANDARD", 
    "sun.os.patch.level": "Service Pack 1", 
    "PID": "9332", 
    "java.vm.specification.name": "Java Virtual Machine Specification", 
    "user.dir": "C:\Apps\wkneon\product", 

The metrics are especially interesting (http://localhost:8080/metrics):

{ 
  "mem": 353416, 
  "mem.free": 216921, 
  "processors": 4, 
  "instance.uptime": 624968, 
  "uptime": 642521, 
... 
  "gauge.servo.response.dev.product.id": 5, 
... 
   threads.peak": 38, 
  "threads.daemon": 35, 
  "threads.totalStarted": 45, 
  "threads": 37, 
... 

The information includes the counters and gauges which store the number of times the service was accessed and the response times.

主站蜘蛛池模板: 九台市| 靖西县| 垦利县| 莫力| 东安县| 西丰县| 通辽市| 丹凤县| 涡阳县| 清新县| 马公市| 确山县| 湘西| 东乡| 三门县| 延庆县| 宁远县| 太谷县| 清新县| 堆龙德庆县| 呼图壁县| 甘南县| 九寨沟县| 公主岭市| 潢川县| 洛扎县| 兴隆县| 新巴尔虎左旗| 紫云| 碌曲县| 雷山县| 青神县| 小金县| 黄石市| 金寨县| 呼伦贝尔市| 石家庄市| 民和| 北安市| 镇平县| 额济纳旗|