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.TomcatContainer;
18  import psiprobe.beans.ClusterWrapperBean;
19  import psiprobe.beans.ContainerWrapperBean;
20  import psiprobe.model.jmx.Cluster;
21  import psiprobe.tools.TimeExpression;
22  
23  /**
24   * The Class ClusterStatsCollectorBean.
25   */
26  public class ClusterStatsCollectorBean extends AbstractStatsCollectorBean {
27  
28    /** The container wrapper. */
29    @Inject
30    private ContainerWrapperBean containerWrapper;
31  
32    /** The cluster wrapper. */
33    @Inject
34    private ClusterWrapperBean clusterWrapper;
35  
36    @Override
37    public void collect() throws Exception {
38      // Job can be called before the servlet finished initialization. Make sure
39      // we don't get an NPE.
40      TomcatContainer container = containerWrapper.getTomcatContainer();
41      if (container != null) {
42        Cluster cluster =
43            clusterWrapper.getCluster(container.getName(), container.getHostName(), false);
44        if (cluster != null) {
45          buildDeltaStats("cluster.received", cluster.getTotalReceivedBytes());
46          buildDeltaStats("cluster.sent", cluster.getSenderTotalBytes());
47          buildDeltaStats("cluster.req.received", cluster.getNrOfMsgsReceived());
48          buildDeltaStats("cluster.req.sent", cluster.getSenderNrOfRequests());
49        }
50      }
51    }
52  
53    /**
54     * Sets the max series expression.
55     *
56     * @param period the period
57     * @param span the span
58     */
59    public void setMaxSeries(
60        @Value("${psiprobe.beans.stats.collectors.cluster.period}") String period,
61        @Value("${psiprobe.beans.stats.collectors.cluster.span}") String span) {
62      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
63    }
64  
65  }