com.twitter.ostrich.stats.Stats Java Examples

The following examples show how to use com.twitter.ostrich.stats.Stats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TerrapinRoutingTableProvider.java    From terrapin with Apache License 2.0 6 votes vote down vote up
public TerrapinRoutingTableProvider(ZooKeeperManager zkManager,
                                    List<String> resourceList) {
  this.zkManager = zkManager;
  this.viewInfoRecordMap = Maps.newHashMapWithExpectedSize(resourceList.size());
  // Initialize the view info with what we have in zookeeper to avoid double writes.
  for (String resource : resourceList) {
    ViewInfo viewInfo = this.zkManager.getViewInfo(resource);
    if (viewInfo != null) {
      ViewInfoRecord viewInfoRecord = new ViewInfoRecord();
      viewInfoRecord.drained = true;
      viewInfoRecord.viewInfo = viewInfo;
      this.viewInfoRecordMap.put(resource, viewInfoRecord);
    } else {
      LOG.error("Compressed view is null on startup for " + resource);
      Stats.incr("compressed-view-init-errors");
    }
  }
}
 
Example #2
Source File: ElasticSearchHealthCheckJob.java    From soundwave with Apache License 2.0 6 votes vote down vote up
private void logNodeStats(Map<String, NodeStats> statsMap) {
  Map<String, String> tags = new HashMap<>();
  for (NodeStats stat : statsMap.values()) {
    tags.put("esnode", stat.getHostname());
    Stats.setGauge(StatsUtil.getStatsName("eshealth", "heapUsedPercent", tags),
        stat.getJvm().getMem().getHeapUsedPrecent());
    Stats.setGauge(StatsUtil.getStatsName("eshealth", "heapMaxMB", tags),
        stat.getJvm().getMem().getHeapMax().getMbFrac());
    Stats.setGauge(StatsUtil.getStatsName("eshealth", "heapUsedMB", tags),
        stat.getJvm().getMem().getHeapUsed().getMbFrac());
    Stats.setGauge(StatsUtil.getStatsName("eshealth", "upMinutes", tags),
        stat.getJvm().getUptime().getMinutesFrac());
    Stats.setGauge(StatsUtil.getStatsName("eshealth", "docCount", tags),
        stat.getIndices().getDocs().getCount());
  }
}
 
Example #3
Source File: HealthCheckJob.java    From soundwave with Apache License 2.0 6 votes vote down vote up
private void checkQueueLength() {
  try {
    GetQueueAttributesResult
        result =
        sqsClient.getQueueAttributes(queueUrl, Arrays.asList(QUEUELENGTHATTR,
            QUEUEINVISIBLEATTR));
    Map<String, String> attrs = result.getAttributes();

    if (attrs.containsKey(QUEUELENGTHATTR)) {
      Stats.addMetric(StatsUtil.getStatsName("healthcheck", "ec2queue_length"),
          Integer.parseInt(attrs.get(QUEUELENGTHATTR)));
      logger.info("Ec2 queue length is {}", attrs.get(QUEUELENGTHATTR));
    }

    if (attrs.containsKey(QUEUEINVISIBLEATTR)) {
      Stats.addMetric(StatsUtil.getStatsName("healthcheck", "ec2queue_in_processing"),
          Integer.parseInt(attrs.get("ApproximateNumberOfMessagesNotVisible")));
      logger.info("Ec2 queue in processing length is {}", attrs.get(QUEUEINVISIBLEATTR));
    }

  } catch (Exception ex) {
    logger.warn(ExceptionUtils.getRootCauseMessage(ex));
    logger.warn(ExceptionUtils.getFullStackTrace(ex));
  }

}
 
Example #4
Source File: ThriftLogFileReader.java    From singer with Apache License 2.0 6 votes vote down vote up
@Override
public void setByteOffset(long byteOffset) throws LogFileReaderException {
  if (closed) {
    throw new LogFileReaderException("Reader closed.");
  }

  try {
    thriftReader.setByteOffset(byteOffset);
  } catch (Exception e) {
    LOG.error(
        String.format(
            "Caught exception when set reader byte offset of log file: %s to: %d",
            logFile, byteOffset),
        e);
    Stats.incr("singer.reader.exception.unexpected");
    throw new LogFileReaderException("Can not set byte offset on the thrift reader", e);
  }
}
 
Example #5
Source File: ReconcileWithAwsJob.java    From soundwave with Apache License 2.0 6 votes vote down vote up
private void logReconcileStats(Collection<Instance> ec2Instances,
                               Collection<EsInstance> cmdbInstances) {

  int ec2RunningCount = 0;
  for (Instance inst : ec2Instances) {
    if (inst.getState().getCode() == 16) {
      //EC2 API may return some terminated instances. Only get the running count
      ec2RunningCount++;
    }
  }
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "ec2TotalRunningCount"), ec2RunningCount);
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "cmdbTotalRunningCount"),
      cmdbInstances.size());
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "diffcount"),
      Math.abs(ec2RunningCount - cmdbInstances.size()));

  int serviceMappingMissingCount = 0;
  for (EsInstance instance : cmdbInstances) {
    /*if (instance.getServiceMappings() == null || instance.getServiceMappings().length == 0) {
      serviceMappingMissingCount++;
    }*/
  }
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "servicemappingmissingcount"),
      serviceMappingMissingCount);

}
 
Example #6
Source File: OperationStats.java    From soundwave with Apache License 2.0 6 votes vote down vote up
public void failed(Map<String, String> additionalTags) {

    this.watch.stop();

    if (tags == null) {
      this.tags = additionalTags;
    } else {
      this.tags.putAll(additionalTags);
    }

    Stats
        .incr(StatsUtil
            .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.FAILURE, tags));
    Stats.addMetric(
        StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags),
        (int) watch.getTime());
  }
 
Example #7
Source File: OperationStats.java    From soundwave with Apache License 2.0 6 votes vote down vote up
public void succeed(Map<String, String> additionalTags) {

    this.watch.stop();

    if (tags == null) {
      this.tags = additionalTags;
    } else {
      this.tags.putAll(additionalTags);
    }

    Stats
        .incr(StatsUtil
            .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.SUCCESS, tags));
    Stats.addMetric(
        StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags),
        (int) watch.getTime());
  }
 
Example #8
Source File: TerrapinControllerHandler.java    From terrapin with Apache License 2.0 6 votes vote down vote up
private void startThriftServer(int thriftPort) throws UnknownHostException {
  TerrapinController.ServiceIface serviceImpl = new TerrapinControllerServiceImpl(
      this.configuration,
      this.zkManager,
      this.hdfsClient,
      this.helixAdmin,
      this.clusterName);
  TerrapinController.Service service =
      new TerrapinController.Service(serviceImpl, new TBinaryProtocol.Factory());

  this.server = ServerBuilder.safeBuild(
      service,
      ServerBuilder.get()
      .name("TerrapinController")
      .codec(ThriftServerFramedCodec.get())
      .hostConnectionMaxIdleTime(Duration.fromTimeUnit(
          configuration.getInt(Constants.THRIFT_CONN_MAX_IDLE_TIME, 1), TimeUnit.MINUTES))
      .maxConcurrentRequests(configuration.getInt(Constants.THRIFT_MAX_CONCURRENT_REQUESTS,
          100))
      .reportTo(new OstrichStatsReceiver(Stats.get("")))
      .bindTo(new InetSocketAddress(thriftPort)));
  new OstrichAdminService(configuration.getInt(Constants.OSTRICH_METRICS_PORT, 9999)).start();
}
 
Example #9
Source File: GaugeManagerTest.java    From terrapin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGaugeManagerRunnable() {
  String fileSet = "file-set";
  when(mockZKManager.getFileSetInfoMap()).thenReturn(ImmutableMap.of(fileSet, mockFileSetInfo));
  when(mockZKManager.getFileSetInfo(eq(fileSet))).thenReturn(mockFileSetInfo);
  when(mockZKManager.getViewInfo(eq(fileSet))).thenReturn(mockViewInfo);
  when(mockViewInfo.getNumOnlinePartitions()).thenReturn(3);
  mockServingInfo.helixResource = fileSet;
  mockServingInfo.numPartitions = 12;
  GaugeManager gaugeManager = new GaugeManager(mockZKManager, 1);
  try {
    Thread.sleep(1500);
    Option<Object> value = Stats.getGauge("terrapin-controller-fileset-file-set-online-pct");
    assertEquals(0.25, value.get());
  } catch (InterruptedException e) {
    gaugeManager.shutdown();
    fail("test failed for interruption");
  }
  gaugeManager.shutdown();
}
 
Example #10
Source File: TerrapinThriftMain.java    From terrapin with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  final PropertiesConfiguration config = TerrapinUtil.readPropertiesExitOnFailure(
      System.getProperties().getProperty("terrapin.config", "thrift.properties"));

  OstrichStatsReceiver statsReceiver = new OstrichStatsReceiver(Stats.get(""));
  int listenPort = config.getInt("thrift_port", 9090);
  TerrapinServiceImpl serviceImpl = new TerrapinServiceImpl(config,
      (List) config.getList("cluster_list"));
  Service<byte[], byte[]> service = new TerrapinService.Service(serviceImpl,
      new TBinaryProtocol.Factory());
  Server server = ServerBuilder.safeBuild(
      service,
      ServerBuilder.get()
          .name("TERRAPIN_THRIFT")
          .codec(ThriftServerFramedCodec.get())
          .hostConnectionMaxIdleTime(Duration.apply(1, TimeUnit.MINUTES))
          .maxConcurrentRequests(3000)
          .reportTo(statsReceiver)
          .bindTo(new InetSocketAddress(listenPort)));
  new OstrichAdminService(config.getInt(Constants.OSTRICH_METRICS_PORT, 9999)).start();
  LOG.info("\n#######################################"
          + "\n#      Ready To Serve Requests.       #"
          + "\n#######################################");
}
 
Example #11
Source File: ServerTracker.java    From pinlater with Apache License 2.0 6 votes vote down vote up
/**
 * Report a failed heartbeat.
 */
private synchronized void reportHeartbeatFailure() {
  Stats.incr(String.format("heartbeat_failures_%s_%d", host, port));
  currentConsecutiveSuccesses = 0;
  currentConsecutiveFailures += 1;

  if (!isLive) {
    // Do not LOG here to prevent noise.
    Stats.incr(String.format("healthcheck_dead_%s_%d", host, port));
    return;
  }

  if (currentConsecutiveFailures >= consecutiveFailures) {
    LOG.info(String.format("Server %s:%d is determined as dead by health check.", host, port));
    Stats.incr(String.format("healthcheck_dead_%s_%d", host, port));
    isLive = false;
  }
}
 
Example #12
Source File: TerrapinServerHandler.java    From terrapin with Apache License 2.0 6 votes vote down vote up
private void startThriftServer(int thriftPort) {
  TerrapinServerInternal.ServiceIface serviceImpl = new TerrapinServerInternalImpl(configuration,
      resourcePartitionMap);
  TerrapinServerInternal.Service service =
      new TerrapinServerInternal.Service(serviceImpl, new TBinaryProtocol.Factory());

  this.server = ServerBuilder.safeBuild(
      service,
      ServerBuilder.get()
          .name("TerrapinServer")
          .codec(ThriftServerFramedCodec.get())
          .hostConnectionMaxIdleTime(Duration.fromTimeUnit(
                  configuration.getInt(Constants.THRIFT_CONN_MAX_IDLE_TIME, 1), TimeUnit.MINUTES))
          .maxConcurrentRequests(configuration.getInt(Constants.THRIFT_MAX_CONCURRENT_REQUESTS,
                  100))
          .reportTo(new OstrichStatsReceiver(Stats.get("")))
          .bindTo(new InetSocketAddress(thriftPort)));
    new OstrichAdminService(configuration.getInt(Constants.OSTRICH_METRICS_PORT, 9999)).start();  
}
 
Example #13
Source File: PinLaterServiceImpl.java    From pinlater with Apache License 2.0 6 votes vote down vote up
@Override
public Future<PinLaterDequeueResponse> dequeueJobs(
    RequestContext context, final PinLaterDequeueRequest request) {
  if (!queueConfig.allowDequeue(request.getQueueName(), request.getLimit())) {
    Stats.incr(request.getQueueName() + "_dequeue_requests_rate_limited");
    return Future.exception(new PinLaterException(ErrorCode.DEQUEUE_RATE_LIMITED,
        "Dequeue rate limit exceeded for queue: " + request.getQueueName()));
  }

  return Stats.timeFutureMillis(
      "PinLaterService.dequeueJobs",
      backend.dequeueJobs(context.getSource(), request).onSuccess(
          new Function<PinLaterDequeueResponse, BoxedUnit>() {
            @Override
            public BoxedUnit apply(PinLaterDequeueResponse response) {
              Stats.incr(request.getQueueName() + "_dequeue", response.getJobsSize());
              return null;
            }
          }).rescue(new LogAndWrapException<PinLaterDequeueResponse>(
          context, "dequeueJobs", request.toString())));
}
 
Example #14
Source File: PinLaterServiceImpl.java    From pinlater with Apache License 2.0 6 votes vote down vote up
@Override
public Future<Void> ackDequeuedJobs(RequestContext context, final PinLaterJobAckRequest request) {
  return Stats.timeFutureMillis(
      "PinLaterService.ackDequeuedJobs",
      backend.ackDequeuedJobs(request).onSuccess(
          new Function<Void, BoxedUnit>() {
            @Override
            public BoxedUnit apply(Void aVoid) {
              Stats.incr(request.getQueueName() + "_ack_succeeded",
                  request.getJobsSucceededSize());
              Stats.incr(request.getQueueName() + "_ack_failed", request.getJobsFailedSize());
              return null;
            }
          }).rescue(new LogAndWrapException<Void>(context, "ackDequeuedJobs",
          request.toString())));
}
 
Example #15
Source File: HFileReader.java    From terrapin with Apache License 2.0 6 votes vote down vote up
/**
 * Issues an HFile lookup on the underlying HFile.Reader. This is protected
 * for testing.
 */
protected Pair<ByteBuffer, Pair<ByteBuffer, Throwable>> getValueFromHFile(ByteBuffer key) {
  try {
    HFileScanner scanner = reader.getScanner(true, true, false);
    KeyValue kv = buildKeyValueForLookup(
        BytesUtil.readBytesFromByteBufferWithoutConsume(key));
    int code = scanner.seekTo(kv.getKey());
    ByteBuffer value = null;
    if (code == 0) {
      value = ByteBuffer.wrap(scanner.getKeyValue().getValue());
      if (this.sizeStatsKey != null) {
        Stats.addMetric(this.sizeStatsKey, value.remaining());
      }
      Stats.addMetric("value-size", value.remaining());
    } else {
      Stats.incr("not-found");
      if (this.notFoundStatsKey != null) {
        Stats.incr(this.notFoundStatsKey);
      }
    }
    return new ImmutablePair(key, new ImmutablePair(value, null));
  } catch (Throwable t) {
    return new ImmutablePair(key, new ImmutablePair(null, t));
  }
}
 
Example #16
Source File: StatTrackingEventListener.java    From pinlater with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(T t) {
  // Counts can be derived from the metric's count.
  Stats.addMetric(
      String.format("%s.success", statPrefix),
      (int) (TimeUtils.millisTime() - startTime));
  String tagsString = getTagsString();
  if (!Strings.isNullOrEmpty(tagsString)) {
    Stats.addMetric(
        String.format("%s.success.withtags%s", statPrefix, tagsString),
        (int) (TimeUtils.millisTime() - startTime));
  }
}
 
Example #17
Source File: PinLaterServiceImpl.java    From pinlater with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Response> apply(Throwable throwable) {
  LOG.error("Context: {} Method: {} Request: {} Exception:",
      context, methodName, requestDesc, throwable);
  PinLaterException exception;
  if (throwable instanceof PinLaterException) {
    exception = (PinLaterException) throwable;
  } else {
    exception = new PinLaterException(ErrorCode.UNKNOWN, throwable.toString());
  }
  String errorStats = "PinLater." + methodName + ".errors."
      + errorCodeToStr(exception.getErrorCode());
  Stats.incr(errorStats);
  return Future.exception(exception);
}
 
Example #18
Source File: EC2LocalityInfoProvider.java    From singer with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Map<String, String> conf) throws IllegalArgumentException, IOException {
  // check if EC2 AZ info is working
  try {
    EC2MetadataUtils.getAvailabilityZone();
    // cache locality info to avoid service based lookups
    cachedLocality = EC2MetadataUtils.getAvailabilityZone();
  } catch (Exception e) {
    LOG.error("Failed to get AZ info", e);
    Stats.addMetric(SingerMetrics.LOCALITY_MISSING, 1);
    cachedLocality = LOCALITY_NOT_AVAILABLE;
  }
}
 
Example #19
Source File: OperationStats.java    From soundwave with Apache License 2.0 5 votes vote down vote up
public OperationStats(String methodName, String statsName, Map<String, String> tags) {
  this.methodName = methodName;
  this.statsName = statsName;
  this.tags = tags;
  Stats.incr(StatsUtil.getStatsName(methodName, statsName, tags));
  watch = new StopWatch();
  watch.start();
}
 
Example #20
Source File: OperationStats.java    From soundwave with Apache License 2.0 5 votes vote down vote up
public void failed() {
  this.watch.stop();
  Stats
      .incr(StatsUtil
          .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.FAILURE, tags));
  Stats.addMetric(
      StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags),
      (int) watch.getTime());
}
 
Example #21
Source File: KubeService.java    From singer with Apache License 2.0 5 votes vote down vote up
/**
 * Check if there are any new events available in the eventfetcher queue
 * 
 * @throws InterruptedException
 */
public void checkAndProcessFsEvents() throws InterruptedException {
    // process events from fsEventFetcher
    FileSystemEvent event = fsEventFetcher.getEvent();
    WatchEvent.Kind<?> kind = event.event().kind();
    Path file = (Path) event.event().context();
    // should be NO use case for FS Modify
    // ignore delete events
    if (kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) {
        if (!file.toFile().isFile()) {
            String podName = file.toFile().getName();
            if (podName.startsWith(".")) {
                // ignore tombstone files
                return;
            }
            LOG.info("New pod directory discovered by FSM:" + event.logDir() + " " + podLogDirectory 
                + " podname:" + podName);
            Stats.incr(SingerMetrics.PODS_CREATED);
            Stats.incr(SingerMetrics.NUMBER_OF_PODS);
            activePodSet.add(podName);
            updatePodWatchers(podName, false);
        }
        // ignore all events that are not directory create events
    } else if (kind.equals(StandardWatchEventKinds.OVERFLOW)) {
        LOG.warn("Received overflow watch event from filesystem: Events may have been lost");
        // perform a full sync on pod names from file system
        updatePodNamesFromFileSystem();
    } else if (kind.equals(StandardWatchEventKinds.ENTRY_DELETE)) {
        // ignore the . files
        if (!file.toFile().getName().startsWith(".")) {
            LOG.info("File deleted:" + file.toFile().getName());
        }
    }
}
 
Example #22
Source File: LoggingAuditHeadersInjector.java    From singer with Apache License 2.0 5 votes vote down vote up
@Override
public Headers addHeaders(Headers headers, LogMessage logMessage) {
  try {
    headers.add(HEADER_KEY, SER.serialize(logMessage.getLoggingAuditHeaders()));
  } catch (TException e) {
    Stats.incr(SingerMetrics.NUMBER_OF_SERIALIZING_HEADERS_ERRORS);
    LOG.warn("Exception thrown while serializing loggingAuditHeaders", e);
  }
  return headers;
}
 
Example #23
Source File: PinLaterBackendBase.java    From pinlater with Apache License 2.0 5 votes vote down vote up
protected void initialize() throws Exception {
  if (this.shardConfigFilePath != null) {
    String fullFilePath = getClass().getResource("/" + shardConfigFilePath).getPath();
    ConfigFileWatcher.defaultInstance().addWatch(
        fullFilePath, new ExceptionalFunction<byte[], Void>() {
      @Override
      public synchronized Void applyE(byte[] bytes) throws Exception {
        processConfigUpdate(bytes);
        return null;
      }
    });
  }

  // Initialize the future pool we will use to make blocking calls to Redis.
  // We size the future pool such that there is one thread for every available connection.
  int futurePoolSize = configuration.getInt("BACKEND_CONNECTIONS_PER_SHARD") * getShards().size();
  this.futurePool = new ExecutorServiceFuturePool(Executors.newFixedThreadPool(
      futurePoolSize,
      new ThreadFactoryBuilder().setDaemon(true).setNameFormat(
          backendName + "FuturePool-%d").build()));

  // Create a map of queueName -> aync semaphore to control dequeue concurrency.
  // We configure the map to create entries on demand since queues can be created at any time.
  final int dequeueConcurrencyPerQueue =
      configuration.getInt("BACKEND_DEQUEUE_CONCURRENCY_PER_QUEUE_PER_SHARD") * getShards()
          .size();
  // We set maxWaiters on the async semaphore to the max concurrency on the server as an
  // additional safety measure.
  final int maxWaiters = configuration.getInt("MAX_CONCURRENT_REQUESTS");
  this.dequeueSemaphoreMap = CacheBuilder.newBuilder().build(
      new CacheLoader<String, AsyncSemaphore>() {
        @Override
        public AsyncSemaphore load(String queueName) throws Exception {
          AsyncSemaphore asyncSemaphore =
              new AsyncSemaphore(dequeueConcurrencyPerQueue, maxWaiters);
          Stats.setGauge("dequeue-semaphore-waiters-" + queueName, asyncSemaphore.numWaiters());
          return asyncSemaphore;
        }
      });
}
 
Example #24
Source File: OstrichMetricCollectorTest.java    From secor with Apache License 2.0 5 votes vote down vote up
@Test
public void metric() throws Exception {
    metricCollector.metric("expectedLabel", 42.0, "ignored");

    PowerMockito.verifyStatic(Stats.class);
    Stats.addMetric("expectedLabel", 42);
}
 
Example #25
Source File: OperationStats.java    From soundwave with Apache License 2.0 5 votes vote down vote up
public void succeed() {
  this.watch.stop();
  Stats
      .incr(StatsUtil
          .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.SUCCESS, tags));
  Stats.addMetric(
      StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags),
      (int) watch.getTime());
}
 
Example #26
Source File: PinLaterServiceImpl.java    From pinlater with Apache License 2.0 5 votes vote down vote up
@Override
public Future<PinLaterScanJobsResponse> scanJobs(RequestContext context,
                                                 PinLaterScanJobsRequest request) {
  return Stats.timeFutureMillis(
      "PinLaterService.scanJobs",
      backend.scanJobs(request).rescue(
          new LogAndWrapException<PinLaterScanJobsResponse>(
              context, "scanJobs", request.toString())));
}
 
Example #27
Source File: ZookeeperClient.java    From doctorkafka with Apache License 2.0 5 votes vote down vote up
public void removeZkNode(String path) throws Exception {
  try {
    curator.delete().forPath(path);
  } catch (Exception e) {
    LOG.error("Failed to remove zk node {}", path);
    Stats.incr("merced.zookeeper.failure.remove_zknode");
    throw e;
  }
}
 
Example #28
Source File: HFileReaderTest.java    From terrapin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetValues() throws Throwable {
  // Set up a null file set to start with.
  hfileReader.setFileSet(null);
  // Test a batch of all even values along with some lookups on non existent keys.
  List<ByteBuffer> keyList = Lists.newArrayListWithCapacity(5000);
  for (int i = 0; i < 10000; i += 2) {
    keyList.add(ByteBuffer.wrap(String.format("%04d", i).getBytes()));
  }
  // Add one not found key.
  keyList.add(ByteBuffer.wrap(String.format("%04d", 15000).getBytes()));

  checkKeyValues(keyList, 5000, 1000, 1);
  assertEquals(5001, Stats.getMetric("lookup-latency-ms").apply().count());
  assertEquals(1000, Stats.getCounter("lookup-errors").apply());
  assertEquals(1, Stats.getCounter("not-found").apply());

  // Test a batch of all odd values along with some lookups on non existent keys.
  // This time, we use "test" as the file set to check if the metrics are recorded
  // correctly.
  hfileReader.setFileSet("test");
  keyList = Lists.newArrayListWithCapacity(5000);
  for (int i = 1; i < 10000; i += 2) {
    keyList.add(ByteBuffer.wrap(String.format("%04d", i).getBytes()));
  }
  // Add one not found key.
  keyList.add(ByteBuffer.wrap(String.format("%04d", 16000).getBytes()));
  checkKeyValues(keyList, 5000, 1000, 1);

  assertEquals(10002, Stats.getMetric("lookup-latency-ms").apply().count());
  assertEquals(5001, Stats.getMetric("test-lookup-latency-ms").apply().count());
  assertEquals(8000, Stats.getMetric("value-size").apply().count());
  assertEquals(4000, Stats.getMetric("test-value-size").apply().count());
  assertEquals(2000, Stats.getCounter("lookup-errors").apply());
  assertEquals(1000, Stats.getCounter("test-lookup-errors").apply());
  assertEquals(2, Stats.getCounter("not-found").apply());
  assertEquals(1, Stats.getCounter("test-not-found").apply());
}
 
Example #29
Source File: TerrapinUtil.java    From terrapin with Apache License 2.0 5 votes vote down vote up
/**
 * Return the fileset corresponding to a file on HDFS. If the file path is not valid,
 * then return null.
 */
public static String extractFileSetFromPath(String resource) {
  String[] splits = resource.split("[/]");
  if (splits.length <= 3) {
    // This should really never happen.
    Stats.incr("invalid-resource");
    return null;
  }
  return splits[splits.length - 3];
}
 
Example #30
Source File: OstrichMetricCollectorTest.java    From secor with Apache License 2.0 5 votes vote down vote up
@Test
public void incrementByOne() throws Exception {
    metricCollector.increment("expectedLabel", "ignored");

    PowerMockito.verifyStatic(Stats.class);
    Stats.incr("expectedLabel");
}