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    @Override
35    public void collect() throws Exception {
36      List<MemoryPool> pools = jvmMemoryInfoAccessor.getPools();
37      long time = System.currentTimeMillis();
38      for (MemoryPool pool : pools) {
39        buildAbsoluteStats("memory.pool." + pool.getName(), pool.getUsed(), time);
40      }
41    }
42  
43    /**
44     * Sets the max series expression.
45     *
46     * @param period the period
47     * @param span the span
48     */
49    public void setMaxSeries(@Value("${psiprobe.beans.stats.collectors.memory.period}") String period,
50        @Value("${psiprobe.beans.stats.collectors.memory.span}") String span) {
51      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
52    }
53  
54    @Autowired
55    @Override
56    public void setListeners(List<StatsCollectionListener> listeners) {
57      super.setListeners(listeners);
58    }
59  
60  }