Springboot2 actuator(一)

學習springboot2 actuator模塊的內容,記錄一下問題.html

actuator功能 : 對執行系統的監控和功能統計,監控採集本身系統的各類指標git

開始使用actuator,看了網上的操做簡單的一逼,簡單歸簡單,本身練練手理解理解唄github

--------------------------------------------------------web

試一試

引入maven依賴spring

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

能夠了,跑起來試試:json

理想->訪問 http://localhost:8080/health 瀏覽器顯示如下jsonapi

{
  "status": "UP",
  "diskSpace": {
      "status": "UP",
      "total": 131200434816,
      "free": 253870264444,
      "threshold": 01483760
  }
}

現實-> 訪問 http://localhost:8080/health 瀏覽器顯示如下瀏覽器

打臉的 404,灰色的現實.springboot

PS: springboot2以前沒有接觸這些好玩東西,springboot2版本時候開始上手,對於這些跟隨資料理解練手的打臉現象非常懵逼,因而開始有想法記錄,寫博客app

瞎想: 對於什麼都沒有寫,只加入了依賴出了問題,仍是404的問題,就想以前的資料,是否是升級了之後有改動層次或者是棄用,合併各類改動呢?

來一份別人的控制檯信息:

來一份本座的控制檯信息:

上面信息說暴露端點有2個 endpoint(s), 根路徑是 '/actuator'

目前如今能夠訪問 /actuator/health 和 /actuator/info 和/actuator,請求方式是GET

再試試唄,訪問以下: 訪問 http://localhost:8080/actuator/health

{
   status: "UP"
}

PS: 剛纔注意到本座的控制檯的Mapped就兩個,別人的都暴露出來了,可能須要加什麼約定,後面再說.

我也想要,問題

我怎麼只有一個UP,見了鬼了,其餘信息呢? 查詢資料,須要在application.yml中配置一下

發現springboot2以前的信息都過期了,懵逼

點擊進入

進去json文件, spring-configuration-metadata.json

裏面說明了這些都已經被棄用 deprecated: true 列表,網上也看不到明確資料,乾脆去官網上去找找發現

springboot2變更文檔 地址:

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide

官方actuatorAPI文檔 地址:

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/

 

搞定

官方文檔上說endpoints都歸在management下,show-details是health的詳細信息設置

application.yml 配置以下: 顯示health詳細信息

management:
  endpoint:
    health:
      show-details: always

運行結果以下:

{
	status: "UP",
	details: {
		db: {
		status: "UP",
		details: {
			datasourceCat: {
			status: "UP",
			details: {
				database: "MySQL",
				hello: 1
			}
		},
		datasourceDog: {
			status: "UP",
			details: {
				database: "MySQL",
				hello: 1
			}
		}
	}
	},
		diskSpace: {
		status: "UP",
			details: {
				total: 280248709120,
				free: 268942974976,
				threshold: 10485760
			}
		}
	}
}

 

遇到相同問題的同窗能夠看下文檔,上面都有說明以及操做

本次學習最後的配置yml:

management:
  endpoint:
    health:
      show-details: always
  server:
    servlet:
      context-path: /cat
    port: 8081
  endpoints:
    web:
      base-path: /tom
      exposure:
        include: '*'

server.servlet.context-path: /cat 必須在指定 server.port端口才會有效果

endpoints.web.base-path: /tom  能夠替換原來的/actuator訪問路徑,也能夠設置/ 自定義訪問

include: '*' 是打開全部的端點 ,還有一個shutdown端點須要另外打開,再說

測試: 訪問瀏覽器 http://localhost:8081/cat/tom -- 以及json數據返回:

{
	_links: {
		self: {
			href: "http://localhost:8081/cat/tom",
			templated: false
		},
		auditevents: {
			href: "http://localhost:8081/cat/tom/auditevents",
			templated: false
		},
		beans: {
			href: "http://localhost:8081/cat/tom/beans",
			templated: false
		},
		health: {
			href: "http://localhost:8081/cat/tom/health",
			templated: false
		},
		conditions: {
			href: "http://localhost:8081/cat/tom/conditions",
			templated: false
		},
		configprops: {
			href: "http://localhost:8081/cat/tom/configprops",
			templated: false
		},
		env: {
			href: "http://localhost:8081/cat/tom/env",
			templated: false
		},
		env - toMatch: {
			href: "http://localhost:8081/cat/tom/env/{toMatch}",
			templated: true
		},
		info: {
			href: "http://localhost:8081/cat/tom/info",
			templated: false
		},
		loggers: {
			href: "http://localhost:8081/cat/tom/loggers",
			templated: false
		},
		loggers - name: {
			href: "http://localhost:8081/cat/tom/loggers/{name}",
			templated: true
		},
		heapdump: {
			href: "http://localhost:8081/cat/tom/heapdump",
			templated: false
		},
		threaddump: {
			href: "http://localhost:8081/cat/tom/threaddump",
			templated: false
		},
		metrics: {
			href: "http://localhost:8081/cat/tom/metrics",
			templated: false
		},
		metrics - requiredMetricName: {
			href: "http://localhost:8081/cat/tom/metrics/{requiredMetricName}",
			templated: true
		},
		scheduledtasks: {
			href: "http://localhost:8081/cat/tom/scheduledtasks",
			templated: false
		},
		httptrace: {
			href: "http://localhost:8081/cat/tom/httptrace",
			templated: false
		},
		mappings: {
			href: "http://localhost:8081/cat/tom/mappings",
			templated: false
		}
	}
}

 

------------------------------------------------

相關文章
相關標籤/搜索