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

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.

主站蜘蛛池模板: 凭祥市| 临沂市| 塔河县| 嫩江县| 五常市| 张掖市| 合山市| 东阳市| 洛扎县| 南澳县| 德州市| 长兴县| 枣庄市| 淳安县| 华阴市| 松阳县| 建昌县| 荣昌县| 六盘水市| 乐安县| 包头市| 万州区| 涞水县| 拜城县| 晋中市| 天水市| 临沂市| 龙南县| 基隆市| 登封市| 碌曲县| 类乌齐县| 波密县| 三原县| 句容市| 琼结县| 都安| 郑州市| 正阳县| 鹤峰县| 屏山县|