com.netflix.spectator.api.Registry类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.netflix.spectator.api.Registry类的一些代码示例,展示了Registry类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry类的具体详情如下:
包路径:com.netflix.spectator.api.Registry
类名称:Registry

Registry介绍

[英]Registry to manage a set of meters.
[中]注册表来管理一组仪表。

代码示例

代码示例来源:origin: Netflix/conductor

private static Counter getCounter(String className, String name, String... additionalTags) {
  Map<String, String> tags = toMap(className, additionalTags);
  return counters.computeIfAbsent(name, s -> new ConcurrentHashMap<>()).computeIfAbsent(tags, t -> {
    Id id = registry.createId(name, tags);
    return registry.counter(id);
  });
}

代码示例来源:origin: Netflix/servo

private Timer get() {
 Timer t = timer;
 if (t == null) {
  t = registry.timer(id);
  timer = t;
 }
 return t;
}

代码示例来源:origin: Netflix/zuul

public HttpMetricsChannelHandler(Registry registry, String name, String id)
{
  super();
  this.registry = registry;
  this.currentRequestsGauge = this.registry.gauge(this.registry.createId(name + ".http.requests.current", "id", id));
  this.unSupportedPipeliningCounter = this.registry.counter(name + ".http.requests.pipelining.dropped", "id", id);
}

代码示例来源:origin: Netflix/Priam

@Inject
public BackupMetrics(Registry registry) {
  this.registry = registry;
  validDownloads = registry.counter(Metrics.METRIC_PREFIX + "download.valid");
  invalidDownloads = registry.counter(Metrics.METRIC_PREFIX + "download.invalid");
  validUploads = registry.counter(Metrics.METRIC_PREFIX + "upload.valid");
  invalidUploads = registry.counter(Metrics.METRIC_PREFIX + "upload.invalid");
  uploadRate = registry.distributionSummary(Metrics.METRIC_PREFIX + "upload.rate");
  downloadRate = registry.distributionSummary(Metrics.METRIC_PREFIX + "download.rate");
  snsNotificationSuccess =
      registry.counter(Metrics.METRIC_PREFIX + "sns.notification.success");
  snsNotificationFailure =
      registry.counter(Metrics.METRIC_PREFIX + "sns.notification.failure");
  forgottenFiles = registry.counter(Metrics.METRIC_PREFIX + "forgotten.files");
}

代码示例来源:origin: Netflix/zuul

private void openSslStatGauge(OpenSslSessionStats stats, String sslContextId, String statName, ToDoubleFunction<OpenSslSessionStats> value) {
  Id id = spectatorRegistry.createId("server.ssl.stats", "id", sslContextId, "stat", statName);
  spectatorRegistry.gauge(id, stats, value);
  LOG.debug("Registered spectator gauge - " + id.name());
}

代码示例来源:origin: spinnaker/kayenta

private List<InfluxDbResult> queryInfluxdb(InfluxDbRemoteService remoteService, String metricSetName, String query) {
 long startTime = registry.clock().monotonicTime();
 List<InfluxDbResult> influxDbResults;
 try {
  influxDbResults = remoteService.query(metricSetName, query);
 } finally {
  long endTime = registry.clock().monotonicTime();
  Id influxDbFetchTimerId = registry.createId("influxdb.fetchTime");
  registry.timer(influxDbFetchTimerId).record(endTime - startTime, TimeUnit.NANOSECONDS);
 }
 return influxDbResults;
}

代码示例来源:origin: Netflix/spectator

@Test
public void testCounterBadTypeAccessNoThrow() {
 Registry r = newRegistry(5, false);
 r.counter(r.createId("foo")).count();
 Counter c = r.counter("foo");
 DistributionSummary ds = r.distributionSummary(r.createId("foo"));
 ds.record(42);
 Assertions.assertEquals(ds.count(), 0L);
}

代码示例来源:origin: Netflix/spectator

@Test
public void testTimerBadTypeAccess() {
 Assertions.assertThrows(IllegalStateException.class, () -> {
  Registry r = newRegistry(5, true);
  r.timer(r.createId("foo")).count();
  r.counter(r.createId("foo")).count();
 });
}

代码示例来源:origin: spinnaker/kayenta

Id id = registry.createId(metricName)
 .withTag("controller", controller)
 .withTag("method", handlerMethod.getMethod().getName())
registry.timer(id).record(
 getNanoTime() - ((Long) request.getAttribute(TIMER_ATTRIBUTE)), TimeUnit.NANOSECONDS
);
 registry.createId(contentLengthMetricName).withTags(id.tags())
).record(request.getContentLengthLong());

代码示例来源:origin: Netflix/zuul

public ClientResponseWriter(RequestCompleteHandler requestCompleteHandler, Registry registry) {
  this.requestCompleteHandler = requestCompleteHandler;
  this.responseBeforeReceivedLastContentCounter = registry.counter("server.http.requests.responseBeforeReceivedLastContent");
}

代码示例来源:origin: Netflix/zuul

public EventLoopMetrics(Registry registry, String eventLoopName)
{
  this.name = eventLoopName;
  this.registry = registry;
  this.currentRequestsId = this.registry.createId("server.eventloop.http.requests.current");
  this.currentConnectionsId = this.registry.createId("server.eventloop.connections.current");
}

代码示例来源:origin: Netflix/spectator

@Test
public void testGaugeHelpersWithFunction() {
 AtomicLong al1 = new AtomicLong(1L);
 Registry r = new DefaultRegistry(new ManualClock(40, 0));
 DoubleFunction<AtomicLong> f = Functions.age(r.clock());
 AtomicLong v1 = r.gauge("foo", al1, f);
 Assertions.assertSame(v1, al1);
 Id id1 = r.createId("foo");
 assertGaugeValue(r, id1, 39.0 / 1000.0);
}

代码示例来源:origin: Netflix/servo

@Test
public void testUnregisteredBasicTimerIncrement() {
 BasicTimer t = new BasicTimer(CONFIG);
 t.record(42, TimeUnit.MILLISECONDS);
 Id id = registry.createId("test")
   .withTag("unit", "MILLISECONDS");
 assertEquals(3, registry.counters().count());
 assertEquals(0, registry.timers().count());
 assertEquals(1, registry.gauges().count());
 assertEquals(0, registry.distributionSummaries().count());
 assertEquals(1, registry.counter(id.withTag(Statistic.count)).count());
 assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).count());
 assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).count());
 assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value());
}

代码示例来源:origin: Netflix/EVCache

public static DistributionSummary getDistributionSummary(String name, String appName, String serverGroup) {
  final String metricName = getMetricName(appName, serverGroup, name);
  final DistributionSummary _ds = distributionSummaryMap.get(metricName);
  if(_ds != null) return _ds;
  final Registry registry = Spectator.globalRegistry(); //_poolManager.getRegistry();
  if (registry != null) {
    Id id = registry.createId(name);
    id = id.withTag("owner", "evcache");
    id = id.withTag("APP", appName);
    if(serverGroup != null) id = id.withTag("ServerGroup", serverGroup);
    final DistributionSummary ds = registry.distributionSummary(id);
    if (!Monitors.isObjectRegistered(ds)) Monitors.registerObject(ds);
    distributionSummaryMap.put(metricName, ds);
    return ds;
  }
  return null;
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/** Create a new instance. */
Stats(Registry registry, String id) {
 this.registry = registry;
 activeCount = PolledMeter.using(registry)
   .withId(newId(registry, id, "activeThreads"))
   .monitorValue(new AtomicInteger());
 taskExecutionTime = registry.timer(newId(registry, id, "taskExecutionTime"));
 taskExecutionDelay = registry.timer(newId(registry, id, "taskExecutionDelay"));
 skipped = registry.counter(newId(registry, id, "skipped"));
 uncaughtExceptionsId = newId(registry, id, "uncaughtExceptions");
}

代码示例来源:origin: Netflix/spectator

@Test
public void testDistributionSummaryBadTypeAccess() {
 Assertions.assertThrows(IllegalStateException.class, () -> {
  Registry r = newRegistry(5, true);
  r.distributionSummary(r.createId("foo")).count();
  r.timer(r.createId("foo")).count();
 });
}

代码示例来源:origin: Netflix/servo

@Test
public void testStatsTimerRecordMillis() {
 StatsConfig sc = new StatsConfig.Builder()
   .withPercentiles(new double[] {50.0, 95.0})
   .withPublishCount(true)
   .withPublishMax(true)
   .withPublishMean(true)
   .withSampleSize(10)
   .build();
 StatsTimer d = new StatsTimer(CONFIG, sc);
 register(d);
 d.record(42, TimeUnit.MILLISECONDS);
 d.computeStats();
 Id id = ID.withTag("unit", "MILLISECONDS");
 assertEquals(1, registry.counter(id.withTag(Statistic.count)).count());
 assertEquals(42.0, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12);
 assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12);
 assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_50")).value(), 1e-12);
 assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_95")).value(), 1e-12);
 assertEquals(42.0, registry.gauge(id.withTag("statistic", "avg")).value(), 1e-12);
}

代码示例来源:origin: spinnaker/kayenta

String isoStep = Duration.of(atlasCanaryScope.getStep(), SECONDS) + "";
long start = registry.clock().monotonicTime();
List <AtlasResults> atlasResultsList;
try {
 MAX_RETRIES, RETRY_BACKOFF);
} finally {
 long end = registry.clock().monotonicTime();
 registry.timer("atlas.fetchTime").record(end - start, TimeUnit.NANOSECONDS);

代码示例来源:origin: Netflix/servo

@Test
public void testBasicDistributionSummaryRecord() {
 BasicDistributionSummary d = new BasicDistributionSummary(CONFIG);
 register(d);
 d.record(42);
 assertEquals(1, registry.counter(ID.withTag(Statistic.count)).count());
 assertEquals(42, registry.counter(ID.withTag(Statistic.totalAmount)).count());
 assertEquals(42.0, registry.maxGauge(ID.withTag(Statistic.max)).value(), 1e-12);
}

代码示例来源:origin: Netflix/zuul

private void updateGauge(Id gaugeId, int value)
  {
    registry.gauge(gaugeId.withTag("eventloop", name)).set(value);
  }
}

相关文章