Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
ExampleInvocationListener.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.engine.e1.collector.invocation;
2 
3 import com.griddynamics.jagger.engine.e1.Provider;
4 import com.griddynamics.jagger.engine.e1.collector.AvgMetricAggregatorProvider;
5 import com.griddynamics.jagger.engine.e1.collector.MaxMetricAggregatorProvider;
6 import com.griddynamics.jagger.engine.e1.collector.MetricDescription;
7 import com.griddynamics.jagger.engine.e1.collector.MinMetricAggregatorProvider;
8 import com.griddynamics.jagger.engine.e1.collector.PercentileAggregatorProvider;
9 import com.griddynamics.jagger.engine.e1.collector.invocation.InvocationInfo;
10 import com.griddynamics.jagger.engine.e1.collector.invocation.InvocationListener;
11 import com.griddynamics.jagger.engine.e1.services.ServicesAware;
12 import com.griddynamics.jagger.invoker.InvocationException;
13 
22 public class ExampleInvocationListener extends ServicesAware implements Provider<InvocationListener> {
23 
24  private final String metricName = "example-duration-metric";
25 
26  @Override
27  protected void init() {
28 
29  //begin: following section is used for docu generation - example of the metric with multiple aggregators
30  getMetricService().createMetric(new MetricDescription(metricName)
31  .displayName("Example duration metric, ms")
32  .showSummary(true)
33  .plotData(true)
34  .addAggregator(new MinMetricAggregatorProvider())
35  .addAggregator(new MaxMetricAggregatorProvider())
36  .addAggregator(new AvgMetricAggregatorProvider())
37  .addAggregator(new PercentileAggregatorProvider(40D))
38  .addAggregator(new PercentileAggregatorProvider(50D))
39  .addAggregator(new PercentileAggregatorProvider(60D))
40  .addAggregator(new PercentileAggregatorProvider(70D))
41  .addAggregator(new PercentileAggregatorProvider(80D))
42  .addAggregator(new PercentileAggregatorProvider(90D))
43  .addAggregator(new PercentileAggregatorProvider(95D))
44  .addAggregator(new PercentileAggregatorProvider(99D))
45  );
46  //end: following section is used for docu generation - example of the metric with multiple aggregators
47  }
48 
49  @Override
50  public InvocationListener provide() {
51  return new InvocationListener() {
52  @Override
53  public void onStart(InvocationInfo invocationInfo) { }
54 
55  @Override
56  public void onSuccess(InvocationInfo invocationInfo) {
57  if (invocationInfo.getResult() != null) {
58  getMetricService().saveValue(metricName, invocationInfo.getDuration());
59  }
60  }
61 
62  @Override
63  public void onFail(InvocationInfo invocationInfo, InvocationException e) { }
64 
65  @Override
66  public void onError(InvocationInfo invocationInfo, Throwable error) { }
67  };
68  }
69 }