MonitoringHandler { public void updateRequestPerRuleMonitoring(HttpServerRequest request, String metricName){ if(isRequestPerRuleMonitoringActive()){ String headerValue = StringUtils.getStringOrDefault(request.getHeader(requestPerRuleMonitoringProperty), UNKNOWN_VALUE); if(StringUtils.isNotEmptyTrimmed(metricName)){ String key = headerValue + "." + metricName; getRequestPerRuleMonitoringMap().merge(key, 1L, (oldValue, one) -> oldValue + one); } else { Logger requestlog = RequestLoggerFactory.getLogger(MonitoringHandler.class, request); requestlog.warn("Request per rule monitoring is active but was called without a rule metricName. This request will be ignored."); } } } @Deprecated  MonitoringHandler(Vertx vertx, RedisClient redisClient, final ResourceStorage storage, String prefix); @Deprecated  MonitoringHandler(Vertx vertx, RedisClient redisClient, final ResourceStorage storage, String prefix, String requestPerRulePath);  MonitoringHandler(Vertx vertx, final ResourceStorage storage, String prefix);  MonitoringHandler(Vertx vertx, final ResourceStorage storage, String prefix, String requestPerRulePath); String getRequestPerRuleMonitoringPath(); boolean isRequestPerRuleMonitoringActive(); long getRequestPerRuleSampling(); long getRequestPerRuleExpiry(); void updateIncomingRequests(HttpServerRequest request); void updateRequestPerRuleMonitoring(HttpServerRequest request, String metricName); void updateRequestsMeter(String target, String uri); long startRequestMetricTracking(final String metricName, String targetUri); void stopRequestMetricTracking(final String metricName, long startTime, String targetUri); void updateQueueCountInformation(); void updateLastUsedQueueSizeInformation(final String queue); void updateQueuesSizesInformation(final int numQueues, final boolean showEmptyQueues, final MonitoringCallback callback); void updateEnqueue(); void updateDequeue(); void updateListenerCount(long count); void updateRoutesCount(long count); static final String METRIC_NAME; static final String METRIC_ACTION; static final String MARK; static final String SET; static final String REQUESTS_CLIENT_NAME; static final String REQUESTS_BACKENDS_NAME; static final String PENDING_REQUESTS_METRIC; static final String ACTIVE_QUEUE_COUNT_METRIC; static final String LAST_USED_QUEUE_SIZE_METRIC; static final String ENQUEUE_METRIC; static final String DEQUEUE_METRIC; static final String LISTENER_COUNT_METRIC; static final String ROUTE_COUNT_METRIC; @Deprecated
    static final String QUEUES_KEY_PREFIX; @Deprecated
    static final int MAX_AGE_MILLISECONDS; static final String REQUEST_PER_RULE_PREFIX; static final String REQUEST_PER_RULE_PROPERTY; static final String REQUEST_PER_RULE_SAMPLING_PROPERTY; static final String REQUEST_PER_RULE_EXPIRY_PROPERTY; static final long REQUEST_PER_RULE_DEFAULT_SAMPLING; static final long REQUEST_PER_RULE_DEFAULT_EXPIRY; }
@Test public void testConsumeMonitoringAddress(TestContext testContext){ Async async = testContext.async(); activateRequestPerRuleMonitoring(true); System.setProperty(MonitoringHandler.REQUEST_PER_RULE_SAMPLING_PROPERTY, "100"); MonitoringHandler mh = new MonitoringHandler(vertx, storage, PREFIX); PUTRequest request = new PUTRequest(); request.addHeader(PROPERTY_NAME, "my_value_123"); mh.updateRequestPerRuleMonitoring(request, "a_fancy_rule"); vertx.eventBus().consumer(Address.monitoringAddress(), (Handler<Message<JsonObject>>) message -> { final JsonObject body = message.body(); testContext.assertEquals("gateleen.rpr.my_value_123.a_fancy_rule", body.getString("name")); async.complete(); }); }
@Test public void testWriteRequestPerRuleMonitoringToStorage(){ activateRequestPerRuleMonitoring(true); System.setProperty(MonitoringHandler.REQUEST_PER_RULE_SAMPLING_PROPERTY, "100"); MonitoringHandler mh = new MonitoringHandler(vertx, storage, PREFIX, REQUEST_PER_RULE_MONITORING_PATH); PUTRequest request = new PUTRequest(); request.addHeader(PROPERTY_NAME, "my_value_123"); mh.updateRequestPerRuleMonitoring(request, "a_fancy_rule"); await().atMost(Duration.ONE_SECOND).until(storageContainsData("my_value_123.a_fancy_rule")); }