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.ContainerListenerBean;
18  import psiprobe.model.Connector;
19  import psiprobe.tools.TimeExpression;
20  
21  /**
22   * The Class ConnectorStatsCollectorBean.
23   */
24  public class ConnectorStatsCollectorBean extends AbstractStatsCollectorBean {
25  
26    /** The listener bean. */
27    @Inject
28    private ContainerListenerBean listenerBean;
29  
30    @Override
31    public void collect() throws Exception {
32      for (Connector connector : listenerBean.getConnectors(false)) {
33        String statName = "stat.connector." + connector.getProtocolHandler();
34        buildDeltaStats(statName + ".requests", connector.getRequestCount());
35        buildDeltaStats(statName + ".errors", connector.getErrorCount());
36        buildDeltaStats(statName + ".sent", connector.getBytesSent());
37        buildDeltaStats(statName + ".received", connector.getBytesReceived());
38        buildDeltaStats(statName + ".proc_time", connector.getProcessingTime());
39      }
40    }
41  
42    /**
43     * Reset.
44     *
45     * @throws Exception the exception
46     */
47    public void reset() throws Exception {
48      for (Connector connector : listenerBean.getConnectors(false)) {
49        reset(connector.getProtocolHandler());
50      }
51    }
52  
53    /**
54     * Reset.
55     *
56     * @param connectorName the connector name
57     */
58    public void reset(String connectorName) {
59      String statName = "stat.connector." + connectorName;
60      resetStats(statName + ".requests");
61      resetStats(statName + ".errors");
62      resetStats(statName + ".sent");
63      resetStats(statName + ".received");
64      resetStats(statName + ".proc_time");
65    }
66  
67    /**
68     * Sets the max series expression.
69     *
70     * @param period the period
71     * @param span the span
72     */
73    public void setMaxSeries(
74        @Value("${psiprobe.beans.stats.collectors.connector.period}") String period,
75        @Value("${psiprobe.beans.stats.collectors.connector.span}") String span) {
76      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
77    }
78  
79  }