Java Code Examples for com.netflix.spectator.api.Registry#gauge()

The following examples show how to use com.netflix.spectator.api.Registry#gauge() . 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: ClusterRemovableInstanceGroupAgentRemover.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public ClusterRemovableInstanceGroupAgentRemover(TitusRuntime titusRuntime,
                                                 ClusterOperationsConfiguration configuration,
                                                 AgentManagementService agentManagementService,
                                                 V3JobOperations v3JobOperations,
                                                 Scheduler scheduler) {
    this.titusRuntime = titusRuntime;
    this.configuration = configuration;
    this.agentManagementService = agentManagementService;
    this.v3JobOperations = v3JobOperations;
    this.scheduler = scheduler;
    this.agentInstancesBeingTerminated = CacheBuilder.newBuilder()
            .expireAfterWrite(AGENT_INSTANCES_BEING_TERMINATED_TTL_MS, TimeUnit.MILLISECONDS)
            .build();

    Registry registry = titusRuntime.getRegistry();
    totalAgentsToRemoveGauge = registry.gauge(METRIC_ROOT + "totalAgentsToRemove");
    totalEligibleAgentsToRemoveGauge = registry.gauge(METRIC_ROOT + "totalEligibleAgentsToRemove");
    totalAgentsBeingRemovedGauge = registry.gauge(METRIC_ROOT + "totalAgentsBeingRemoved");
    createTokenBucket();
}
 
Example 2
Source File: ClusterAgentAutoScaler.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
TierAutoScalerExecution(Tier tier, Registry registry) {
    List<Tag> commonTags = singletonList(new BasicTag("tier", tier.name()));
    totalIdleInstancesGauge = registry.gauge(METRIC_ROOT + "totalIdleInstances", commonTags);
    totalFailedTasksGauge = registry.gauge(METRIC_ROOT + "totalFailedTasks", commonTags);
    totalTasksPastSloGauge = registry.gauge(METRIC_ROOT + "totalTasksPastSlo", commonTags);
    totalTasksForScaleUpGauge = registry.gauge(METRIC_ROOT + "totalTasksForScaleUp", commonTags);
    totalAgentsToScaleUpGauge = registry.gauge(METRIC_ROOT + "totalAgentsToScaleUp", commonTags);
    totalAgentsBeingScaledUpGauge = registry.gauge(METRIC_ROOT + "totalAgentsBeingScaledUp", commonTags);
    totalAgentsToScaleDownGauge = registry.gauge(METRIC_ROOT + "totalAgentsToScaleDown", commonTags);
    totalAgentsBeingScaledDownGauge = registry.gauge(METRIC_ROOT + "totalAgentsBeingScaledDown", commonTags);

    ImmutableRefillStrategy scaleUpRefillStrategy = ImmutableLimiters.refillAtFixedInterval(SCALE_UP_TOKEN_BUCKET_REFILL_AMOUNT,
            SCALE_UP_TOKEN_BUCKET_REFILL_INTERVAL_MS, TimeUnit.MILLISECONDS);
    lastScaleUpTokenBucket = ImmutableLimiters.tokenBucket(SCALE_UP_TOKEN_BUCKET_CAPACITY, scaleUpRefillStrategy);

    ImmutableRefillStrategy scaleDownRefillStrategy = ImmutableLimiters.refillAtFixedInterval(SCALE_DOWN_TOKEN_BUCKET_REFILL_AMOUNT,
            SCALE_DOWN_TOKEN_BUCKET_REFILL_INTERVAL_MS, TimeUnit.MILLISECONDS);
    lastScaleDownTokenBucket = ImmutableLimiters.tokenBucket(SCALE_DOWN_TOKEN_BUCKET_CAPACITY, scaleDownRefillStrategy);
}
 
Example 3
Source File: ClusterRemovableAgentRemover.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public ClusterRemovableAgentRemover(TitusRuntime titusRuntime,
                                    ClusterOperationsConfiguration configuration,
                                    AgentManagementService agentManagementService,
                                    V3JobOperations v3JobOperations,
                                    Scheduler scheduler) {
    this.titusRuntime = titusRuntime;
    this.configuration = configuration;
    this.agentManagementService = agentManagementService;
    this.v3JobOperations = v3JobOperations;
    this.scheduler = scheduler;
    this.agentInstancesBeingTerminated = CacheBuilder.newBuilder()
            .expireAfterWrite(AGENT_INSTANCES_BEING_TERMINATED_TTL_MS, TimeUnit.MILLISECONDS)
            .build();

    Registry registry = titusRuntime.getRegistry();
    totalAgentsToRemoveGauge = registry.gauge(METRIC_ROOT + "totalAgentsToRemove");
    totalEligibleAgentsToRemoveGauge = registry.gauge(METRIC_ROOT + "totalEligibleAgentsToRemove");
    totalAgentsBeingRemovedGauge = registry.gauge(METRIC_ROOT + "totalAgentsBeingRemoved");
    createTokenBucket();
}
 
Example 4
Source File: ReconciliationEngineMetrics.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
ReconciliationEngineMetrics(Function<ChangeAction, List<Tag>> extraChangeActionTags,
                            Function<EVENT, List<Tag>> extraModelActionTags,
                            Registry registry,
                            Clock clock) {
    this.extraChangeActionTags = extraChangeActionTags;
    this.extraModelActionTags = extraModelActionTags;
    this.registry = registry;
    this.clock = clock;

    List<Tag> commonTags = Collections.emptyList();
    this.evaluationId = registry.createId(EVALUATIONS, commonTags);
    this.startedChangeActionsId = registry.createId(STARTED_CHANGE_ACTIONS, commonTags);
    this.finishedChangeActionId = registry.createId(FINISHED_CHANGE_ACTIONS, commonTags);
    this.emittedEventId = registry.createId(EMITTED_EVENTS, commonTags);

    this.changeActionQueueSize = registry.gauge(registry.createId(ROOT_NAME + "changeActionQueueSize", commonTags));
    PolledMeter.using(registry).withName(PENDING_CHANGE_ACTIONS).withTags(commonTags).monitorValue(pendingChangeActions);
}
 
Example 5
Source File: InitializationErrorCollector.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
InitializationErrorCollector(JobManagerConfiguration jobManagerConfiguration, TitusRuntime titusRuntime) {
    this.jobManagerConfiguration = jobManagerConfiguration;
    this.titusRuntime = titusRuntime;

    Registry registry = titusRuntime.getRegistry();
    this.corruptedJobRecordsGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "corruptedJobRecords");
    this.corruptedTaskRecordsGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "corruptedTaskRecords");
    this.invalidJobsGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "invalidJobs");
    this.strictlyInvalidJobsGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "strictlyInvalidJobs");
    this.invalidTasksGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "invalidTasks");
    this.strictlyInvalidTasksGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "strictlyInvalidTasks");
    this.failedToAddToFenzoTaskGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "failedToAddToFenzoTask");
    this.inconsistentTasksGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "inconsistentTasks");
    this.launchedTasksWithUnidentifiedAgentsGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "launchedTasksWithUnidentifiedAgents");
    this.eniOverlapsGauge = registry.gauge(JobReconciliationFrameworkFactory.ROOT_METRIC_NAME + "eniOverlaps");
}
 
Example 6
Source File: ServerChannelMetrics.java    From zuul with Apache License 2.0 5 votes vote down vote up
public ServerChannelMetrics(String id, Registry registry) {
    String metricNamePrefix = "server.connections.";
    currentConnectionsGauge = registry.gauge(metricNamePrefix + "current", "id", id);
    totalConnections = registry.counter(metricNamePrefix + "connect", "id", id);
    connectionErrors = registry.counter(metricNamePrefix + "errors", "id", id);
    connectionClosed = registry.counter(metricNamePrefix + "close", "id", id);
    connectionIdleTimeout = registry.counter(metricNamePrefix + "idle.timeout", "id", id);
    connectionThrottled = registry.counter(metricNamePrefix + "throttled", "id", id);
}
 
Example 7
Source File: UserRolesSyncer.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Autowired
public UserRolesSyncer(
    Optional<DiscoveryClient> discoveryClient,
    Registry registry,
    LockManager lockManager,
    PermissionsRepository permissionsRepository,
    PermissionsResolver permissionsResolver,
    ResourceProvider<ServiceAccount> serviceAccountProvider,
    ResourceProvidersHealthIndicator healthIndicator,
    @Value("${fiat.write-mode.retry-interval-ms:10000}") long retryIntervalMs,
    @Value("${fiat.write-mode.sync-delay-ms:600000}") long syncDelayMs,
    @Value("${fiat.write-mode.sync-failure-delay-ms:600000}") long syncFailureDelayMs,
    @Value("${fiat.write-mode.sync-delay-timeout-ms:30000}") long syncDelayTimeoutMs) {
  this.discoveryClient = discoveryClient;

  this.lockManager = lockManager;
  this.permissionsRepository = permissionsRepository;
  this.permissionsResolver = permissionsResolver;
  this.serviceAccountProvider = serviceAccountProvider;
  this.healthIndicator = healthIndicator;

  this.retryIntervalMs = retryIntervalMs;
  this.syncDelayMs = syncDelayMs;
  this.syncFailureDelayMs = syncFailureDelayMs;
  this.syncDelayTimeoutMs = syncDelayTimeoutMs;

  this.isEnabled =
      new AtomicBoolean(
          // default to enabled iff discovery is not available
          !discoveryClient.isPresent());

  this.registry = registry;
  this.userRolesSyncCount = registry.gauge(metricName("syncCount"));
}
 
Example 8
Source File: RegistryUtil.java    From metacat with Apache License 2.0 5 votes vote down vote up
/**

     * Register the pool properties.
     * @param registry Spectator registry
     * @param name name of the monitor
     * @param pool thread pool
     */
    public static void registerThreadPool(final Registry registry,
        final String name,
        final ThreadPoolExecutor pool) {
        registry.gauge(NAME_MONITORED_POOL + name + "_" + "activeCount", pool, ThreadPoolExecutor::getActiveCount);
        registry.gauge(NAME_MONITORED_POOL + name + "_" + "completedTaskCount", pool,
            ThreadPoolExecutor::getCompletedTaskCount);
        registry.gauge(NAME_MONITORED_POOL + name + "_" + "corePoolSize", pool, ThreadPoolExecutor::getCorePoolSize);
        registry
            .gauge(NAME_MONITORED_POOL + name + "_" + "maximumPoolSize", pool, ThreadPoolExecutor::getMaximumPoolSize);
        registry.gauge(NAME_MONITORED_POOL + name + "_" + "poolSize", pool, ThreadPoolExecutor::getPoolSize);
        registry.collectionSize(NAME_MONITORED_POOL + name + "_" + "queueSize", pool.getQueue());
        registry.gauge(NAME_MONITORED_POOL + name + "_" + "taskCount", pool, ThreadPoolExecutor::getTaskCount);
    }
 
Example 9
Source File: ReactorSerializedInvokerMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
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 10
Source File: InstrumentedCache.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public InstrumentedCache(String metricNameRoot, Cache<K, V> cache, Registry registry) {
    this.cache = cache;

    Preconditions.checkNotNull(registry, "registry");
    Preconditions.checkNotNull(cache, "cache");

    String metricPrefix = metricNameRoot + ".cache.";
    requestCountGauge = registry.gauge(metricPrefix + "requestCount");
    hitCountGauge = registry.gauge(metricPrefix + "hitCount");
    missCountGauge = registry.gauge(metricPrefix + "missCount");
    loadSuccessCountGauge = registry.gauge(metricPrefix + "loadSuccessCount");
    loadFailureCountGauge = registry.gauge(metricPrefix + "loadFailureCount");
    totalLoadTimeGauge = registry.gauge(metricPrefix + "totalLoadTime");
    evictionCountGauge = registry.gauge(metricPrefix + "evictionCount");
    evictionWeightGauge = registry.gauge(metricPrefix + "evictionWeight");
    estimatedSizeGauge = registry.gauge(metricPrefix + "estimatedSize");

    metricSubscription = ObservableExt.schedule(metricNameRoot, registry, UPDATE_CACHE_METRICS_NAME,
            Completable.fromAction(this::updateMetrics), 0, UPDATE_METRICS_INTERVAL_SEC, TimeUnit.SECONDS, Schedulers.computation()
    ).subscribe(
            next -> {
                if (next.isPresent()) {
                    Throwable cause = next.get();
                    logger.error("Unable to update cache metrics with error", cause);
                } else {
                    logger.debug("Successfully updated cache metrics");
                }
            }
    );
}
 
Example 11
Source File: SubscriptionMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
SubscriptionMetrics(String root, List<Tag> commonTags, Registry registry) {
    this.rootId = registry.createId(root, commonTags);
    this.registry = registry;
    this.onNextCounter = registry.counter(root + ".onNext", commonTags);
    this.unsubscribed = registry.gauge(rootId.withTag("status", "unsubscribed"), new AtomicInteger());
    this.lastEmitTimestamp = new AtomicLong(registry.clock().wallTime());
    registry.gauge(
            registry.createId(root + ".lastEmit", commonTags),
            0L,
            this::getTimeSinceLastEmit
    );
}
 
Example 12
Source File: ValueRangeMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private void buildValueGauge(Id rootId, SOURCE source, Function<SOURCE, Long> valueSupplier, Registry registry) {
    registry.gauge(
            registry.createId(rootId.name() + "current", rootId.tags()),
            source, sourceArg -> {
                long newValue = valueSupplier.apply(sourceArg);
                return newValue < 0 ? 0 : newValue;
            }
    );
}
 
Example 13
Source File: AppScaleManagerMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public AppScaleManagerMetrics(Registry registry) {
    errorMetricId = registry.createId(METRIC_APPSCALE_ERRORS);
    fsmMetricsMap = new ConcurrentHashMap<>();
    numTargets = registry.gauge(METRIC_TITUS_APPSCALE_NUM_TARGETS, new AtomicInteger(0));
    this.registry = registry;
    droppedRequestsCount = registry.counter(METRIC_BACK_PRESSURE_DROP_COUNT);
}
 
Example 14
Source File: ResourceConsumptionServiceMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
ResourceConsumptionServiceMetrics(Id rootId, Registry registry) {
    this.rootId = rootId;
    this.registry = registry;
    this.updateTimestamp = registry.clock().wallTime();

    registry.gauge(
            registry.createId(rootId.name() + "updateDelay", rootId.tags()),
            this,
            self -> (registry.clock().wallTime() - updateTimestamp)
    );
}
 
Example 15
Source File: AgentStatusMonitorMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public AgentStatusMonitorMetrics(String name, Registry registry) {
    this.rootName = MetricConstants.METRIC_AGENT_MONITOR + name + '.';
    this.registry = registry;

    registry.gauge(newId("agentCount"), this, self -> self.statusByAgent.size());
    for (AgentStatusCode status : AgentStatusCode.values()) {
        registry.gauge(newId("status").withTag("status", status.name()), status, s -> statusMap.get(status));
    }
}
 
Example 16
Source File: KubeApiServerIntegrator.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: StorageServiceSupport.java    From front50 with Apache License 2.0 4 votes vote down vote up
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());
}