1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.stats.collectors;
12
13 import jakarta.inject.Inject;
14
15 import org.springframework.beans.factory.annotation.Value;
16
17 import psiprobe.beans.RuntimeInfoAccessorBean;
18 import psiprobe.model.jmx.RuntimeInformation;
19 import psiprobe.tools.TimeExpression;
20
21
22
23
24 public class RuntimeStatsCollectorBean extends AbstractStatsCollectorBean {
25
26
27 @Inject
28 private RuntimeInfoAccessorBean runtimeInfoAccessorBean;
29
30
31
32
33
34
35 public RuntimeInfoAccessorBean getRuntimeInfoAccessorBean() {
36 return runtimeInfoAccessorBean;
37 }
38
39
40
41
42
43
44 public void setRuntimeInfoAccessorBean(RuntimeInfoAccessorBean runtimeInfoAccessorBean) {
45 this.runtimeInfoAccessorBean = runtimeInfoAccessorBean;
46 }
47
48 @Override
49 public void collect() throws Exception {
50 RuntimeInformation ri = runtimeInfoAccessorBean.getRuntimeInformation();
51 if (ri != null) {
52 long time = System.currentTimeMillis();
53 buildAbsoluteStats("os.memory.committed", ri.getCommittedVirtualMemorySize() / 1024, time);
54 buildAbsoluteStats("os.memory.physical",
55 (ri.getTotalPhysicalMemorySize() - ri.getFreePhysicalMemorySize()) / 1024, time);
56 buildAbsoluteStats("os.memory.swap",
57 (ri.getTotalSwapSpaceSize() - ri.getFreeSwapSpaceSize()) / 1024, time);
58
59 buildAbsoluteStats("os.fd.open", ri.getOpenFileDescriptorCount(), time);
60 buildAbsoluteStats("os.fd.max", ri.getMaxFileDescriptorCount(), time);
61
62 long processCpuTimeMs = ri.getProcessCpuTime() / 1000000;
63
64 buildTimePercentageStats("os.cpu", processCpuTimeMs / ri.getAvailableProcessors(), time);
65 }
66 }
67
68
69
70
71
72
73
74 public void setMaxSeries(@Value("${psiprobe.beans.stats.collectors.runtime.period}") long period,
75 @Value("${psiprobe.beans.stats.collectors.runtime.span}") long span) {
76 super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
77 }
78
79 }