Jagger
 All Classes Namespaces Files Functions Variables 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  getMetricService().createMetric(new MetricDescription(metricName)
29  .displayName("Example duration metric, ms")
30  .showSummary(true)
31  .plotData(true)
32  .addAggregator(new MinMetricAggregatorProvider())
33  .addAggregator(new MaxMetricAggregatorProvider())
34  .addAggregator(new AvgMetricAggregatorProvider())
35  .addAggregator(new PercentileAggregatorProvider(40D))
36  .addAggregator(new PercentileAggregatorProvider(50D))
37  .addAggregator(new PercentileAggregatorProvider(60D))
38  .addAggregator(new PercentileAggregatorProvider(70D))
39  .addAggregator(new PercentileAggregatorProvider(80D))
40  .addAggregator(new PercentileAggregatorProvider(90D))
41  .addAggregator(new PercentileAggregatorProvider(95D))
42  .addAggregator(new PercentileAggregatorProvider(99D))
43  )
44  ;
45  }
46 
47  @Override
48  public InvocationListener provide() {
49  return new InvocationListener() {
50  @Override
51  public void onStart(InvocationInfo invocationInfo) { }
52 
53  @Override
54  public void onSuccess(InvocationInfo invocationInfo) {
55  if (invocationInfo.getResult() != null) {
56  getMetricService().saveValue(metricName, invocationInfo.getDuration());
57  }
58  }
59 
60  @Override
61  public void onFail(InvocationInfo invocationInfo, InvocationException e) { }
62 
63  @Override
64  public void onError(InvocationInfo invocationInfo, Throwable error) { }
65  };
66  }
67 }