01: /*
02: @license.text@
03: */
04: package com.pavelvlasov.metrics.sample;
05:
06: import java.util.Random;
07:
08: import org.apache.log4j.BasicConfigurator;
09: import org.apache.log4j.Level;
10: import org.apache.log4j.Logger;
11:
12: import biz.hammurapi.metrics.MeasurementCategoryFactory;
13: import biz.hammurapi.metrics.MeasurementConsumer;
14:
15: /**
16: * This program demonstrates indirect usage of MeasurementSinks
17: * through MeasurementSinkFactory.
18: * It produces random metrics with random interval and stores
19: * them to a database.
20: * @author Pavel Vlasov
21: *
22: * @version $Revision$
23: */
24: public class Boot {
25: static {
26: BasicConfigurator.configure();
27: Logger.getRootLogger().setLevel(Level.INFO);
28: }
29:
30: private static final MeasurementConsumer measurementSink = MeasurementCategoryFactory
31: .getCategory(Boot.class);
32:
33: public static void main(String[] args) throws Exception {
34: Random random = new Random(System.currentTimeMillis()
35: ^ Boot.class.hashCode());
36: for (int i = 0; i < 1000; i++) {
37: double rValue = i < 250 ? 0 : 0.2 * Math.random()
38: * Math.sin(i / 50.0) + Math.cos(i / 100.0);
39: long currentTimeMillis = System.currentTimeMillis();
40: // System.out.println(i+"["+currentTimeMillis+"] -> "+rValue);
41: measurementSink.addMeasurement("SimpleMetric", rValue,
42: currentTimeMillis);
43: if (rValue < 0.7) {
44: measurementSink.addMeasurement("Metric 2", i / 1000.0
45: + random.nextDouble() * Math.cos(i / 300.0),
46: currentTimeMillis);
47: }
48: Thread.sleep(random.nextInt(10) + 1);
49: }
50: // MeasurementCategoryFactory.shutdownBootSinks();
51: System.out.println("Done");
52: }
53: }
|