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

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.

主站蜘蛛池模板: 遂溪县| 隆昌县| 花莲市| 泾川县| 西峡县| 巍山| 郧西县| 无锡市| 濉溪县| 分宜县| 福建省| 福建省| 克东县| 梨树县| 阜宁县| 康平县| 贵港市| 白城市| 东乌| 兴隆县| 敖汉旗| 寻甸| 海南省| 怀远县| 历史| 兴仁县| 安远县| 哈密市| 镇安县| 进贤县| 囊谦县| 双鸭山市| 临潭县| 舟山市| 辽阳县| 屏东市| 鱼台县| 大荔县| 临江市| 广州市| 若尔盖县|