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

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.

主站蜘蛛池模板: 葫芦岛市| 保定市| 石林| 桂平市| 江华| 巢湖市| 江川县| 将乐县| 九寨沟县| 顺昌县| 同心县| 平谷区| 虎林市| 阳东县| 高要市| 格尔木市| 泸水县| 厦门市| 环江| 东乌| 城口县| 开封县| 章丘市| 昌图县| 德化县| 怀来县| 马边| 呼玛县| 临西县| 额尔古纳市| 章丘市| 阳春市| 扎囊县| 嘉鱼县| 庆云县| 长沙市| 曲阜市| 周至县| 邳州市| 道真| 连州市|