Java Code Examples for com.netflix.spectator.api.Registry#timer()
The following examples show how to use
com.netflix.spectator.api.Registry#timer() .
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: TestMetricsRestPublisher.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void measure_normal() { Clock clock = new ManualClock(); GlobalRegistry globalRegistry = new GlobalRegistry(); Registry registry = new DefaultRegistry(clock); registry.timer(registry.createId("name", "t1", "v1", "t2", "v2")); globalRegistry.add(registry); EventBus eventBus = new EventBus(); publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig()); Map<String, Double> result = publisher.measure(); Assert.assertEquals(2, result.size()); Assert.assertEquals(0, result.get("name(statistic=count,t1=v1,t2=v2)"), 0); Assert.assertEquals(0, result.get("name(statistic=totalTime,t1=v1,t2=v2)"), 0); }
Example 2
Source File: SchedulerMetrics.java From titus-control-plane with Apache License 2.0 | 6 votes |
SchedulerMetrics(DefaultLocalScheduler scheduler, Clock clock, Registry registry) { this.clock = clock; this.registry = registry; this.scheduler = scheduler; this.lastEvaluationTime = clock.wallTime(); this.activeSchedulesId = registry.createId(ScheduleMetrics.ROOT_NAME + "active"); PolledMeter.using(registry) .withId(activeSchedulesId) .monitorValue(this, self -> self.scheduler.getActiveSchedules().size()); this.archivedSchedulesId = registry.createId(ScheduleMetrics.ROOT_NAME + "archived"); PolledMeter.using(registry) .withId(activeSchedulesId) .monitorValue(this, self -> self.scheduler.getArchivedSchedules().size()); this.evaluationTimer = registry.timer(ScheduleMetrics.ROOT_NAME + "evaluationTime"); this.lastEvaluationId = registry.createId(ScheduleMetrics.ROOT_NAME + "lastEvaluationMs"); PolledMeter.using(registry) .withId(lastEvaluationId) .monitorValue(this, self -> self.clock.wallTime() - self.lastEvaluationTime); }
Example 3
Source File: StepMetrics.java From titus-control-plane with Apache License 2.0 | 5 votes |
StepMetrics(String stepName, TitusRuntime titusRuntime) { Registry registry = titusRuntime.getRegistry(); Id baseCounterId = registry.createId(RelocationMetrics.METRIC_ROOT + "steps", "step", stepName); this.successCounter = registry.counter(baseCounterId.withTag("status", "success")); this.failureCounter = registry.counter(baseCounterId.withTag("status", "failure")); Id baseTimerId = registry.createId(RelocationMetrics.METRIC_ROOT + "steps", "stepExecutionTime", stepName); this.successExecutionTime = registry.timer(baseTimerId.withTag("status", "success")); this.failureExecutionTime = registry.timer(baseTimerId.withTag("status", "failure")); }
Example 4
Source File: ContinuousSubscriptionMetrics.java From titus-control-plane with Apache License 2.0 | 5 votes |
ContinuousSubscriptionMetrics(String root, List<Tag> commonTags, Registry registry) { this.registry = registry; this.latency = registry.timer(root + ".latency", commonTags); this.shouldRemove = new AtomicBoolean(false); this.hasSubscribed = new AtomicBoolean(false); this.latencyStart = new AtomicLong(0); this.lastCompleteTimestamp = new AtomicLong(registry.clock().wallTime()); this.timeSinceLastCompleteId = registry.createId(root + ".timeSinceLastComplete", commonTags); PolledMeter.using(registry) .withId(timeSinceLastCompleteId) .monitorValue(this, ContinuousSubscriptionMetrics::getTimeSinceLastComplete); asCompletable = new CompletableTransformer(); }
Example 5
Source File: ActionMetrics.java From titus-control-plane with Apache License 2.0 | 5 votes |
public ActionMetrics(Id rootId, Registry registry) { this.root = rootId.name(); this.commonTags = rootId.tags(); this.registry = registry; this.successCounter = registry.counter(registry.createId(root, commonTags).withTag("status", "success")); this.latencyTimerOnSuccess = registry.timer(registry.createId(root + ".latency", commonTags).withTag("status", "success")); this.latencyTimerOnError = registry.timer(registry.createId(root + ".latency", commonTags).withTag("status", "failure")); this.sinceLastExecutionId = registry.createId(root + ".sinceLastCompletion", commonTags); this.lastCompletionRef = new AtomicLong(registry.clock().wallTime()); PolledMeter.using(registry).withId(sinceLastExecutionId).monitorValue(lastCompletionRef); }
Example 6
Source File: ReactorSerializedInvokerMetrics.java From titus-control-plane with Apache License 2.0 | 5 votes |
ReactorSerializedInvokerMetrics(String name, Registry registry) { this.name = name; this.registry = registry; this.submitCounter = registry.counter(ROOT_NAME + "submit", "name", name); this.queueFullCounter = registry.counter(ROOT_NAME + "queueFull", "name", name); this.queueSize = registry.gauge(ROOT_NAME + "queueSize", "name", name); this.queueingTimer = registry.timer(ROOT_NAME + "queueingTime", "name", name); this.executionTimer = registry.timer(ROOT_NAME + "executionTime", "name", name, "status", "success"); this.executionErrorTimer = registry.timer(ROOT_NAME + "executionTime", "name", name, "status", "error"); this.executionDisposedTimer = registry.timer(ROOT_NAME + "executionTime", "name", name, "status", "disposed"); }
Example 7
Source File: ElasticSearchEventHandlers.java From metacat with Apache License 2.0 | 5 votes |
/** * Constructor. * * @param es elastic search util * @param registry registry to spectator * @param config configurations */ public ElasticSearchEventHandlers(final ElasticSearchUtil es, final Registry registry, final Config config) { this.es = es; this.metacatJsonLocator = new MetacatJsonLocator(); this.config = config; this.databaseCreateEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "database.create"); this.databaseCreateTimer = registry.timer(Metrics.TimerElasticSearchDatabaseCreate.getMetricName()); this.tableCreateEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "table.create"); this.tableCreateTimer = registry.timer(Metrics.TimerElasticSearchTableCreate.getMetricName()); this.databaseDeleteEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "database.delete"); this.databaseDeleteTimer = registry.timer(Metrics.TimerElasticSearchDatabaseDelete.getMetricName()); this.tableDeleteEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "table.delete"); this.tableDeleteTimer = registry.timer(Metrics.TimerElasticSearchTableDelete.getMetricName()); this.partitionDeleteEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "partition.delete"); this.partitionDeleteTimer = registry.timer(Metrics.TimerElasticSearchPartitionDelete.getMetricName()); this.tableRenameEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "table.rename"); this.tableRenameTimer = registry.timer(Metrics.TimerElasticSearchTableRename.getMetricName()); this.tableUpdateEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "table.update"); this.tableUpdateTimer = registry.timer(Metrics.TimerElasticSearchTableUpdate.getMetricName()); this.partitionSaveEventsDelayTimer = registry.timer(Metrics.TimerElasticSearchEventsDelay.getMetricName(), Metrics.TagEventsType.getMetricName(), "partition.save"); this.partitionSaveTimer = registry.timer(Metrics.TimerElasticSearchPartitionSave.getMetricName()); }
Example 8
Source File: CaffeineStatsCounter.java From kork with Apache License 2.0 | 5 votes |
/** * Constructs an instance for use by a single cache. * * @param registry the registry of metric instances * @param metricsPrefix the prefix name for the metrics */ public CaffeineStatsCounter(Registry registry, String metricsPrefix) { hitCount = registry.counter(metricsPrefix + ".hits"); missCount = registry.counter(metricsPrefix + ".misses"); totalLoadTime = registry.timer(metricsPrefix + ".loads"); loadSuccessCount = registry.counter(metricsPrefix + ".loads-success"); loadFailureCount = registry.counter(metricsPrefix + ".loads-failure"); evictionCount = registry.counter(metricsPrefix + ".evictions"); evictionWeight = registry.counter(metricsPrefix + ".evictions-weight"); }
Example 9
Source File: PercentileTimer.java From spectator with Apache License 2.0 | 5 votes |
/** Create a new instance. */ private PercentileTimer( Registry registry, Id id, long min, long max, AtomicReferenceArray<Counter> counters) { this.registry = registry; this.id = id; this.timer = registry.timer(id); this.min = min; this.max = max; this.counters = counters; }
Example 10
Source File: Scheduler.java From spectator with Apache License 2.0 | 5 votes |
/** 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"); }
Example 11
Source File: KubeApiServerIntegrator.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Inject public KubeApiServerIntegrator(TitusRuntime titusRuntime, MesosConfiguration mesosConfiguration, DirectKubeConfiguration directKubeConfiguration, @Named(GC_UNKNOWN_PODS) FixedIntervalTokenBucketConfiguration gcUnknownPodsTokenBucketConfiguration, LocalScheduler scheduler, Injector injector, KubeApiFacade kubeApiFacade, ContainerResultCodeResolver containerResultCodeResolver) { this.titusRuntime = titusRuntime; this.mesosConfiguration = mesosConfiguration; this.directKubeConfiguration = directKubeConfiguration; this.gcUnknownPodsTokenBucketConfiguration = gcUnknownPodsTokenBucketConfiguration; this.scheduler = scheduler; this.clock = titusRuntime.getClock(); this.injector = injector; this.kubeApiFacade = kubeApiFacade; this.containerResultCodeResolver = containerResultCodeResolver; this.vmTaskStatusObserver = PublishSubject.create(); Registry registry = titusRuntime.getRegistry(); launchTaskCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "launchTask"); launchTasksTimer = registry.timer(MetricConstants.METRIC_KUBERNETES + "launchTasksLatency"); this.podSizeMetrics = BucketCounter.get( registry, registry.createId(MetricConstants.METRIC_KUBERNETES + "podSize"), BucketFunctions.bytes(32768) ); rejectLeaseCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "rejectLease"); killTaskCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "killTask"); nodeAddCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "nodeAdd"); nodeUpdateCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "nodeUpdate"); nodeDeleteCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "nodeDelete"); podAddCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "podAdd"); podUpdateCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "podUpdate"); podDeleteCounter = registry.counter(MetricConstants.METRIC_KUBERNETES + "podDelete"); timedOutNodesToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "timedOutNodesToGc"); orphanedPodsWithoutValidNodesToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "orphanedPodsWithoutValidNodesToGc"); terminalPodsToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "terminalPodsToGc"); potentialUnknownPodsToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "potentialUnknownPodsToGc"); unknownPodsToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "unknownPodsToGc"); podsPastDeletionTimestampToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "podsPastDeletionTimestampToGc"); pendingPodsWithDeletionTimestampToGcGauge = registry.gauge(MetricConstants.METRIC_KUBERNETES + "pendingPodsWithDeletionTimestampToGc"); }
Example 12
Source File: DefaultReconciliationFramework.java From titus-control-plane with Apache License 2.0 | 4 votes |
public DefaultReconciliationFramework(List<InternalReconciliationEngine<EVENT>> bootstrapEngines, Function<EntityHolder, InternalReconciliationEngine<EVENT>> engineFactory, long idleTimeoutMs, long activeTimeoutMs, Map<Object, Comparator<EntityHolder>> indexComparators, Registry registry, Optional<Scheduler> optionalScheduler) { Preconditions.checkArgument(idleTimeoutMs > 0, "idleTimeout <= 0 (%s)", idleTimeoutMs); Preconditions.checkArgument(activeTimeoutMs <= idleTimeoutMs, "activeTimeout(%s) > idleTimeout(%s)", activeTimeoutMs, idleTimeoutMs); this.engineFactory = engineFactory; this.indexSet = IndexSet.newIndexSet(indexComparators); this.idleTimeoutMs = idleTimeoutMs; this.activeTimeoutMs = activeTimeoutMs; if (optionalScheduler.isPresent()) { this.scheduler = optionalScheduler.get(); this.executor = null; } else { this.executor = Executors.newSingleThreadExecutor(runnable -> { Thread thread = new Thread(runnable, "TitusReconciliationFramework"); thread.setDaemon(true); return thread; }); this.scheduler = Schedulers.from(executor); } this.worker = scheduler.createWorker(); this.eventsObservable = Observable.merge(eventsMergeSubject).share(); // To keep eventsObservable permanently active. this.internalEventSubscription = eventsObservable.subscribe(ObservableExt.silentSubscriber()); this.loopExecutionTime = registry.timer(LOOP_EXECUTION_TIME_METRIC); this.lastFullCycleExecutionTimeMs = scheduler.now() - idleTimeoutMs; this.lastExecutionTimeMs = scheduler.now(); PolledMeter.using(registry).withName(LAST_EXECUTION_TIME_METRIC).monitorValue(this, self -> scheduler.now() - self.lastExecutionTimeMs); PolledMeter.using(registry).withName(LAST_FULL_CYCLE_EXECUTION_TIME_METRIC).monitorValue(this, self -> scheduler.now() - self.lastFullCycleExecutionTimeMs); engines.addAll(bootstrapEngines); bootstrapEngines.forEach(engine -> eventsMergeSubject.onNext(engine.events())); updateIndexSet(); }
Example 13
Source File: HiveConnectorFastServiceMetric.java From metacat with Apache License 2.0 | 4 votes |
private Timer createTimer(final Registry registry, final String requestTag) { final HashMap<String, String> tags = new HashMap<>(); tags.put("request", requestTag); return registry.timer(registry.createId(HiveMetrics.TimerFastHiveRequest.getMetricName()).withTags(tags)); }
Example 14
Source File: ServoTimerTest.java From spectator with Apache License 2.0 | 4 votes |
private Timer newTimer(String name) { final Registry r = Servo.newRegistry(clock); return r.timer(r.createId(name)); }
Example 15
Source File: SpectatorServiceMetricCollector.java From spectator with Apache License 2.0 | 4 votes |
/** Create a new instance. */ SpectatorServiceMetricCollector(Registry registry) { super(); this.clientGetConnectionTime = registry.timer("aws.request.httpClientGetConnectionTime"); }
Example 16
Source File: StorageServiceSupport.java From front50 with Apache License 2.0 | 4 votes |
public StorageServiceSupport( ObjectType objectType, StorageService service, Scheduler scheduler, ObjectKeyLoader objectKeyLoader, long refreshIntervalMs, boolean shouldWarmCache, Registry registry, CircuitBreakerRegistry circuitBreakerRegistry) { this.objectType = objectType; this.service = service; this.scheduler = scheduler; this.objectKeyLoader = objectKeyLoader; this.refreshIntervalMs = refreshIntervalMs; if (refreshIntervalMs >= getHealthMillis()) { throw new IllegalArgumentException( "Cache refresh time must be more frequent than cache health timeout"); } this.shouldWarmCache = shouldWarmCache; this.registry = registry; this.circuitBreakerRegistry = circuitBreakerRegistry; String typeName = objectType.name(); this.autoRefreshTimer = registry.timer( registry.createId("storageServiceSupport.autoRefreshTime", "objectType", typeName)); this.scheduledRefreshTimer = registry.timer( registry.createId( "storageServiceSupport.scheduledRefreshTime", "objectType", typeName)); this.addCounter = registry.counter( registry.createId("storageServiceSupport.numAdded", "objectType", typeName)); this.removeCounter = registry.counter( registry.createId("storageServiceSupport.numRemoved", "objectType", typeName)); this.updateCounter = registry.counter( registry.createId("storageServiceSupport.numUpdated", "objectType", typeName)); this.mismatchedIdCounter = registry.counter( registry.createId("storageServiceSupport.mismatchedIds", "objectType", typeName)); registry.gauge( registry.createId("storageServiceSupport.cacheSize", "objectType", typeName), this, new ToDoubleFunction() { @Override public double applyAsDouble(Object ignore) { Set itemCache = allItemsCache.get(); return itemCache != null ? itemCache.size() : 0; } }); registry.gauge( registry.createId("storageServiceSupport.cacheAge", "objectType", typeName), lastRefreshedTime, (lrt) -> Long.valueOf(System.currentTimeMillis() - lrt.get()).doubleValue()); }