add > spring boot actuator endpoints

This commit is contained in:
lihengming
2017-12-03 22:47:55 +08:00
parent 5c2bbe6001
commit 02b42bb2af
3 changed files with 68 additions and 3 deletions
+17 -3
View File
@@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.4</version>
<version>1.1.6</version>
<packaging>jar</packaging>
<name>druid-spring-boot-starter</name>
<description>Spring Boot with Druid support,help you simplify Druid config in Spring Boot.</description>
<url>https://github.com/alibaba/druid</url>
<properties>
<druid.version>1.1.4</druid.version>
<spring-boot.version>1.5.6.RELEASE</spring-boot.version>
<druid.version>1.1.6</druid.version>
<spring-boot.version>1.5.9.RELEASE</spring-boot.version>
</properties>
<developers>
@@ -44,6 +44,10 @@
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
@@ -54,6 +58,16 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@@ -0,0 +1,44 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.spring.boot.autoconfigure.actuator.endpoint;
import com.alibaba.druid.stat.DruidStatManagerFacade;
import org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author lihengming [89921218@qq.com]
*/
@ConfigurationProperties(prefix = "endpoints.druid")
public class DruidDataSourceMvcEndpoint extends AbstractMvcEndpoint {
public DruidDataSourceMvcEndpoint() {
super("/druid-endpoint", true);
}
@ResponseBody
@GetMapping( produces = {ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE})
public Object invoke() {
return DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
}
}
@@ -25,4 +25,11 @@ spring.jpa.hibernate.ddl-auto=create-drop
# 更多配置属性见 DruidDataSource 内成员变量(只要有set方法便支持),或者根据IDE提示,或者查看官方文档
# 启用endpoint,默认访问地址:/druid-endpoint,可以使用endpoints.druid.path=自定义终端地址
endpoints.druid.enabled=true
# 默认需要安全认证才可以访问,可以用下面两种方法之一来禁用安全认证,详情见 Spring Boot 官方文档
endpoints.druid.sensitive=true
# management.security.enabled=false
# 注:配置文件可以根据习惯更换为 .yml