public Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { Timeable timeable = map.get(pjp.getTarget()); if (timeable == null) { return pjp.proceed(); } EventMetricCollector collector = timer.getCollector(); try { collector.startTiming(timeable, pjp.getSignature().getName()); return pjp.proceed(); } finally { collector.stopTiming(); } }
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (shouldMonitorBean(bean, beanName)) { eventTimer.registerTimeable((Timeable) bean, beanName); } return bean; }
private EventCounters getCounterSet(String eventGroup) { EventMetricCounters invocationCounter = createEventMetricCounters(eventGroup, "count", "Total number of times the event was directly triggered", ONE); EventCounters counters = new EventCounters(invocationCounter, cleanName(eventGroup)); for (ThreadMetric metric : metricSuite.metrics()) { EventMetricCounters timingCounter = createEventMetricCounters(eventGroup, metric .getCounterSuffix(), metric.getDescription(), metric.getUnit()); counters.addMetric(metric, timingCounter); } return counters; }
private EventMetricCounters createEventMetricCounters(String beanName, String metric, String metricDescription, Unit<?> unit) { MonitoredCounter metricCounter = createMetric(beanName, metric, metricDescription + " [" + beanName + "]", unit); MonitoredCounter totalCounter; totalCounter = totalCountersAcrossEvents.get(metric); if (totalCounter == null) { totalCounter = new MonitoredCounter(getTotalMetricName(metric), metricDescription + " [TOTAL]", registry, unit); totalCountersAcrossEvents.put(metric, totalCounter); } return new EventMetricCounters(metricCounter, totalCounter); }
@Test public void testValuesConvertedToStringsForExport() { ThreadContext context = new ThreadContext(); context.put("stringvalue", "floop"); context.put("intvalue", 99); Timeable t = new Timeable() { @Override public void setEventTimer(EventTimer timer) { } }; EventTimer timer = new EventTimer("foo", new MonitorableRegistry(), ThreadMetricSuite.blank(), false, false, Collections.<StepMeasurementSink>singletonList(new LoggerSink())); timer.registerTimeable(t, "foo"); timer.getCollector().startTiming(t, "stuff"); InProgressSnapshot snapshot = InProgressSnapshot.capture(timer, context); TabularData data = JmxInProgressMonitor.TO_TABULAR_DATA.apply(snapshot); assertEquals(SimpleType.STRING, data.getTabularType().getRowType().getType("stringvalue")); assertEquals(SimpleType.STRING, data.getTabularType().getRowType().getType("intvalue")); }
public void testTotalMonitoredCounterSize() { metricFactory.registerTimeable(workflowWizardControl, "/WorkFlowWizard"); /** * This total value includes the invocation count counter, which is stored separately to the * other counters in the counter set object. So when comparing the number of counters for * each event, this should not be taken into consideration. */ Integer totalEventCounterSize = metricFactory.getNumberOfTotalEventCounters(); EventCounters wizardCounterSet = metricFactory .getCounterSetForEventGroup(workflowWizardControl); Integer numberOfMetricCounters = wizardCounterSet.numberOfTimerCounters(); assertEquals("Should be the same number of per event and total counters", --totalEventCounterSize, numberOfMetricCounters); metricFactory.registerTimeable(logonControl, "/Logon"); assertEquals( "Number of total event counters should not change after adding event", ++totalEventCounterSize, metricFactory.getNumberOfTotalEventCounters()); EventCounters logonCounterSet = metricFactory .getCounterSetForEventGroup(logonControl); assertEquals("Should be the same number of per event and total counters", --totalEventCounterSize, logonCounterSet.numberOfTimerCounters()); metricFactory.registerTimeable(attachmentControl, "/Attachments"); assertEquals( "Number of total event counters should not change after adding event", ++totalEventCounterSize, metricFactory.getNumberOfTotalEventCounters()); EventCounters attachmentCounterSet = metricFactory .getCounterSetForEventGroup(attachmentControl); assertEquals("Should be the same number of per event and total counters", --totalEventCounterSize, attachmentCounterSet.numberOfTimerCounters()); }
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(); }
public void testTotalMonitoredCounterSingletons() { metricFactory.registerTimeable(logonControl, "/Logon"); metricFactory.registerTimeable(workflowWizardControl, "/WorkflowWizard"); metricFactory.registerTimeable(attachmentControl, "/Attachments"); EventCounters wizardCounterSet = metricFactory.getCounterSetForEventGroup(workflowWizardControl); EventCounters logonCounterSet = metricFactory.getCounterSetForEventGroup(logonControl); EventCounters attachmentsCounterSet = metricFactory .getCounterSetForEventGroup(attachmentControl); assertNotNull("Couldnt obtain counter set for workflow wizard event", wizardCounterSet); assertNotNull("Couldnt obtain counter set for logon event", logonCounterSet); assertNotNull("Couldnt obtain counter set for attachments event", attachmentsCounterSet); for (ThreadMetric metric : wizardCounterSet.getMetrics().keySet()) { EventMetricCounters wizardCounter = wizardCounterSet.getMetrics().get(metric); assertNotNull("Couldnt obtain wizard counter for metric " + metric.getMetricName(), wizardCounter); EventMetricCounters logonCounter = logonCounterSet.getMetrics().get(metric); assertNotNull("Couldnt obtain logon counter for metric " + metric.getMetricName(), logonCounter); EventMetricCounters attachmentsCounter = attachmentsCounterSet.getMetrics() .get(metric); assertNotNull( "Couldnt obtain attachments counter for metric " + metric.getMetricName(), attachmentsCounter); assertEquals("Total counter for metric " + metric + " is not a singleton", wizardCounter.getTotalCounter(), logonCounter.getTotalCounter()); assertEquals("Total counter for metric " + metric + " is not a singleton", logonCounter .getTotalCounter(), attachmentsCounter.getTotalCounter()); } }
classes.add(String.class); for (ThreadMetric metric : timer.getMetricSuite().metrics()) { names.add(metric.getMetricName()); descriptions.add(metric.getDescription()); for (Map.Entry<Thread, EventMetricCollector> entry : timer.getCollectorThreadMap() .entrySet()) { StepMeasurements m = entry.getValue().getInProgressMeasurements(); keyedValues.put("Thread ID", entry.getKey().getId()); keyedValues.put("Event", event); for (ThreadMetric metric : timer.getMetricSuite().metrics()) { keyedValues.put(metric.getMetricName(), snapshotValues.get(metric)); LOG.trace(String.format("Thread %s in event %s, metric %s has value %s", entry
private void initEvents() { metricFactory = new EventTimer("test", new MonitorableRegistry(), ThreadMetricSuite .withDefaultMetrics(), true, true, Collections.<StepMeasurementSink>singletonList(new LoggerSink())); workflowWizardControl = new DummyTimeable(); logonControl = new DummyTimeable(); attachmentControl = new DummyTimeable(); }
private String getMetricName(String eventGroup, String metric) { return prefix + "." + cleanName(eventGroup) + "." + metric; }
@Override public void handleMessage(XMLMessage message) throws Fault { Exchange exchange = message.getExchange(); // TODO break out into a strategy (not JAXRS-specific) OperationResourceInfo operationResourceInfo = exchange.get(OperationResourceInfo.class); if (operationResourceInfo == null) { message.getInterceptorChain().doIntercept(message); return; } // TODO annotate with a better name? String methodName = operationResourceInfo.getMethodToInvoke().getName(); // TODO annotate with a better name? Object key = operationResourceInfo.getClassResourceInfo().getResourceProvider() .getInstance(); if (!(key instanceof Timeable)) { message.getInterceptorChain().doIntercept(message); return; } EventMetricCollector collector = timer.getCollector(); collector.startTiming((Timeable) key, methodName); try { message.getInterceptorChain().doIntercept(message); } finally { collector.stopTiming(); } } }
@Override public void addAdvised(Object advised, String name) { DummyTimeable timeable = new DummyTimeable(); timer.registerTimeable(timeable, name); map.put(advised, timeable); } }
@Override public void run() { EventMetricCollector collector = timer.getCollector(); for (int i = 1; i < 30; i++) { try { context.put("Name", randomName()); context.put("Company", randomCompany()); collector.startTiming(this, action); doJob(i); collector.pauseForForward(); collector.startTiming(this, "frog"); collector.stopTiming(); collector.resumeAfterForward(); collector.stopTiming(); context.remove("Name"); context.remove("Company"); } catch (Exception e) { throw new RuntimeException(e); } } }