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); }); }
private Timer get() { Timer t = timer; if (t == null) { t = registry.timer(id); timer = t; } return t; }
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); }
@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"); }
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()); }
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; }
@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); }
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());
public ClientResponseWriter(RequestCompleteHandler requestCompleteHandler, Registry registry) { this.requestCompleteHandler = requestCompleteHandler; this.responseBeforeReceivedLastContentCounter = registry.counter("server.http.requests.responseBeforeReceivedLastContent"); }
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"); }
@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); }
@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()); }
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; }
/** 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"); }
@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(); }); }
@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); }
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);
@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); }
private void updateGauge(Id gaugeId, int value) { registry.gauge(gaugeId.withTag("eventloop", name)).set(value); } }