Skip to content

Commit 58fbaab

Browse files
committed
Spring Boot Actuator project initial commit
1 parent fc6fd3e commit 58fbaab

File tree

12 files changed

+319
-0
lines changed

12 files changed

+319
-0
lines changed

spring-boot-actuator/.classpath

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="output" path="target/classes"/>
31+
</classpath>

spring-boot-actuator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

spring-boot-actuator/.project

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>spring-boot-actuator</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.wst.validation.validationbuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
<buildCommand>
29+
<name>org.eclipse.m2e.core.maven2Builder</name>
30+
<arguments>
31+
</arguments>
32+
</buildCommand>
33+
</buildSpec>
34+
<natures>
35+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
36+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
37+
<nature>org.eclipse.jdt.core.javanature</nature>
38+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
39+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
40+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
41+
</natures>
42+
</projectDescription>

spring-boot-actuator/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.baeldung</groupId>
5+
<artifactId>spring-boot-actuator</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
<name>Spring Boot Actuator</name>
9+
<description>This is simple boot application for Spring boot actuator test</description>
10+
11+
<!-- Inherit defaults from Spring Boot -->
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>1.2.3.RELEASE</version>
16+
</parent>
17+
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-actuator</artifactId>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-security</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>io.dropwizard.metrics</groupId>
37+
<artifactId>metrics-core</artifactId>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-maven-plugin</artifactId>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
50+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.baeldung.endpoints;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.springframework.boot.actuate.endpoint.Endpoint;
7+
import org.springframework.stereotype.Component;
8+
9+
@Component
10+
public class CustomEndpoint implements Endpoint<List<String>> {
11+
12+
public CustomEndpoint() {
13+
14+
}
15+
16+
public String getId() {
17+
return "customEndpoint";
18+
}
19+
20+
public boolean isEnabled() {
21+
return true;
22+
}
23+
24+
public boolean isSensitive() {
25+
return true;
26+
}
27+
28+
public List<String> invoke() {
29+
//Your logic to display the output
30+
List<String> messages = new ArrayList<String>();
31+
messages.add("This is message 1");
32+
messages.add("This is message 2");
33+
return messages;
34+
}
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.baeldung.endpoints;
2+
3+
import java.util.List;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
7+
import org.springframework.boot.actuate.endpoint.Endpoint;
8+
import org.springframework.stereotype.Component;
9+
10+
@Component
11+
public class ListEndpoints extends AbstractEndpoint<List<Endpoint>> {
12+
private List<Endpoint> endpoints;
13+
14+
@Autowired
15+
public ListEndpoints(List<Endpoint> endpoints) {
16+
super("listEndpoints");
17+
this.endpoints = endpoints;
18+
}
19+
20+
public List<Endpoint> invoke() {
21+
return this.endpoints;
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.baeldung.endpoints;
2+
3+
import org.springframework.boot.actuate.health.Health;
4+
import org.springframework.boot.actuate.health.HealthIndicator;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class MyHealthCheck implements HealthIndicator {
9+
10+
public Health health() {
11+
int errorCode = check(); // perform some specific health check
12+
if (errorCode != 0) {
13+
return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build();
14+
}
15+
return Health.up().build();
16+
}
17+
18+
public int check() {
19+
// Your logic to check health
20+
return 1;
21+
}
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.baeldung.main;
2+
3+
4+
import org.baeldung.service.LoginService;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8+
import org.springframework.context.annotation.ComponentScan;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@RestController
13+
@EnableAutoConfiguration
14+
@ComponentScan({"org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx"})
15+
public class SpringBootActuatorApplication {
16+
17+
@Autowired
18+
private LoginService service;
19+
20+
@RequestMapping("/")
21+
String home() {
22+
service.login("admin", "admin".toCharArray());
23+
return "TADA!!! You are in Spring Boot Actuator test application.";
24+
}
25+
26+
public static void main(String[] args) {
27+
SpringApplication.run(SpringBootActuatorApplication.class, args);
28+
}
29+
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.baeldung.monitor.jmx;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import com.codahale.metrics.JmxReporter;
8+
import com.codahale.metrics.MetricRegistry;
9+
10+
@Configuration
11+
public class MonitoringConfig {
12+
@Autowired
13+
private MetricRegistry registry;
14+
15+
@Bean
16+
public JmxReporter jmxReporter() {
17+
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
18+
reporter.start();
19+
return reporter;
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.baeldung.service;
2+
3+
public interface LoginService {
4+
public boolean login(String userName, char[] password);
5+
}

0 commit comments

Comments
 (0)