86 return new InvocationListener() {
88 public void onStart(InvocationInfo invocationInfo) { }
91 public void onSuccess(InvocationInfo invocationInfo) {
92 if (invocationInfo.getResult() != null) {
93 JHttpUserScenarioInvocationResult invocationResult = ((JHttpUserScenarioInvocationResult) invocationInfo.getResult());
94 List<JHttpUserScenarioStepInvocationResult> stepInvocationResults = invocationResult.getStepInvocationResults();
95 String scenarioId = generateScenarioId(invocationResult.getScenarioId());
98 if (!createdMetrics.contains(scenarioId)) {
99 createdMetrics.add(scenarioId);
100 createScenarioMetricDescriptions(scenarioId, invocationResult.getScenarioDisplayName());
102 getMetricService().saveValue(generateMetricId(scenarioId, ITERATION_SAMPLES_ID), 1);
103 getMetricService().saveValue(generateMetricId(scenarioId, LATENCY_ID),
104 invocationInfo.getDuration() / 1000.0);
105 getMetricService().saveValue(generateMetricId(scenarioId, SUCCESS_RATE_ID), invocationResult.getSucceeded() ? 1 : 0);
109 Integer stepIndex = 1;
110 for (JHttpUserScenarioStepInvocationResult stepResult : stepInvocationResults) {
111 String scenarioStepId = generateScenarioStepId(invocationResult.getScenarioId(), stepResult.getStepId(), stepIndex);
112 if (!createdMetrics.contains(scenarioStepId)) {
113 createdMetrics.add(scenarioStepId);
114 createScenarioStepMetricDescriptions(scenarioStepId,String.format(
"%02d. %s ", stepIndex, stepResult.getStepDisplayName()));
116 getMetricService().saveValue(generateMetricId(scenarioStepId, LATENCY_ID),
117 stepResult.getLatency().doubleValue() / 1000);
118 getMetricService().saveValue(generateMetricId(scenarioStepId, SUCCESS_RATE_ID), stepResult.getSucceeded() ? 1 : 0);
119 getMetricService().saveValue(generateMetricId(scenarioStepId, ITERATION_SAMPLES_ID), 1);
126 private void createScenarioMetricDescriptions(String scenarioId, String scenarioDisplayName) {
127 getMetricService().createMetric(
128 new MetricDescription(generateMetricId(scenarioId, ITERATION_SAMPLES_ID)).
129 displayName(generateMetricDisplayName(scenarioDisplayName, ITERATIONS_SAMPLES)).
130 addAggregator(SUM_AGGREGATOR));
132 getMetricService().createMetric(
133 new MetricDescription(generateMetricId(scenarioId, LATENCY_ID)).
134 displayName(generateMetricDisplayName(scenarioDisplayName, LATENCY_SEC)).
135 addAggregator(AVG_AGGREGATOR));
137 getMetricService().createMetric(
138 new MetricDescription(generateMetricId(scenarioId, SUCCESS_RATE_ID)).
139 displayName(generateMetricDisplayName(scenarioDisplayName, SUCCESS_RATE)).
141 addAggregator(SUCCESS_AGGREGATOR).
142 addAggregator(FAILS_AGGREGATOR));
145 private void createScenarioStepMetricDescriptions(String scenarioStepId, String scenarioStepDisplayName) {
146 MetricDescription metricDescription =
147 new MetricDescription(generateMetricId(scenarioStepId,LATENCY_ID)).
148 displayName(generateMetricDisplayName(scenarioStepDisplayName,LATENCY_SEC))
150 if (latencyAggregatorProviders.isEmpty())
151 latencyAggregatorProviders.addAll(newHashSet(MAX_AGGREGATOR, MIN_AGGREGATOR, STD_DEV_AGGREGATOR, AVG_AGGREGATOR));
152 latencyAggregatorProviders.forEach(metricDescription::addAggregator);
153 getMetricService().createMetric(metricDescription);
155 getMetricService().createMetric(
156 new MetricDescription(generateMetricId(scenarioStepId, ITERATION_SAMPLES_ID)).
157 displayName(generateMetricDisplayName(scenarioStepDisplayName, ITERATIONS_SAMPLES)).
158 addAggregator(SUM_AGGREGATOR));
160 getMetricService().createMetric(
161 new MetricDescription(generateMetricId(scenarioStepId, SUCCESS_RATE_ID)).
162 displayName(generateMetricDisplayName(scenarioStepDisplayName, SUCCESS_RATE)).
164 addAggregator(SUCCESS_AGGREGATOR).
165 addAggregator(FAILS_AGGREGATOR));
169 public void onFail(InvocationInfo invocationInfo, InvocationException e) {
174 public void onError(InvocationInfo invocationInfo, Throwable error) {