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    /**
37     * Gets the container wrapper.
38     *
39     * @return the container wrapper
40     */
41    public ContainerWrapperBean getContainerWrapper() {
42      return containerWrapper;
43    }
44  
45    /**
46     * Sets the container wrapper.
47     *
48     * @param containerWrapper the new container wrapper
49     */
50    public void setContainerWrapper(ContainerWrapperBean containerWrapper) {
51      this.containerWrapper = containerWrapper;
52    }
53  
54    /**
55     * Gets the cluster wrapper.
56     *
57     * @return the cluster wrapper
58     */
59    public ClusterWrapperBean getClusterWrapper() {
60      return clusterWrapper;
61    }
62  
63    /**
64     * Sets the cluster wrapper.
65     *
66     * @param clusterWrapper the new cluster wrapper
67     */
68    public void setClusterWrapper(ClusterWrapperBean clusterWrapper) {
69      this.clusterWrapper = clusterWrapper;
70    }
71  
72    @Override
73    public void collect() throws Exception {
74      // Job can be called before the servlet finished initialization. Make sure
75      // we don't get an NPE.
76      TomcatContainer container = containerWrapper.getTomcatContainer();
77      if (container != null) {
78        Cluster cluster =
79            clusterWrapper.getCluster(container.getName(), container.getHostName(), false);
80        if (cluster != null) {
81          buildDeltaStats("cluster.received", cluster.getTotalReceivedBytes());
82          buildDeltaStats("cluster.sent", cluster.getSenderTotalBytes());
83          buildDeltaStats("cluster.req.received", cluster.getNrOfMsgsReceived());
84          buildDeltaStats("cluster.req.sent", cluster.getSenderNrOfRequests());
85        }
86      }
87    }
88  
89    /**
90     * Sets the max series expression.
91     *
92     * @param period the period
93     * @param span the span
94     */
95    public void setMaxSeries(@Value("${psiprobe.beans.stats.collectors.cluster.period}") long period,
96        @Value("${psiprobe.beans.stats.collectors.cluster.span}") long span) {
97      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
98    }
99  
100 }