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

The following examples show how to use com.netflix.spectator.api.Registry#createId() . 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: SchedulerMetrics.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
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 2
Source File: VertxMetersInitializer.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
  Registry registry = globalRegistry.getDefaultRegistry();

  Id endpointsId = registry.createId(VERTX_ENDPOINTS);
  VertxEndpointsMeter clientMeter = new HttpClientEndpointsMeter(
      endpointsId.withTag(ENDPOINTS_TYPE, ENDPOINTS_CLINET),
      SharedVertxFactory.getMetricsFactory()
          .getVertxMetrics()
          .getClientEndpointMetricManager()
          .getClientEndpointMetricMap());
  SpectatorUtils.registerMeter(registry, clientMeter);

  VertxEndpointsMeter serverMeter = new ServerEndpointsMeter(
      endpointsId.withTag(ENDPOINTS_TYPE, ENDPOINTS_SERVER),
      SharedVertxFactory.getMetricsFactory()
          .getVertxMetrics()
          .getServerEndpointMetricMap());
  SpectatorUtils.registerMeter(registry, serverMeter);
}
 
Example 3
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 4
Source File: PolledMeterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void monitorMonotonicCounterNull() {
  Registry r = new DefaultRegistry(Clock.SYSTEM, p -> null);
  Id id = r.createId("test");

  AtomicLong v = new AtomicLong(42);
  PolledMeter.using(r).withId(id).<AtomicLong>monitorMonotonicCounter(null, n -> v.get());
  PolledMeter.update(r);

  Assertions.assertEquals(0, r.counter(id).count());
}
 
Example 5
Source File: Http2ConnectionCloseHandler.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Inject
public Http2ConnectionCloseHandler(Registry registry)
{
    super();
    this.registry = registry;
    this.counterBaseId = registry.createId("server.connection.close.handled");
}
 
Example 6
Source File: TitusGatewayModule.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public TitusRuntime getTitusRuntime(SystemLogService systemLogService, SystemAbortListener systemAbortListener, Registry registry) {
    CodeInvariants codeInvariants = new CompositeCodeInvariants(
            LoggingCodeInvariants.getDefault(),
            new SpectatorCodeInvariants(registry.createId("titus.runtime.invariant.violations"), registry)
    );
    return new DefaultTitusRuntime(codeInvariants, systemLogService, false, systemAbortListener, registry);
}
 
Example 7
Source File: BalancedBucketManager.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public BalancedBucketManager(int initialBucketCount, int maxBucketSize, String metricNameRoot, Registry registry) {
    this.maxBucketSize = maxBucketSize;
    this.registry = registry;

    this.itemToBucket = new ConcurrentHashMap<>();
    this.bucketSizes = new ConcurrentHashMap<>();
    this.highestBucketIndex = new AtomicInteger();
    this.bucketWithLeastItems = new AtomicInteger();
    bucketSizeId = registry.createId(metricNameRoot + ".bucketSize");

    createInitialBuckets(initialBucketCount);
}
 
Example 8
Source File: PartitionServiceImpl.java    From metacat with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param catalogService       catalog service
 * @param connectorManager     connector manager
 * @param tableService         table service
 * @param userMetadataService  user metadata service
 * @param threadServiceManager thread manager
 * @param config               configurations
 * @param eventBus             Internal event bus
 * @param converterUtil        utility to convert to/from Dto to connector resources
 * @param registry             registry handle
 */
public PartitionServiceImpl(
    final CatalogService catalogService,
    final ConnectorManager connectorManager,
    final TableService tableService,
    final UserMetadataService userMetadataService,
    final ThreadServiceManager threadServiceManager,
    final Config config,
    final MetacatEventBus eventBus,
    final ConverterUtil converterUtil,
    final Registry registry
) {
    this.catalogService = catalogService;
    this.connectorManager = connectorManager;
    this.tableService = tableService;
    this.userMetadataService = userMetadataService;
    this.threadServiceManager = threadServiceManager;
    this.config = config;
    this.eventBus = eventBus;
    this.converterUtil = converterUtil;
    this.registry = registry;
    this.partitionAddDistSummary =
        registry.createId(Metrics.DistributionSummaryAddPartitions.getMetricName());
    this.partitionMetadataOnlyAddDistSummary =
        registry.createId(Metrics.DistributionSummaryMetadataOnlyAddPartitions.getMetricName());
    this.partitionGetDistSummary =
        registry.createId(Metrics.DistributionSummaryGetPartitions.getMetricName());
    this.partitionDeleteDistSummary =
        registry.createId(Metrics.DistributionSummaryDeletePartitions.getMetricName());
}
 
Example 9
Source File: JobAndTaskMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Inject
public JobAndTaskMetrics(ApplicationSlaManagementService applicationSlaManagementService,
                         V3JobOperations v3JobOperations,
                         JobManagerConfiguration configuration,
                         Registry registry) {
    this.applicationSlaManagementService = applicationSlaManagementService;
    this.v3JobOperations = v3JobOperations;
    this.configuration = configuration;
    this.registry = registry;

    this.jobCountId = registry.createId(JOBS_METRIC_NAME);
    this.taskCountId = registry.createId(TASKS_METRIC_NAME);
}
 
Example 10
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 11
Source File: IntervalCounterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncrement() {
  Registry r = new DefaultRegistry(clock);
  Id id = r.createId("test");
  Counter c = IntervalCounter.get(r, id);
  Assertions.assertEquals(0, c.count());
  c.increment();
  Assertions.assertEquals(1, c.count());
  c.increment(41);
  Assertions.assertEquals(42, c.count());
}
 
Example 12
Source File: DefaultLoadBalancerReconciler.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
DefaultLoadBalancerReconciler(LoadBalancerConfiguration configuration,
                              LoadBalancerStore store,
                              LoadBalancerConnector connector,
                              LoadBalancerJobOperations loadBalancerJobOperations,
                              Runnable afterReconciliation,
                              Registry registry,
                              Scheduler scheduler) {
    this.store = store;
    this.connector = connector;
    this.jobOperations = loadBalancerJobOperations;
    this.delayMs = configuration.getReconciliationDelayMs();
    this.timeoutMs = configuration::getReconciliationTimeoutMs;
    this.afterReconciliation = afterReconciliation;
    this.registry = registry;
    this.scheduler = scheduler;

    List<Tag> tags = Collections.singletonList(new BasicTag("class", DefaultLoadBalancerReconciler.class.getSimpleName()));
    final Id updatesCounterId = registry.createId(METRIC_RECONCILER + ".updates", tags);
    this.registerCounter = registry.counter(updatesCounterId.withTag("operation", "register"));
    this.deregisterCounter = registry.counter(updatesCounterId.withTag("operation", "deregister"));
    this.removeCounter = registry.counter(updatesCounterId.withTag("operation", "remove"));
    this.fullReconciliationMetrics = SpectatorExt.continuousSubscriptionMetrics(METRIC_RECONCILER + ".full", tags, registry);
    this.orphanUpdateMetrics = SpectatorExt.continuousSubscriptionMetrics(METRIC_RECONCILER + ".orphanUpdates", tags, registry);
    this.removeMetrics = SpectatorExt.continuousSubscriptionMetrics(METRIC_RECONCILER + ".remove", tags, registry);
    this.removeTargetsMetrics = SpectatorExt.continuousSubscriptionMetrics(METRIC_RECONCILER + ".removeTargets", tags, registry);
    this.registeredIpsMetrics = SpectatorExt.continuousSubscriptionMetrics(METRIC_RECONCILER + ".getRegisteredIps", tags, registry);
    this.ignoredMetricsId = registry.createId(METRIC_RECONCILER + ".ignored", tags);
    this.orphanMetricsId = registry.createId(METRIC_RECONCILER + ".orphan", tags);
    PolledMeter.using(registry).withId(ignoredMetricsId).monitorSize(ignored);
    PolledMeter.using(registry).withId(orphanMetricsId).monitorSize(markedAsOrphan);
}
 
Example 13
Source File: EmbeddedHiveClient.java    From metacat with Apache License 2.0 5 votes vote down vote up
/**
 * Embedded hive client implementation.
 *
 * @param catalogName catalogName
 * @param handler     handler
 * @param registry    registry
 */
public EmbeddedHiveClient(final String catalogName,
                          @Nullable final IMetacatHMSHandler handler,
                          final Registry registry) {
    this.handler = handler;
    this.registry = registry;
    this.requestTimerId = registry.createId(HiveMetrics.TimerHiveRequest.getMetricName());
    this.hiveSqlErrorCounter =
        registry.counter(HiveMetrics.CounterHiveSqlLockError.getMetricName() + "." + catalogName);
}
 
Example 14
Source File: PolledMeterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void monitorStaticMethodValue() {
  Registry r = new DefaultRegistry();
  Id id = r.createId("test");

  PolledMeter.using(r).withId(id).monitorStaticMethodValue(PolledMeterTest::testValue);
  PolledMeter.update(r);

  Assertions.assertEquals(42.0, r.gauge(id).value());
}
 
Example 15
Source File: ManyTags.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Override public void accept(Registry registry) {
  Random random = new Random(42);
  for (int i = 0; i < 10000; ++i) {
    Id id = registry.createId("manyTagsTest");
    for (int j = 0; j < 20; ++j) {
      String v = "" + random.nextInt(10);
      id = id.withTag("" + j, v);
    }
    registry.counter(id).increment();
  }
}
 
Example 16
Source File: StepMetrics.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
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 17
Source File: SpectatorExt.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
/**
 * Collection of metrics for tracking a status of an action run periodically.
 */
public static ActionMetrics actionMetrics(String rootName, List<Tag> tags, Registry registry) {
    return new ActionMetrics(registry.createId(rootName, tags), registry);
}
 
Example 18
Source File: AuthorizationMetrics.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
public AuthorizationMetrics(String authorizationName, Registry registry) {
    this.registry = registry;
    authorizationId = registry.createId(AUTHORIZATION_METRICS_ROOT + authorizationName);
}
 
Example 19
Source File: GcsStorageService.java    From front50 with Apache License 2.0 4 votes vote down vote up
public GcsStorageService(
    String bucketName,
    String bucketLocation,
    String basePath,
    String projectName,
    String credentialsPath,
    String applicationVersion,
    String dataFilename,
    Integer connectTimeoutSec,
    Integer readTimeoutSec,
    int maxWaitInterval,
    int retryIntervalBase,
    int jitterMultiplier,
    int maxRetries,
    TaskScheduler taskScheduler,
    Registry registry) {
  Storage storage;

  try {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    GoogleCredentials credentials = loadCredential(credentialsPath);
    HttpRequestInitializer requestInitializer =
        new HttpCredentialsAdapter(credentials) {
          public void initialize(HttpRequest request) throws IOException {
            super.initialize(request);
            request.setConnectTimeout(connectTimeoutSec * 1000);
            request.setReadTimeout(readTimeoutSec * 1000);
          }
        };

    String applicationName = "Spinnaker/" + applicationVersion;
    storage =
        new Storage.Builder(httpTransport, jsonFactory, requestInitializer)
            .setApplicationName(applicationName)
            .build();
  } catch (IOException | java.security.GeneralSecurityException e) {
    throw new IllegalStateException(e);
  }

  // "google.com:" is deprecated but may be in certain old projects.
  this.bucketName = bucketName.replace("google.com:", "");
  this.bucketLocation = bucketLocation;
  this.basePath = basePath;
  this.projectName = projectName;
  this.storage = storage;
  this.obj_api = this.storage.objects();
  this.dataFilename = dataFilename;
  this.taskScheduler = taskScheduler;
  this.registry = registry;
  this.safeRetry =
      GoogleCommonSafeRetry.builder()
          .maxWaitInterval(maxWaitInterval)
          .retryIntervalBase(retryIntervalBase)
          .jitterMultiplier(jitterMultiplier)
          .maxRetries(maxRetries)
          .build();

  Id id = registry.createId("google.storage.invocation");
  deleteTimer = id.withTag("method", "delete");
  purgeTimer = id.withTag("method", "purgeTimestamp");
  loadTimer = id.withTag("method", "load");
  listTimer = id.withTag("method", "list");
  mediaDownloadTimer = id.withTag("method", "mediaDownload");
  insertTimer = id.withTag("method", "insert");
  patchTimer = id.withTag("method", "patch");
}
 
Example 20
Source File: RxEventBusMetrics.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
RxEventBusMetrics(Id rootId, Registry registry) {
    this.eventCounterId = registry.createId(rootId.name() + "input", rootId.tags());
    this.subscriberMetricsId = registry.createId(rootId.name() + "subscribers", rootId.tags());
    this.registry = registry;
}