Package com.netflix.servo.monitor

Examples of com.netflix.servo.monitor.Stopwatch


       
    }

    @Override
    public void publish(Object event) {
        Stopwatch start = stats.publishStats.start();
        try {
            if (!applyEventLevelFilters(event)) {
                return;
            }

            Set<Class<?>> allTypesForAnEvent = getAllTypesForAnEvent(event);
            for (Class<?> eventType : allTypesForAnEvent) {
                Set<EventConsumer> eventConsumers = consumersByEventType.get(eventType);
                for (EventConsumer eventConsumer : eventConsumers) {
                    eventConsumer.enqueue(event);
                }
            }
            if (null != catchAllSubInstance && catchAllSubInstance.isEnabled()) {
                catchAllSubscriber.enqueue(event);
            }
        } catch (Throwable th) {
            LOGGER.error("Error occured while publishing event. Swallowing the error to avoid publisher from failing.", th);
            stats.publishErrors.increment();
        } finally {
            start.stop();
        }
    }
View Full Code Here


        }
    }

    @Override
    public void publishIffNotDead(EventCreator creator, Class<?>... eventTypes) {
        Stopwatch start = stats.conditionalPublishStats.start();
        try {
            Map<Class<?>, Set<EventConsumer>> interestedConsumersByType = new HashMap<Class<?>, Set<EventConsumer>>();
            for (Class<?> eventType : eventTypes) {
                for (Class<?> anEventSubType : getAllTypesForAnEventType(eventType)) {
                    Set<EventConsumer> eventConsumers = consumersByEventType.get(anEventSubType);
                    if (!eventConsumers.isEmpty()) {
                        /*
                        * Since any change in the underlying consumers get reflected in this set, we get the benefit of any changes
                        * to the consumers after this check being reflected when we invoke these consumers.
                        * We add the evenType to the map and not the subType as the event creator is only aware of the high
                        * level types & not the entire hierarchy.
                        */
                        interestedConsumersByType.put(eventType, eventConsumers);
                    }
                }
            }

            if (interestedConsumersByType.isEmpty()) {
                LOGGER.debug(String.format("Skipping publishing of events types %s as there are no interested listeners.",
                                           Arrays.toString(eventTypes)));
                return;
            }

            List events = creator.createEvent(interestedConsumersByType.keySet());
            if (null == events) {
                LOGGER.debug(String.format("No events created by event creator for event types %s",
                        interestedConsumersByType.keySet()));
                return;
            }

            for (Object event : events) {
                if (!applyEventLevelFilters(event)) {
                    continue;
                }
                Set<EventConsumer> eventConsumers = interestedConsumersByType.get(event.getClass());
                for (EventConsumer eventConsumer : eventConsumers) {
                    eventConsumer.enqueue(event);
                }
            }
        } catch (Throwable th) {
            LOGGER.error("Error occured while publishing event. Swallowing the error to avoid publisher from failing.", th);
            stats.conditionalPublishErrors.increment();
        } finally {
            start.stop();
        }
    }
View Full Code Here

                                       delegateSubscriber.toGenericString(), SyncSubscribersGatekeeper.ALLOW_SYNC_SUBSCRIBERS));
            processEvent(event);
            return;
        }

        Stopwatch start = stats.enqueueStats.start();
        try {
            int retries = 0;
            int maxRetries = maxRetriesOnQueueFull.get();
            while (!eventQueue.offer(event) && retries++ < maxRetries) {
                stats.QUEUE_OFFER_RETRY_COUNTER.increment();
                eventQueue.nonBlockingTake(); // removes and rejects.
                LOGGER.info(String.format("Subscriber: %s queue full, rejected one %s as a result of retries.",
                        delegateSubscriber.toGenericString(),
                        (Subscribe.BatchingStrategy.None == batchingStrategy) ? "event" : "batch"));
            }

            if (0 != retries) {
                LOGGER.info(String.format("Subscriber: %s %s one event after %s retries.",
                        delegateSubscriber.toGenericString(),
                        ((retries >= maxRetries) ? "rejected" : "accepted"),
                        (retries - 1)));
                if (retries >= maxRetries) {
                    stats.EVENT_ENQUEUE_REJECTED_COUNTER.increment();
                }
            }

        } finally {
            start.stop();
        }
    }
View Full Code Here

    SubscriberConfigProvider.SubscriberConfig getSubscriberConfig() {
        return subscriberConfig;
    }

    private void processEvent(Object event) {
        Stopwatch start = stats.consumptionStats.start();

        event = wrapIfBatched(event);

        if (applyFilters(event)) {
            try {
                delegateSubscriber.invoke(subscriberClassInstance, event);
            } catch (Exception e) {
                LOGGER.error("Failed to dispatch event: " + event + " to subscriber class: " +
                             subscriberClassInstance.getClass() + " and method: " + delegateSubscriber.toGenericString() +
                             ". Ignoring the event.", e);
            } finally {
                start.stop();
            }
        }
    }
View Full Code Here

    public static boolean applyFilters(Object event, Set<EventFilter> filters, StatsTimer filterStats,
                                       String invokerDesc, Logger logger) {
        if (filters.isEmpty()) {
            return true;
        }
        Stopwatch filterStart = filterStats.start();
        try {
            for (EventFilter filter : filters) {
                if (!filter.apply(event)) {
                    logger.debug(
                            "Event: " + event + " filtered out for : " + invokerDesc + " due to the filter: " + filter);
                    return false;
                }
            }
            return true;
        } finally {
            filterStart.stop();
        }
    }
View Full Code Here

    public void handle(HttpExchange exchange) throws IOException {
        CountingInputStream input = new CountingInputStream(exchange.getRequestBody());
        CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody());
        exchange.setStreams(input, output);
        Stopwatch stopwatch = latency.start();
        try {
            handleImpl(exchange);
        } finally {
            stopwatch.stop();
            bytesReceived.increment(input.getCount());
            bytesSent.increment(output.getCount());
        }
    }
View Full Code Here

  @GET
  @Path("/v1/logs/{key}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getLogs(final @PathParam("key") String key) {
    Stopwatch stopwatch = statsTimer.start();

    try {
      // increment request counter
      requestCounter.increment();

      // invoke service through Hystrix
      HystrixCommand<String> getCommand = new GetLogsCommand(key);
      Future<String> future = getCommand.queue();
      String responseString = future.get();

      // increment the fallback counter if the response came from a
      // fallback
      // TODO: this isn't needed as the hystrix framework exports its own
      // metrics on a per-command basis.
      // this is here for demo purposes.
      if (getCommand.isResponseFromFallback()) {
        fallbackCounter.increment();
      }

      // increment the timeout counter if the response timed out and
      // triggered fallback
      // TODO: this isn't needed as the hystrix framework exports its own
      // metrics on a per-command basis.
      // this is here for demo purposes.
      if (getCommand.isResponseTimedOut()) {
        timeoutCounter.increment();
      }

      // return response
      return Response.ok(responseString).build();
    } catch (Exception ex) {
      // add error counter
      errorCounter.increment();

      logger.error("Error processing the get request.", ex);

      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    } finally {
      stopwatch.stop();

      statsTimer.record(stopwatch.getDuration(TimeUnit.MILLISECONDS),
          TimeUnit.MILLISECONDS);
    }
  }
View Full Code Here

      throw new RuntimeException("Cannot decode log '" + log + "'", exc);
    }
  }
 
  private Response doAddLog(final String key, final String log) {
    Stopwatch stopwatch = statsTimer.start();

    try {
      // increment request counter
      requestCounter.increment();

      // invoke service through Hystrix
      HystrixCommand<String> getCommand = new AddLogCommand(key, log);
     
      Future<String> future = getCommand.queue();
     
      String responseString = future.get();

      // increment the fallback counter if the response came from a
      // fallback
      // TODO: this isn't needed as the hystrix framework exports its own
      // metrics on a per-command basis.
      // this is here for demo purposes.
      if (getCommand.isResponseFromFallback()) {
        fallbackCounter.increment();
      }

      // increment the timeout counter if the response timed out and
      // triggered fallback
      // TODO: this isn't needed as the hystrix framework exports its own
      // metrics on a per-command basis.
      // this is here for demo purposes.
      if (getCommand.isResponseTimedOut()) {
        timeoutCounter.increment();
      }

      // return response
      return Response.ok(responseString).build();
    } catch (Exception ex) {
      // add error counter
      errorCounter.increment();

      logger.error("Error processing the add request.", ex);

      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    } finally {
      stopwatch.stop();

      statsTimer.record(stopwatch.getDuration(TimeUnit.MILLISECONDS),
          TimeUnit.MILLISECONDS);
    }
  }
View Full Code Here

  public List<String> getLogs(String key) throws Exception {
        QueryRequest queryRequest = new QueryRequest()
                .withTableName(tableName.get())
                .withHashKeyValue(new AttributeValue(key));
       
        Stopwatch stopwatch = getLogsTimer.start();
       
        QueryResult result;
        try {
            // perform query
          result = dbClient.query(queryRequest);
        } finally {
            getLogsTimer.record(stopwatch.getDuration(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
        }
       
        List<String> logs = new ArrayList<String>(result.getCount());

        // prepend the total row count to the list
View Full Code Here

          .withTableName(tableName.get())
          .withItem(ImmutableMap.of(hashKeyName.get(), new AttributeValue(key),
                        rangeKeyName.get(), new AttributeValue(dateTimeStr),
                        valueName.get(), new AttributeValue(log)));
       
        Stopwatch stopwatch = addLogTimer.start();

        try {
          dbClient.putItem(putItemRequest);
        } finally {
          addLogTimer.record(stopwatch.getDuration(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
        }
       
        return dateTime;       
  }
View Full Code Here

TOP

Related Classes of com.netflix.servo.monitor.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.