11package in .erail .route ;
22
3+ import com .codahale .metrics .Meter ;
4+ import com .codahale .metrics .Metered ;
35import com .codahale .metrics .MetricRegistry ;
46import com .codahale .metrics .Timer ;
57import com .google .common .base .Strings ;
3335public class OpenAPI3RouteBuilder extends AbstractRouterBuilderImpl {
3436
3537 private static final String AUTHORIZATION_PREFIX = "realm" ;
38+ private static final String FAIL_SUFFIX = ".fail" ;
3639 private ServiceArray mServices ;
3740 private File mOpenAPI3File ;
3841 private DeliveryOptions mDeliveryOptions ;
3942 private boolean mSecurityEnable = true ;
40- private HashMap <String , Timer > mMetricTimers = new HashMap <>();
43+ private HashMap <String , Metered > mMetrics = new HashMap <>();
4144 private MetricRegistry mMetricRegistry ;
4245
4346 public File getOpenAPI3File () {
@@ -64,16 +67,19 @@ public void start() {
6467 .stream ()
6568 .forEach ((api ) -> {
6669 RESTService service = (RESTService ) api ;
67- getMetricTimers ().put (service .getServiceUniqueId (),
68- getMetricRegistry ().timer ("api.framework.service." + service .getServiceUniqueId ())
69- );
70+ getMetrics ()
71+ .put (service .getServiceUniqueId (),
72+ getMetricRegistry ().timer ("api.framework.service." + service .getServiceUniqueId ()));
73+ getMetrics ()
74+ .put (service .getServiceUniqueId () + FAIL_SUFFIX ,
75+ getMetricRegistry ().meter ("api.framework.service." + service .getServiceUniqueId () + FAIL_SUFFIX ));
7076 });
7177
7278 }
7379
7480 public void process (RoutingContext pRequestContext , String pServiceUniqueId ) {
7581
76- Timer .Context timerCtx = getMetricTimers () .get (pServiceUniqueId ).time ();
82+ Timer .Context timerCtx = (( Timer ) getMetrics () .get (pServiceUniqueId ) ).time ();
7783
7884 getVertx ()
7985 .eventBus ()
@@ -85,6 +91,7 @@ public void process(RoutingContext pRequestContext, String pServiceUniqueId) {
8591 JsonObject response = (JsonObject ) reply .result ().body ();
8692 buildResponseFromReply (response , pRequestContext ).end ();
8793 } else {
94+ ((Meter ) getMetrics ().get (pServiceUniqueId + FAIL_SUFFIX )).mark ();
8895 getLog ().error (() -> "Error in reply:" + reply .cause ().toString ());
8996 pRequestContext
9097 .response ()
@@ -238,12 +245,12 @@ public void setOpenAPI3JSON(JsonObject pOpenAPI3JSON) {
238245 }
239246 }
240247
241- public HashMap <String , Timer > getMetricTimers () {
242- return mMetricTimers ;
248+ public HashMap <String , Metered > getMetrics () {
249+ return mMetrics ;
243250 }
244251
245- public void setMetricTimers (HashMap <String , Timer > pMetricTimers ) {
246- this .mMetricTimers = pMetricTimers ;
252+ public void setMetrics (HashMap <String , Metered > pMetrics ) {
253+ this .mMetrics = pMetrics ;
247254 }
248255
249256 public MetricRegistry getMetricRegistry () {
0 commit comments