File tree Expand file tree Collapse file tree
springboot-actuator-prometheus Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
4+ <modelVersion >4.0.0</modelVersion >
5+ <parent >
6+ <groupId >org.springframework.boot</groupId >
7+ <artifactId >spring-boot-starter-parent</artifactId >
8+ <version >2.1.9.RELEASE</version >
9+ <relativePath /> <!-- lookup parent from repository -->
10+ </parent >
11+ <groupId >com.gf</groupId >
12+ <artifactId >springboot-actuator-prometheus</artifactId >
13+ <version >0.0.1-SNAPSHOT</version >
14+ <name >springboot-actuator-prometheus</name >
15+ <description >Demo project for Spring Boot</description >
16+
17+ <properties >
18+ <java .version>1.8</java .version>
19+ </properties >
20+
21+ <dependencies >
22+ <dependency >
23+ <groupId >org.springframework.boot</groupId >
24+ <artifactId >spring-boot-starter-actuator</artifactId >
25+ </dependency >
26+ <dependency >
27+ <groupId >org.springframework.boot</groupId >
28+ <artifactId >spring-boot-starter-web</artifactId >
29+ </dependency >
30+ <dependency >
31+ <groupId >io.micrometer</groupId >
32+ <artifactId >micrometer-registry-prometheus</artifactId >
33+ </dependency >
34+
35+ <dependency >
36+ <groupId >org.springframework.boot</groupId >
37+ <artifactId >spring-boot-starter-test</artifactId >
38+ <scope >test</scope >
39+ </dependency >
40+ </dependencies >
41+
42+ <build >
43+ <plugins >
44+ <plugin >
45+ <groupId >org.springframework.boot</groupId >
46+ <artifactId >spring-boot-maven-plugin</artifactId >
47+ </plugin >
48+ </plugins >
49+ </build >
50+
51+ </project >
Original file line number Diff line number Diff line change 1+ package com .gf ;
2+
3+ import io .micrometer .core .instrument .MeterRegistry ;
4+ import org .springframework .boot .SpringApplication ;
5+ import org .springframework .boot .actuate .autoconfigure .metrics .MeterRegistryCustomizer ;
6+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
7+ import org .springframework .context .annotation .Bean ;
8+ import org .springframework .web .bind .annotation .RequestMapping ;
9+ import org .springframework .web .bind .annotation .RestController ;
10+
11+
12+ @ SpringBootApplication
13+ @ RestController
14+ public class SpringbootActuatorPrometheusDemoApplication {
15+
16+ public static void main (String [] args ) {
17+ SpringApplication .run (SpringbootActuatorPrometheusDemoApplication .class , args );
18+ }
19+
20+ @ RequestMapping (value = "/hello" )
21+ public String sayHello () {
22+ for (int i = 1 ; i <= 10 ; i ++) {
23+ Thread t = new Thread (() -> {
24+ try {
25+ Thread .sleep (5000 );
26+ } catch (InterruptedException e ) {
27+ e .printStackTrace ();
28+ }
29+ } , "HelloThread - " + i );
30+ t .start ();
31+ }
32+ return "ok" ;
33+ }
34+
35+ /**
36+ @Bean
37+ MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
38+ return registry -> registry.config().commonTags("application", "springboot-actuator-prometheus-demo");
39+ }
40+ */
41+
42+ }
Original file line number Diff line number Diff line change 1+ management :
2+ endpoints :
3+ web :
4+ exposure :
5+ include : ' *'
6+
7+ endpoint :
8+ health :
9+ show-details : always
10+
11+ metrics :
12+ tags :
13+ application : actuator-demo
14+
Original file line number Diff line number Diff line change 1+ package com .gf ;
2+
3+ import org .junit .Test ;
4+ import org .junit .runner .RunWith ;
5+ import org .springframework .boot .test .context .SpringBootTest ;
6+ import org .springframework .test .context .junit4 .SpringRunner ;
7+
8+ @ RunWith (SpringRunner .class )
9+ @ SpringBootTest
10+ public class SpringbootActuatorPrometheusDemoApplicationTests {
11+
12+ @ Test
13+ public void contextLoads () {
14+ }
15+
16+ }
You can’t perform that action at this time.
0 commit comments