/
Info.java
51 lines (39 loc) · 1.87 KB
/
Info.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.fabianlee.springbootwithdockerpush;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties;
import org.springframework.http.MediaType;
@Controller
public class Info {
// pull from build.gradle via 'springBoot' directive
@Autowired
private BuildProperties buildProperties;
// pull from application.properties
@Value("${management.server.port}")
protected String mgmtPort;
@RequestMapping(value="/info",method=RequestMethod.GET,produces = MediaType.TEXT_PLAIN_VALUE)
public @ResponseBody String metrics() {
// create map of all keys we want reported back
Map<String,String> kv = new TreeMap<String,String>();
kv.put("key1","0.0");
kv.put("spring_micro_with_actuator","0.0");
kv.put("management_server_port",mgmtPort);
kv.put(String.format("springbootwithdockerpush{version=\"%s\"}",buildProperties.getVersion().toString()),"0.0");
kv.put(String.format("springbootwithdockerpush{name=\"%s\"}",buildProperties.getName().toString()),"0.0");
kv.put(String.format("springbootwithdockerpush{group=\"%s\"}",buildProperties.getGroup().toString()),"0.0");
// build sorted, line-by-line for each key
StringBuffer sbuf = new StringBuffer();
for (Iterator<String> it=kv.keySet().iterator(); it.hasNext();) {
String key = it.next();
sbuf.append(key + " " + kv.get(key) + "\n");
}
return sbuf.toString();
}
}