1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.dataretrievers;
22
23 import org.apache.log4j.Logger;
24
25 import com.ebay.carad.os.vitalsigns.util.ITimeConstants;
26
27 /***
28 * <p>Takes a difference query, and logs its value as a rate per time period. The
29 * time period is specified in minutes, via the constructor.</p>
30 *
31 * <p>Data that is logged = <tt>CurrentCount / (System.currentTimeMillis() - lastTimeStamp) * millisPerInterval</tt>
32 *
33 * @author Jeremy Kraybill
34 * @author Jeremy Thomerson
35 * @version $Id$
36 */
37 public class DifferenceQueryRateLogger extends DifferenceQueryLogger {
38
39 /*** Class logger. */
40 private static final Logger LOGGER = Logger.getLogger(DifferenceQueryRateLogger.class);
41
42 private long millisPer = -1;
43 private long lastTick = -1;
44
45 /***
46 * Basic constructor.
47 */
48 public DifferenceQueryRateLogger() {
49 super();
50 }
51
52 /***
53 * Sets the number of minutes to calculate rate against. For instance, if you want to log
54 * this data as a rate per minute, minsPerTick should be 1; per hour, 60; etc.
55 *
56 * @param minsPerTick the number of minutes per interval
57 */
58 public void setMinsPerTick(int minsPerTick) {
59 millisPer = minsPerTick * ITimeConstants.MINUTE;
60 }
61
62 /***
63 * @see DifferenceQueryRateLogger class comment for details
64 * @see com.ebay.carad.os.vitalsigns.dataretrievers.QueryLogger#getData()
65 */
66 public Float getData() {
67 Float curVal = null;
68 try {
69 curVal = getValue();
70 if (curVal != null) {
71 curVal = new Float(curVal.floatValue() / (System.currentTimeMillis() - lastTick) * millisPer);
72 }
73 lastTick = System.currentTimeMillis();
74 } catch (Exception e) {
75 LOGGER.error(e);
76 }
77 return curVal;
78 }
79 }