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 java.util.List;
16  
17  import org.springframework.beans.factory.annotation.Autowired;
18  import org.springframework.beans.factory.annotation.Value;
19  
20  import psiprobe.beans.JvmMemoryInfoAccessorBean;
21  import psiprobe.beans.stats.listeners.StatsCollectionListener;
22  import psiprobe.model.jmx.MemoryPool;
23  import psiprobe.tools.TimeExpression;
24  
25  /**
26   * The Class JvmMemoryStatsCollectorBean.
27   */
28  public class JvmMemoryStatsCollectorBean extends AbstractStatsCollectorBean {
29  
30    /** The jvm memory info accessor. */
31    @Inject
32    private JvmMemoryInfoAccessorBean jvmMemoryInfoAccessor;
33  
34    /**
35     * Gets the jvm memory info accessor.
36     *
37     * @return the jvm memory info accessor
38     */
39    public JvmMemoryInfoAccessorBean getJvmMemoryInfoAccessor() {
40      return jvmMemoryInfoAccessor;
41    }
42  
43    /**
44     * Sets the jvm memory info accessor.
45     *
46     * @param jvmMemoryInfoAccessor the new jvm memory info accessor
47     */
48    public void setJvmMemoryInfoAccessor(JvmMemoryInfoAccessorBean jvmMemoryInfoAccessor) {
49      this.jvmMemoryInfoAccessor = jvmMemoryInfoAccessor;
50    }
51  
52    @Override
53    public void collect() throws Exception {
54      List<MemoryPool> pools = jvmMemoryInfoAccessor.getPools();
55      long time = System.currentTimeMillis();
56      for (MemoryPool pool : pools) {
57        buildAbsoluteStats("memory.pool." + pool.getName(), pool.getUsed(), time);
58      }
59    }
60  
61    /**
62     * Sets the max series expression.
63     *
64     * @param period the period
65     * @param span the span
66     */
67    public void setMaxSeries(@Value("${psiprobe.beans.stats.collectors.memory.period}") long period,
68        @Value("${psiprobe.beans.stats.collectors.memory.span}") long span) {
69      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
70    }
71  
72    @Autowired
73    @Override
74    public void setListeners(List<StatsCollectionListener> listeners) {
75      super.setListeners(listeners);
76    }
77  
78  }