View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
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   * The Class RuntimeStatsCollectorBean.
23   */
24  public class RuntimeStatsCollectorBean extends AbstractStatsCollectorBean {
25  
26    /** The runtime info accessor bean. */
27    @Inject
28    private RuntimeInfoAccessorBean runtimeInfoAccessorBean;
29  
30    @Override
31    public void collect() throws Exception {
32      RuntimeInformation ri = runtimeInfoAccessorBean.getRuntimeInformation();
33      if (ri != null) {
34        long time = System.currentTimeMillis();
35        buildAbsoluteStats("os.memory.committed", ri.getCommittedVirtualMemorySize() / 1024, time);
36        buildAbsoluteStats("os.memory.physical",
37            (ri.getTotalPhysicalMemorySize() - ri.getFreePhysicalMemorySize()) / 1024, time);
38        buildAbsoluteStats("os.memory.swap",
39            (ri.getTotalSwapSpaceSize() - ri.getFreeSwapSpaceSize()) / 1024, time);
40  
41        buildAbsoluteStats("os.fd.open", ri.getOpenFileDescriptorCount(), time);
42        buildAbsoluteStats("os.fd.max", ri.getMaxFileDescriptorCount(), time);
43        // convert from nanoseconds so times use the same units
44        long processCpuTimeMs = ri.getProcessCpuTime() / 1000000;
45        // divide by the number of processors to reflect shared load (<= 100%)
46        buildTimePercentageStats("os.cpu", processCpuTimeMs / ri.getAvailableProcessors(), time);
47      }
48    }
49  
50    /**
51     * Sets the max series expression.
52     *
53     * @param period the period
54     * @param span the span
55     */
56    public void setMaxSeries(
57        @Value("${psiprobe.beans.stats.collectors.runtime.period}") String period,
58        @Value("${psiprobe.beans.stats.collectors.runtime.span}") String span) {
59      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
60    }
61  
62  }