Revision 45566
Added by Michele Artini over 7 years ago
BaseService.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.services; |
2 | 2 |
|
3 |
import java.io.File; |
|
4 |
import java.lang.management.ManagementFactory; |
|
5 |
import java.lang.management.OperatingSystemMXBean; |
|
3 | 6 |
import java.util.HashMap; |
4 | 7 |
import java.util.Map; |
5 | 8 |
|
6 | 9 |
import javax.annotation.PostConstruct; |
7 |
import javax.servlet.http.HttpServletRequest; |
|
8 | 10 |
|
9 |
import org.apache.commons.lang3.StringUtils; |
|
10 | 11 |
import org.apache.commons.logging.Log; |
11 | 12 |
import org.apache.commons.logging.LogFactory; |
12 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
49 | 50 |
} else { |
50 | 51 |
throw new DnetGenericException("A required annotation is missing (@RequestMapping) in class " + getClass()); |
51 | 52 |
} |
53 |
|
|
54 |
final File dir = new File(containerConfiguration.getBaseDir()); |
|
55 |
if (!dir.exists()) { |
|
56 |
dir.mkdirs(); |
|
57 |
} |
|
52 | 58 |
} |
53 | 59 |
|
54 | 60 |
@Override |
... | ... | |
72 | 78 |
} |
73 | 79 |
|
74 | 80 |
@RequestMapping("identify") |
75 |
public ServiceRunningInstance identify(final HttpServletRequest req) { |
|
76 |
return new ServiceRunningInstance(getProfileId(), StringUtils.substringBeforeLast(req.getRequestURI(), "/identify")); |
|
81 |
public ServiceRunningInstance identify() { |
|
82 |
final File f = new File(containerConfiguration.getBaseDir()); |
|
83 |
final Runtime runtime = Runtime.getRuntime(); |
|
84 |
final OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); |
|
85 |
|
|
86 |
final ServiceRunningInstance res = new ServiceRunningInstance(); |
|
87 |
res.setServiceId(profileId); |
|
88 |
res.setBaseUrl(baseUrl); |
|
89 |
|
|
90 |
res.setFreeDiskSpace(bytesToMegaBytes(f.getFreeSpace())); |
|
91 |
res.setTotalDiskSpace(bytesToMegaBytes(f.getTotalSpace())); |
|
92 |
|
|
93 |
res.setFreeMemory(bytesToMegaBytes(runtime.freeMemory())); |
|
94 |
res.setTotalMemory(bytesToMegaBytes(runtime.totalMemory())); |
|
95 |
res.setMaxMemory(bytesToMegaBytes(runtime.maxMemory())); |
|
96 |
res.setUsedMemory(bytesToMegaBytes(runtime.totalMemory() - runtime.freeMemory())); |
|
97 |
|
|
98 |
res.setNumberOfProcessors(osBean.getAvailableProcessors()); |
|
99 |
res.setSysLoadAvg(osBean.getSystemLoadAverage()); |
|
100 |
|
|
101 |
return res; |
|
77 | 102 |
} |
78 | 103 |
|
79 | 104 |
public String getProfileId() { |
... | ... | |
116 | 141 |
this.baseUrl = baseUrl; |
117 | 142 |
} |
118 | 143 |
|
144 |
private static final long bytesToMegaBytes(final long n) { |
|
145 |
return n / 1_048_576; |
|
146 |
} |
|
147 |
|
|
119 | 148 |
} |
Also available in: Unified diff