01: /*
02: * This software is released under a licence similar to the Apache Software Licence.
03: * See org.logicalcobwebs.proxool.package.html for details.
04: * The latest version is available at http://proxool.sourceforge.net
05: */
06: package org.logicalcobwebs.proxool.admin;
07:
08: import org.apache.commons.logging.Log;
09: import org.logicalcobwebs.proxool.ProxoolConstants;
10:
11: import java.text.DateFormat;
12: import java.text.DecimalFormat;
13: import java.text.SimpleDateFormat;
14:
15: /**
16: * Listens to statistics and logs them
17: * @version $Revision: 1.3 $, $Date: 2006/01/18 14:39:57 $
18: * @author bill
19: * @author $Author: billhorsman $ (current maintainer)
20: * @since Proxool 0.7
21: */
22: public class StatisticsLogger implements StatisticsListenerIF {
23:
24: private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat(
25: "0.00");
26:
27: private static final DateFormat TIME_FORMAT = new SimpleDateFormat(
28: "HH:mm:ss");
29:
30: private Log log;
31:
32: private String logLevel;
33:
34: public StatisticsLogger(Log log, String logLevel) {
35: this .log = log;
36: this .logLevel = logLevel;
37: }
38:
39: public void statistics(String alias, StatisticsIF statistics) {
40:
41: if (statistics != null && logLevel != null) {
42:
43: StringBuffer out = new StringBuffer();
44:
45: out.append(TIME_FORMAT.format(statistics.getStartDate()));
46: out.append(" - ");
47: out.append(TIME_FORMAT.format(statistics.getStopDate()));
48: out.append(", s:");
49: out.append(statistics.getServedCount());
50: out.append(":");
51: out.append(DECIMAL_FORMAT.format(statistics
52: .getServedPerSecond()));
53:
54: out.append("/s, r:");
55: out.append(statistics.getRefusedCount());
56: out.append(":");
57: out.append(DECIMAL_FORMAT.format(statistics
58: .getRefusedPerSecond()));
59:
60: out.append("/s, a:");
61: out.append(DECIMAL_FORMAT.format(statistics
62: .getAverageActiveTime()));
63: out.append("ms/");
64: out.append(DECIMAL_FORMAT.format(statistics
65: .getAverageActiveCount()));
66:
67: if (logLevel
68: .equals(ProxoolConstants.STATISTICS_LOG_LEVEL_TRACE)) {
69: log.trace(out.toString());
70: } else if (logLevel
71: .equals(ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG)) {
72: log.debug(out.toString());
73: } else if (logLevel
74: .equals(ProxoolConstants.STATISTICS_LOG_LEVEL_INFO)) {
75: log.info(out.toString());
76: }
77:
78: }
79:
80: }
81: }
82:
83: /*
84: Revision history:
85: $Log: StatisticsLogger.java,v $
86: Revision 1.3 2006/01/18 14:39:57 billhorsman
87: Unbundled Jakarta's Commons Logging.
88:
89: Revision 1.2 2003/03/03 11:11:59 billhorsman
90: fixed licence
91:
92: Revision 1.1 2003/02/19 23:36:51 billhorsman
93: renamed monitor package to admin
94:
95: Revision 1.1 2003/02/07 14:16:46 billhorsman
96: support for StatisticsListenerIF
97:
98: */
|