public Counter createCounterPair(Unit<?> unit, String globalCounterName, String threadMetricName, String threadMetricSuffix, String description) { MonitoredCounter metric = new MonitoredCounter(globalCounterName, description, registry, unit); ThreadCounter threadCounter = new ThreadCounter.ThreadMapCounter(); ThreadMetric threadMetric = new ThreadValueMetric(threadMetricName, unit, threadMetricSuffix, description, threadCounter); metricSuite.addMetric(threadMetric); return new CounterPair(metric, threadCounter); }
public static void main(String[] args) throws InterruptedException { ThreadMetricSuite suite = ThreadMetricSuite.blank(); suite.addMetric(StandardThreadMetrics.CLOCK_TIME); suite.addMetric(StandardThreadMetrics.BLOCKED_TIME); suite.addMetric(StandardThreadMetrics.WAITED_TIME); suite.addMetric(StandardThreadMetrics.USER_CPU_TIME); EventTimer timer = new EventTimer("blah", new MonitorableRegistry(), suite, true, true, Collections.<StepMeasurementSink>singletonList(new LoggerSink())); ThreadContext context = new ThreadContext(); EmailSender sender = new EmailSender(context); CheckoutBuyer buyer = new CheckoutBuyer(context); timer.registerTimeable(sender, "sendEmail"); timer.registerTimeable(buyer, "buySomething"); Thread t1 = new Thread(sender); Thread t2 = new Thread(buyer); t1.start(); t2.start(); InProgressExporter exporter = new InProgressExporter(timer, context); for (int i = 1; i <= 5; i++) { Thread.sleep(5000); InProgressSnapshot snapshot = exporter.getSnapshot(); System.out.println(snapshot.asFormattedString()); } t1.join(); t2.join(); }