com.netflix.spectator.api.BasicTag Java Examples

The following examples show how to use com.netflix.spectator.api.BasicTag. 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: ReactorHedgedTransformer.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private ReactorHedgedTransformer(List<Pair<Duration, Long>> thresholdSteps,
                                 Predicate<Throwable> retryableErrorPredicate,
                                 Map<String, String> context,
                                 Registry registry,
                                 Scheduler scheduler) {
    this.thresholdSteps = thresholdSteps;
    this.retryableErrorPredicate = retryableErrorPredicate;
    this.context = context;
    this.registry = registry;
    this.scheduler = scheduler;

    this.metricsId = registry.createId(
            METRICS_ROOT,
            context.entrySet().stream().map(e -> new BasicTag(e.getKey(), e.getValue())).collect(Collectors.toList())
    );
}
 
Example #2
Source File: MetricsControllerTest.java    From spectator with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncodeCombinedRegistry() {
  // Multiple occurrences of measurements in the same registry
  // (confirm these are handled within the registry itself).
  Measurement measureBXY2 = new Measurement(idBXY, 5, 5.5);
  Meter meterB2 = new TestMeter("ignoreB", measureBXY2);

  DefaultRegistry registry = new DefaultRegistry(clock);
  registry.register(meterB);
  registry.register(meterB2);

  List<TaggedDataPoints> expectedTaggedDataPoints = Arrays.asList(
     new TaggedDataPoints(
           Arrays.asList(new BasicTag("tagA", "X"),
                         new BasicTag("tagB", "Y")),
           Arrays.asList(new DataPoint(clock.wallTime(), 50.5 + 5.5))));

  HashMap<String, MetricValues> expect = new HashMap<>();
  expect.put("idB", new MetricValues("Counter", expectedTaggedDataPoints));

  PolledMeter.update(registry);
  Assertions.assertEquals(expect, controller.encodeRegistry(registry, allowAll));
}
 
Example #3
Source File: AgentCacheMetrics.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private InstanceGroupMetrics(AgentInstanceGroup instanceGroup) {
    this.instanceGroup = instanceGroup;

    List<Tag> commonTags = asList(
            new BasicTag("id", instanceGroup.getId()),
            new BasicTag("instanceType", instanceGroup.getInstanceType()),
            new BasicTag("state", instanceGroup.getLifecycleStatus().getState().name()),
            new BasicTag("tier", instanceGroup.getTier().name())
    );

    Id counterId = registry.createId(MetricConstants.METRIC_AGENT + "instanceGroup", commonTags);
    this.counter = registry.gauge(counterId, new AtomicInteger(1));

    Id capacityId = registry.createId(MetricConstants.METRIC_AGENT + "instanceGroup.capacity", commonTags);
    this.min = registry.gauge(capacityId.withTag("size", "min"), new AtomicInteger(instanceGroup.getMin()));
    this.desired = registry.gauge(capacityId.withTag("size", "desired"), new AtomicInteger(instanceGroup.getDesired()));
    this.current = registry.gauge(capacityId.withTag("size", "current"), new AtomicInteger(instanceGroup.getCurrent()));
    this.max = registry.gauge(capacityId.withTag("size", "max"), new AtomicInteger(instanceGroup.getMax()));
}
 
Example #4
Source File: SpringSpectatorInterceptor.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    super.postHandle(request, response, handler, modelAndView);

    String callerId = getCallerId();
    String path = request.getServletPath() == null ? "unknown" : trimPath(request.getServletPath());

    List<Tag> tags = Arrays.asList(
            new BasicTag("port", "" + request.getServerPort()),
            new BasicTag("method", request.getMethod()),
            new BasicTag("path", path),
            new BasicTag("status", "" + response.getStatus()),
            new BasicTag("caller", callerId)
    );

    registry.counter(METRICS_REQUEST, tags).increment();

    Long timestamp = (Long) request.getAttribute(REQUEST_TIMESTAMP);
    if (timestamp != null) {
        registry.timer(METRICS_REQUEST_LATENCY, tags).record(clock.wallTime() - timestamp, TimeUnit.MILLISECONDS);
    }
}
 
Example #5
Source File: ThreadPoolMetersInitializer.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected void createThreadPoolMeters(String threadPoolName, Executor executor) {
  if (!ThreadPoolExecutor.class.isInstance(executor)) {
    return;
  }

  ThreadPoolMonitor.attach(registry, (ThreadPoolExecutor) executor, threadPoolName);

  if (executor instanceof ThreadPoolExecutorEx) {
    Tag idTag = new BasicTag("id", threadPoolName);

    PolledMeter.using(registry)
        .withName(REJECTED_COUNT)
        .withTag(idTag)
        .monitorMonotonicCounter((ThreadPoolExecutorEx) executor, ThreadPoolExecutorEx::getRejectedCount);
  }
}
 
Example #6
Source File: HttpClientListener.java    From mantis with Apache License 2.0 6 votes vote down vote up
protected HttpClientListener(String monitorId) {
    super(monitorId);

    final String metricsGroup = "httpClient";
    final String idValue = Optional.ofNullable(monitorId).orElse("none");
    final BasicTag idTag = new BasicTag(GROUP_ID_TAG, idValue);
    Metrics m = new Metrics.Builder()
            .id(metricsGroup, idTag)
            .addGauge("requestBacklog")
            .addGauge("inflightRequests")
            .addCounter("processedRequests")
            .addCounter("requestWriteFailed")
            .addCounter("failedResponses")

            .build();

    requestBacklog = m.getGauge("requestBacklog");
    inflightRequests = m.getGauge("inflightRequests");
    //        requestWriteTimes = newTimer("requestWriteTimes");
    //        responseReadTimes = newTimer("responseReadTimes");
    processedRequests = m.getCounter("processedRequests");
    requestWriteFailed = m.getCounter("requestWriteFailed");
    failedResponses = m.getCounter("failedResponses");
    //  requestProcessingTimes = newTimer("requestProcessingTimes");
}
 
Example #7
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 6 votes vote down vote up
private Timer getTimer(String operation, String operationType, OperationStatus status, String hit, String host, long maxDuration) {
    String name = ((status != null) ? operation + status.getMessage() : operation );
    if(hit != null) name = name + hit;

    Timer timer = timerMap.get(name);
    if(timer != null) return timer;

    final List<Tag> tagList = new ArrayList<Tag>(client.getTagList().size() + 4 + (host == null ? 0 : 1));
    tagList.addAll(client.getTagList());
    if(operation != null) tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TAG, operation));
    if(operationType != null) tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TYPE_TAG, operationType));
    if(status != null) {
        if(status.getStatusCode() == StatusCode.SUCCESS || status.getStatusCode() == StatusCode.ERR_NOT_FOUND || status.getStatusCode() == StatusCode.ERR_EXISTS) {
            tagList.add(new BasicTag(EVCacheMetricsFactory.IPC_RESULT, EVCacheMetricsFactory.SUCCESS));
        } else {
            tagList.add(new BasicTag(EVCacheMetricsFactory.IPC_RESULT, EVCacheMetricsFactory.FAIL));
        }
        tagList.add(new BasicTag(EVCacheMetricsFactory.IPC_STATUS, getStatusCode(status.getStatusCode())));
    }
    if(hit != null) tagList.add(new BasicTag(EVCacheMetricsFactory.CACHE_HIT, hit));
    if(host != null) tagList.add(new BasicTag(EVCacheMetricsFactory.FAILED_HOST, host));

    timer = EVCacheMetricsFactory.getInstance().getPercentileTimer(EVCacheMetricsFactory.IPC_CALL, tagList, Duration.ofMillis(maxDuration));
    timerMap.put(name, timer);
    return timer;
}
 
Example #8
Source File: EVCacheClientPool.java    From EVCache with Apache License 2.0 6 votes vote down vote up
private Gauge getConfigGauge(String metric, ServerGroup serverGroup) {
    final String name = (serverGroup == null ? metric : metric + serverGroup.getName() + isInWriteOnly(serverGroup));
    Gauge gauge = gaugeMap.get(name );
    if(gauge != null) return gauge;

    final List<Tag> tags = new ArrayList<Tag>(5);
    EVCacheMetricsFactory.getInstance().addAppNameTags(tags, _appName);
    tags.add(new BasicTag(EVCacheMetricsFactory.CONFIG_NAME, metric));
    if(serverGroup != null) {
        tags.add(new BasicTag(EVCacheMetricsFactory.SERVERGROUP, serverGroup.getName()));
    }

    final Id id = EVCacheMetricsFactory.getInstance().getId(EVCacheMetricsFactory.INTERNAL_POOL_SG_CONFIG, tags);
    gauge = EVCacheMetricsFactory.getInstance().getRegistry().gauge(id);
    gaugeMap.put(name, gauge);
    return gauge;
}
 
Example #9
Source File: PrototypeMeasurementFilterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void keepAnyTag() {
    PrototypeMeasurementFilter.TagFilterPattern pattern
        = new PrototypeMeasurementFilter.TagFilterPattern(
                  new PrototypeMeasurementFilterSpecification.TagFilterSpecification("", ""));
    Tag tagA = new BasicTag("some_name_value", "some_value_string");
    Assertions.assertTrue(pattern.test(tagA));
}
 
Example #10
Source File: PrototypeMeasurementFilterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void valueTagsMissing() {
    PrototypeMeasurementFilter.ValueFilterPattern pattern
        = new PrototypeMeasurementFilter.ValueFilterPattern(valueSpecAxBy);
    List<Tag> tagsAx = Collections.singletonList(new BasicTag("tagA", "X"));
    List<Tag> tagsAxZy = Arrays.asList(new BasicTag("tagA", "X"),
                                       new BasicTag("tagZ","Y"));
    List<Tag> tagsAyBy = Arrays.asList(new BasicTag("tagA", "Y"),
                                       new BasicTag("tagB", "Y"));

    Assertions.assertFalse(pattern.test(tagsAx));
    Assertions.assertFalse(pattern.test(tagsAxZy));
    Assertions.assertFalse(pattern.test(tagsAyBy));
}
 
Example #11
Source File: ConnectionGroup.java    From mantis with Apache License 2.0 5 votes vote down vote up
public ConnectionGroup(String groupId) {
    this.groupId = groupId;
    this.connections = new HashMap<>();

    final String grpId = Optional.ofNullable(groupId).orElse("none");
    final BasicTag groupIdTag = new BasicTag(MantisMetricStringConstants.GROUP_ID_TAG, grpId);
    this.metricsGroup = new MetricGroupId("ConnectionGroup", groupIdTag);

    Gauge activeConnections
            = new GaugeCallback(metricsGroup, "activeConnections", new Func0<Double>() {
        @Override
        public Double call() {
            synchronized (this) {
                return (double) connections.size();
            }
        }
    });
    this.metrics = new Metrics.Builder()
            .id(metricsGroup)
            .addCounter("numSlotSwaps")
            .addCounter("numSuccessfulWrites")
            .addCounter("numFailedWrites")
            .addGauge(activeConnections)
            .build();

    this.successfulWrites = metrics.getCounter("numSuccessfulWrites");
    this.failedWrites = metrics.getCounter("numFailedWrites");
    this.numSlotSwaps = metrics.getCounter("numSlotSwaps");
}
 
Example #12
Source File: EVCacheImpl.java    From EVCache with Apache License 2.0 5 votes vote down vote up
private void incrementFailure(String metric, String operation, String operationType) {
    final String name = metric + operation;
    Counter counter = counterMap.get(name);
    if(counter == null) {
        final List<Tag> tagList = new ArrayList<Tag>(tags.size() + 3);
        tagList.addAll(tags);
        if(operation != null) tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TAG, operation));
        if(operationType != null) tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TYPE_TAG, operationType));
        tagList.add(new BasicTag(EVCacheMetricsFactory.FAILURE_REASON, metric));
        counter = EVCacheMetricsFactory.getInstance().getCounter(EVCacheMetricsFactory.INTERNAL_FAIL, tagList);
        counterMap.put(name, counter);
    }
    counter.increment();
}
 
Example #13
Source File: DefaultPlaceholderIdTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithFactories() {
  Tag tags1 = new BasicTag("k1", "v1");
  Tag tags2 = new BasicTag("k2", "v2");
  List<TagFactory> factories = Arrays.asList(new ConstantTagFactory(tags1), new ConstantTagFactory(tags2));
  DefaultPlaceholderId id = DefaultPlaceholderId.createWithFactories("foo", factories, REGISTRY);
  Iterator<Tag> tags = id.resolveToId().tags().iterator();

  Assertions.assertEquals("foo", id.name());
  Assertions.assertTrue(tags.hasNext(), "tags empty");
  Assertions.assertEquals(tags1, tags.next());
  Assertions.assertEquals(tags2, tags.next());
}
 
Example #14
Source File: TagFactoryTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void fromSupplierDynamic() {
  AtomicReference<String> value = new AtomicReference<>();
  TagFactory f = TagFactory.from("foo", value::get);
  Assertions.assertEquals("foo", f.name());
  Assertions.assertNull(f.createTag());
  value.set("bar");
  Assertions.assertEquals(new BasicTag("foo", "bar"), f.createTag());
}
 
Example #15
Source File: ConstantTagFactoryTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameFromTag() throws Exception {
  String expected = "factoryName";
  Tag tag = new BasicTag(expected, "unused");
  TagFactory factory = new ConstantTagFactory(tag);

  Assertions.assertEquals(expected, factory.name());
}
 
Example #16
Source File: VersionTracker.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public void run() {
    // init the version information

	if(versionGauge == null) {
	    final String fullVersion;
	    final String jarName;
        if(this.getClass().getPackage().getImplementationVersion() != null) {
            fullVersion = this.getClass().getPackage().getImplementationVersion();
        } else {
            fullVersion = "unknown";
        }

        if(this.getClass().getPackage().getImplementationVersion() != null) {
            jarName = this.getClass().getPackage().getImplementationTitle();
        } else {
            jarName = "unknown";
        }

        if(log.isInfoEnabled()) log.info("fullVersion : " + fullVersion + "; jarName : " + jarName);
        final List<Tag> tagList = new ArrayList<Tag>(3);
        tagList.add(new BasicTag("version", fullVersion));
        tagList.add(new BasicTag("jarName", jarName));
     versionGauge = EVCacheMetricsFactory.getInstance().getLongGauge("evcache-client", tagList);
	}
 versionGauge.set(Long.valueOf(1));
	poolManager.getEVCacheScheduledExecutor().schedule(this, 30, TimeUnit.SECONDS);
}
 
Example #17
Source File: EVCacheClient.java    From EVCache with Apache License 2.0 5 votes vote down vote up
private void incrementFailure(String metric, EVCache.Call call, String host) {
    Counter counter = counterMap.get(metric);
    if(counter == null) {
        final List<Tag> tagList = new ArrayList<Tag>(6);
        tagList.addAll(tags);
        if(call != null) {
            tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TAG, call.name()));
            switch(call) {
            case GET:
            case GETL:
            case GET_AND_TOUCH:
            case ASYNC_GET:
            case  BULK:
            case  GET_ALL:
                tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TYPE_TAG, EVCacheMetricsFactory.READ));
                break;
            default :
                tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TYPE_TAG, EVCacheMetricsFactory.WRITE));
                break;
            }
        }
        tagList.add(new BasicTag(EVCacheMetricsFactory.FAILURE_REASON, metric));
        if(host != null) tagList.add(new BasicTag(EVCacheMetricsFactory.FAILED_HOST, host));
        counter = EVCacheMetricsFactory.getInstance().getCounter(EVCacheMetricsFactory.INTERNAL_FAIL, tagList);
        counterMap.put(metric, counter);
    }
    counter.increment();
}
 
Example #18
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 5 votes vote down vote up
private DistributionSummary getDataSizeDistributionSummary(String operation, String type, String metric) {
    DistributionSummary distributionSummary = distributionSummaryMap.get(operation);
    if(distributionSummary != null) return distributionSummary;

    final List<Tag> tagList = new ArrayList<Tag>(6);
    tagList.addAll(client.getTagList());
    tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TAG, operation));
    tagList.add(new BasicTag(EVCacheMetricsFactory.CALL_TYPE_TAG, type));
    distributionSummary = EVCacheMetricsFactory.getInstance().getDistributionSummary(metric, tagList);
    distributionSummaryMap.put(operation, distributionSummary);
    return distributionSummary;
}
 
Example #19
Source File: DefaultPlaceholderIdTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTagFactories() {
  Tag tags1 = new BasicTag("k1", "v1");
  Tag tags2 = new BasicTag("k2", "v2");
  List<TagFactory> factories = Arrays.asList(new ConstantTagFactory(tags1), new ConstantTagFactory(tags2));
  DefaultPlaceholderId id = new DefaultPlaceholderId("foo", REGISTRY).withTagFactories(factories);
  Iterator<Tag> tags = id.resolveToId().tags().iterator();

  Assertions.assertTrue(tags.hasNext(), "tags empty");
  Assertions.assertEquals(tags1, tags.next());
  Assertions.assertEquals(tags2, tags.next());
}
 
Example #20
Source File: PrototypeMeasurementFilterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void keepTagOk() {
    PrototypeMeasurementFilter.TagFilterPattern pattern
        = new PrototypeMeasurementFilter.TagFilterPattern(
                  Pattern.compile(".+_name_.+"), Pattern.compile(".+_value_.+"));
    Tag tagA = new BasicTag("some_name_value", "some_value_string");
    Assertions.assertTrue(pattern.test(tagA));
}
 
Example #21
Source File: TagsBuilder.java    From spectator with Apache License 2.0 5 votes vote down vote up
/** Add additional tag values. */
public T withTags(String... tags) {
  for (int i = 0; i < tags.length; i += 2) {
    extraTags.add(new BasicTag(tags[i], tags[i + 1]));
  }
  return (T) this;
}
 
Example #22
Source File: MetricsControllerTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeCompositeRegistry() {
  // Multiple occurrences of measurements in the same registry
  // (confirm these are handled within the registry itself).
  // Here measurements are duplicated but meters have different sets.
  Measurement measureAXY2 = new Measurement(idAXY, 20, 20.20);
  Meter meterA2 = new TestMeter("ignoreA", measureAXY2);

  DefaultRegistry registry = new DefaultRegistry(clock);
  registry.register(meterA);
  registry.register(meterA2);

  List<TaggedDataPoints> expectedDataPoints = Arrays.asList(
      new TaggedDataPoints(
          Arrays.asList(new BasicTag("tagA", "X"), new BasicTag("tagZ", "Z")),
          Arrays.asList(new DataPoint(clock.wallTime(), 13.13))),
      new TaggedDataPoints(
          Arrays.asList(new BasicTag("tagA", "X"), new BasicTag("tagB", "Y")),
          Arrays.asList(new DataPoint(clock.wallTime(), 11.11 + 20.20))),
      new TaggedDataPoints(
          Arrays.asList(new BasicTag("tagA", "Y"), new BasicTag("tagB", "X")),
          Arrays.asList(new DataPoint(clock.wallTime(), 12.12)))
  );

  HashMap<String, MetricValues> expect = new HashMap<>();
  expect.put("idA", new MetricValues("Counter", expectedDataPoints));

  PolledMeter.update(registry);
  Assertions.assertEquals(expect, controller.encodeRegistry(registry, allowAll));
}
 
Example #23
Source File: EVCacheInMemoryCache.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public EVCacheInMemoryCache(String appName, Transcoder<T> tc, EVCacheImpl impl) {
    this.appName = appName;
    this.tc = tc;
    this.impl = impl;

    this._cacheDuration = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".inmemory.expire.after.write.duration.ms", Integer.class).orElseGet(appName + ".inmemory.cache.duration.ms").orElse(0);
    this._cacheDuration.subscribe((i) -> setupCache());
    this._exireAfterAccessDuration = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".inmemory.expire.after.access.duration.ms", Integer.class).orElse(0);
    this._exireAfterAccessDuration.subscribe((i) -> setupCache());;

    this._refreshDuration = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".inmemory.refresh.after.write.duration.ms", Integer.class).orElse(0);
    this._refreshDuration.subscribe((i) -> setupCache());

    this._cacheSize = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".inmemory.cache.size", Integer.class).orElse(100);
    this._cacheSize.subscribe((i) -> setupCache());

    this._poolSize = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".thread.pool.size", Integer.class).orElse(5);
    this._poolSize.subscribe((i) -> initRefreshPool());

    final List<Tag> tags = new ArrayList<Tag>(3);
    tags.addAll(impl.getTags());
    tags.add(new BasicTag(EVCacheMetricsFactory.METRIC, "size"));

    this.sizeId = EVCacheMetricsFactory.getInstance().getId(EVCacheMetricsFactory.IN_MEMORY, tags);
    setupCache();
    setupMonitoring(appName);
}
 
Example #24
Source File: MetricsControllerTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeSimpleRegistry() {
  DefaultRegistry registry = new DefaultRegistry(clock);
  Counter counterA = registry.counter(idAXY);
  Counter counterB = registry.counter(idBXY);
  counterA.increment(4);
  counterB.increment(10);

  List<TaggedDataPoints> expectedTaggedDataPointsA
    = Arrays.asList(
        new TaggedDataPoints(
            Arrays.asList(new BasicTag("tagA", "X"),
                          new BasicTag("tagB", "Y")),
            Arrays.asList(new DataPoint(clock.wallTime(), 4))));

  List<TaggedDataPoints> expectedTaggedDataPointsB
    = Arrays.asList(
        new TaggedDataPoints(
            Arrays.asList(new BasicTag("tagA", "X"),
                          new BasicTag("tagB", "Y")),
            Arrays.asList(new DataPoint(clock.wallTime(), 10))));

  HashMap<String, MetricValues> expect = new HashMap<>();
  expect.put("idA", new MetricValues("Counter", expectedTaggedDataPointsA));
  expect.put("idB", new MetricValues("Counter", expectedTaggedDataPointsB));
  Assertions.assertEquals(expect, controller.encodeRegistry(registry, allowAll));
}
 
Example #25
Source File: TagsBuilderTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void tag() {
  Id id = new Builder()
      .withTag(new BasicTag("k", "v"))
      .build();
  Assertions.assertEquals(newId("k", "v"), id);
}
 
Example #26
Source File: PercentileDistributionSummary.java    From spectator with Apache License 2.0 5 votes vote down vote up
private Counter counterFor(int i) {
  Counter c = counters.get(i);
  if (c == null) {
    Id counterId = id.withTags(Statistic.percentile, new BasicTag("percentile", TAG_VALUES[i]));
    c = registry.counter(counterId);
    counters.set(i, c);
  }
  return c;
}
 
Example #27
Source File: MetricsContainer.java    From conductor with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private static List<Tag> getTags(String[] additionalTags) {
    List<Tag> tagList = new ArrayList();
    tagList.add(new BasicTag("class", className));
    for (int j = 0; j < additionalTags.length - 1; j++) {
        tagList.add(new BasicTag(additionalTags[j], additionalTags[j + 1]));
        j++;
    }
    return tagList;
}
 
Example #28
Source File: PercentileTimer.java    From spectator with Apache License 2.0 5 votes vote down vote up
private Counter counterFor(int i) {
  Counter c = counters.get(i);
  if (c == null) {
    Id counterId = id.withTags(Statistic.percentile, new BasicTag("percentile", TAG_VALUES[i]));
    c = registry.counter(counterId);
    counters.set(i, c);
  }
  return c;
}
 
Example #29
Source File: TagsBuilder.java    From spectator with Apache License 2.0 5 votes vote down vote up
/** Add additional tag values. */
public T withTags(Map<String, String> tags) {
  for (Map.Entry<String, String> entry : tags.entrySet()) {
    extraTags.add(new BasicTag(entry.getKey(), entry.getValue()));
  }
  return (T) this;
}
 
Example #30
Source File: IpcLogEntryTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void addTags() {
  Map<String, String> actual = (Map<String, String>) entry
      .addTag(new BasicTag("k1", "v1"))
      .addTag("k2", "v2")
      .convert(this::toMap)
      .get("additionalTags");
  Assertions.assertEquals(2, actual.size());
  Assertions.assertEquals("v1", actual.get("k1"));
  Assertions.assertEquals("v2", actual.get("k2"));
}