private void updateRequestSizeHistogram(String topic, int length) {
    requestSizeHistogramGlobal.update(length);

    if (!requestSizeHistogramByTopic.containsKey(topic)) {
      Histogram requestSizeHistogram =
          HermesMetricsRegistry.getMetricRegistry()
              .histogram(
                  MetricRegistry.name(
                      SubscriptionPushService.class, "SubscriptionPushService", topic, "BodySize"));
      requestSizeHistogramByTopic.put(topic, requestSizeHistogram);
    }

    Histogram requestSizeHistogram = requestSizeHistogramByTopic.get(topic);
    requestSizeHistogram.update(length);
  }
  @Test
  public void testHistogramDisabled() {
    // create timer with id "testMetricAlerts" and register with metric registry, bump up value to
    // 4.
    Histogram h =
        MetricsConfigurator.createHistogram5Min(
            metrics, "testHistogramDisabled", PIPELINE_NAME, REVISION);
    h.update(1000);

    MetricsRuleDefinition metricsRuleDefinition =
        new MetricsRuleDefinition(
            "testHistogramDisabled",
            "testHistogramDisabled",
            "testHistogramDisabled",
            MetricType.HISTOGRAM,
            MetricElement.HISTOGRAM_COUNT,
            "${value()==1}",
            false,
            false);
    MetricRuleEvaluator metricRuleEvaluator =
        new MetricRuleEvaluator(
            metricsRuleDefinition,
            metrics,
            new AlertManager(
                PIPELINE_NAME, REVISION, null, metrics, runtimeInfo, new EventListenerManager()),
            Collections.<String>emptyList());
    metricRuleEvaluator.checkForAlerts();

    // get alert gauge
    Gauge<Object> gauge =
        MetricsConfigurator.getGauge(
            metrics, AlertsUtil.getAlertGaugeName(metricsRuleDefinition.getId()));
    Assert.assertNull(gauge);
  }
Example #3
0
 private void serializeEnum(BluefloodEnumRollup rollup, byte[] buf) throws IOException {
   CodedOutputStream out = CodedOutputStream.newInstance(buf);
   enumRollupSize.update(buf.length);
   out.writeRawByte(Constants.VERSION_1_ENUM_ROLLUP);
   out.writeRawVarint32(rollup.getCount());
   Map<Long, Long> enValues = rollup.getHashedEnumValuesWithCounts();
   for (Long i : enValues.keySet()) {
     out.writeRawVarint64(i);
     out.writeRawVarint64(enValues.get(i));
   }
 }
 @Override
 public void run() {
   samplerLock.lock();
   try {
     for (Histogram histogram : schedulerHistogramList) {
       Timer timer = histogramTimerMap.get(histogram);
       histogram.update((int) timer.getSnapshot().getMean());
     }
   } finally {
     samplerLock.unlock();
   }
 }
Example #5
0
  @Test
  public void testHistogram() {
    System.out.println("******************************* HISTOGRAM *******************************");
    histogram = registry.histogram("histogram");
    try {
      for (int i = 0; i < ITER_COUNT; i++) {
        histogram.update(i);
        Thread.sleep(SLEEP_MS);
      }

    } catch (InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
  }
  @Test
  public void testHistogram() {
    final Histogram histogram = registry.histogram(name("foo", "bar"));
    histogram.update(20);
    histogram.update(40);
    reportAndRefresh();

    SearchResponse searchResponse =
        client().prepareSearch(indexWithDate).setTypes("histogram").execute().actionGet();
    org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()).isEqualTo(1L);

    Map<String, Object> hit = searchResponse.getHits().getAt(0).sourceAsMap();
    assertTimestamp(hit);
    assertKey(hit, "name", prefix + ".foo.bar");
    assertKey(hit, "count", 2);
    assertKey(hit, "max", 40);
    assertKey(hit, "min", 20);
    assertKey(hit, "mean", 30.0);
    assertKey(hit, "host", "localhost");
  }
 @Override
 public final AttributeSet resolve(ResolverContext context) throws Exception {
   checkArgument(context.getDescriptor().getId().equals(descriptor.getId()));
   if (log.isDebugEnabled()) {
     log.debug(
         "Retrieving attributes via resolver id=\"{}\" name=\"{}\"",
         descriptor.getId(),
         descriptor.getName());
   }
   Timer.Context timerCtx = timer.time();
   try {
     return AttributeSet.builder(descriptor)
         .attributes(doResolve(context))
         .ticker(context.getTicker())
         .build();
   } catch (Exception e) {
     if (log.isDebugEnabled()) {
       log.debug(e.getMessage(), e);
     }
     throw e;
   } finally {
     histogram.update(timerCtx.stop());
   }
 }
  /** Submit results to index and return the queue messages to be ack'd */
  private List<QueueMessage> submitToIndex(List<IndexEventResult> indexEventResults) {

    // if nothing came back then return empty list
    if (indexEventResults == null) {
      return new ArrayList<>(0);
    }

    IndexOperationMessage combined = new IndexOperationMessage();
    List<QueueMessage> queueMessages =
        indexEventResults
            .stream()

            // filter out messages that are not present, they were not processed and put into the
            // results
            .filter(result -> result.getQueueMessage().isPresent())
            .map(
                indexEventResult -> {

                  // record the cycle time
                  messageCycle.update(
                      System.currentTimeMillis() - indexEventResult.getCreationTime());

                  // ingest each index op into our combined, single index op for the index producer
                  if (indexEventResult.getIndexOperationMessage().isPresent()) {
                    combined.ingest(indexEventResult.getIndexOperationMessage().get());
                  }

                  return indexEventResult.getQueueMessage().get();
                })
            // collect into a list of QueueMessages that can be ack'd later
            .collect(Collectors.toList());

    queueIndexOperationMessage(combined);

    return queueMessages;
  }
 public void update(long value) {
   if (isEnable == true) {
     instance.update(value);
   }
 }
 /** {@inheritDoc} */
 @Override
 public void recordConnectionUsageMillis(final long elapsedBorrowedMillis) {
   connectionUsage.update(elapsedBorrowedMillis);
 }