Java Code Examples for io.micrometer.core.instrument.MeterRegistry#counter()
The following examples show how to use
io.micrometer.core.instrument.MeterRegistry#counter() .
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: RequestMetricSupport.java From armeria with Apache License 2.0 | 6 votes |
AbstractRequestMetrics(MeterRegistry parent, MeterIdPrefix idPrefix) { final String requests = idPrefix.name("requests"); success = parent.counter(requests, idPrefix.tags("result", "success")); failure = parent.counter(requests, idPrefix.tags("result", "failure")); requestDuration = newTimer( parent, idPrefix.name(Flags.useLegacyMeterNames() ? "requestDuration" : "request.duration"), idPrefix.tags()); requestLength = newDistributionSummary( parent, idPrefix.name(Flags.useLegacyMeterNames() ? "requestLength" : "request.length"), idPrefix.tags()); responseDuration = newTimer( parent, idPrefix.name(Flags.useLegacyMeterNames() ? "responseDuration" : "response.duration"), idPrefix.tags()); responseLength = newDistributionSummary( parent, idPrefix.name(Flags.useLegacyMeterNames() ? "responseLength" : "response.length"), idPrefix.tags()); totalDuration = newTimer( parent, idPrefix.name(Flags.useLegacyMeterNames() ? "totalDuration" : "total.duration"), idPrefix.tags()); }
Example 2
Source File: KafkaMetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Issue("#1968") @Test void shouldBindMetersWithDifferentClientIds() { Supplier<Map<MetricName, ? extends Metric>> supplier = () -> { Map<String, String> firstTags = new LinkedHashMap<>(); firstTags.put("key0", "value0"); firstTags.put("client-id", "client0"); MetricName firstName = new MetricName("a", "b", "c", firstTags); KafkaMetric firstMetric = new KafkaMetric(this, firstName, new Value(), new MetricConfig(), Time.SYSTEM); return Collections.singletonMap(firstName, firstMetric); }; kafkaMetrics = new KafkaMetrics(supplier); MeterRegistry registry = new SimpleMeterRegistry(); registry.counter("kafka.b.a", "client-id", "client1", "key0", "value0"); kafkaMetrics.bindTo(registry); assertThat(registry.getMeters()).hasSize(2); }
Example 3
Source File: CrazyCharactersSample.java From micrometer with Apache License 2.0 | 6 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); String badCounterName = "\"\';^*()!~`_./?a{counter}:with123 weirdChars"; String badTagName = "\"\';^*()!~`_./?a{tag}:with123 weirdChars"; String badValueName = "\"\';^*()!~`_./?a{value}:with123 weirdChars"; Counter counter = registry.counter(badCounterName, badTagName, badValueName); RandomEngine r = new MersenneTwister64(0); Normal dist = new Normal(0, 1, r); Flux.interval(Duration.ofMillis(10)) .doOnEach(d -> { if (dist.nextDouble() + 0.1 > 0) { counter.increment(); } }) .blockLast(); }
Example 4
Source File: CounterSample.java From micrometer with Apache License 2.0 | 6 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); Counter counter = registry.counter("counter", "method", "actual"); AtomicInteger n = new AtomicInteger(0); registry.more().counter("counter", Tags.of("method", "function"), n); RandomEngine r = new MersenneTwister64(0); Normal dist = new Normal(0, 1, r); Flux.interval(Duration.ofMillis(10)) .doOnEach(d -> { if (dist.nextDouble() + 0.1 > 0) { counter.increment(); n.incrementAndGet(); } }) .blockLast(); }
Example 5
Source File: GRpcAgentFileStreamServiceImpl.java From genie with Apache License 2.0 | 6 votes |
private TransferManager( final ControlStreamManager controlStreamsManager, final TaskScheduler taskScheduler, final AgentFileStreamProperties properties, final MeterRegistry registry ) { this.controlStreamsManager = controlStreamsManager; this.taskScheduler = taskScheduler; this.properties = properties; this.registry = registry; this.transferTimeOutCounter = registry.counter(TRANSFER_TIMEOUT_COUNTER); this.transferSizeDistribution = registry.summary(TRANSFER_SIZE_DISTRIBUTION); this.taskScheduler.scheduleAtFixedRate( this::reapStalledTransfers, this.properties.getStalledTransferCheckInterval() ); }
Example 6
Source File: JobMonitoringCoordinator.java From genie with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param genieHostInfo Information about the host the Genie process is currently running on * @param dataServices The {@link DataServices} instance to use * @param genieEventBus The Genie event bus to use for publishing events * @param scheduler The task scheduler to use to register scheduling of job checkers * @param registry The metrics registry * @param jobsDir The directory where job output is stored * @param jobsProperties The properties pertaining to jobs * @param jobSubmitterService implementation of the job submitter service * @param processCheckerFactory The factory of process checkers * @throws IOException on error with the filesystem */ @Autowired public JobMonitoringCoordinator( final GenieHostInfo genieHostInfo, final DataServices dataServices, final GenieEventBus genieEventBus, @Qualifier("genieTaskScheduler") final TaskScheduler scheduler, final MeterRegistry registry, final Resource jobsDir, final JobsProperties jobsProperties, final JobSubmitterService jobSubmitterService, final ProcessChecker.Factory processCheckerFactory ) throws IOException { super(jobSubmitterService, scheduler, genieEventBus, registry); this.hostname = genieHostInfo.getHostname(); this.persistenceService = dataServices.getPersistenceService(); this.jobsDir = jobsDir.getFile(); this.jobsProperties = jobsProperties; this.processCheckerFactory = processCheckerFactory; // Automatically track the number of jobs running on this node this.unableToReAttach = registry.counter("genie.jobs.unableToReAttach.rate"); }
Example 7
Source File: RedisRemoteCache.java From curiostack with MIT License | 5 votes |
RedisRemoteCache(RedisClusterAsyncCommands<K, V> redis, String name, MeterRegistry registry) { this.redis = redis; this.name = name; String requests = DEFAULT_METER_ID_PREFIX.name("requests"); success = registry.counter( requests, DEFAULT_METER_ID_PREFIX.tags("result", "success", "cache", name)); failure = registry.counter( requests, DEFAULT_METER_ID_PREFIX.tags("result", "failure", "cache", name)); }
Example 8
Source File: GRpcAgentFileStreamServiceImpl.java From genie with Apache License 2.0 | 5 votes |
/** * Constructor. * * @param converter The {@link JobDirectoryManifestProtoConverter} instance to use * @param taskScheduler A {@link TaskScheduler} instance to use * @param properties The service properties * @param registry The meter registry */ public GRpcAgentFileStreamServiceImpl( final JobDirectoryManifestProtoConverter converter, final TaskScheduler taskScheduler, final AgentFileStreamProperties properties, final MeterRegistry registry ) { this.fileTransferLimitExceededCounter = registry.counter(TRANSFER_LIMIT_EXCEEDED_COUNTER); this.controlStreamsManager = new ControlStreamManager(converter, properties, registry); this.transferManager = new TransferManager(controlStreamsManager, taskScheduler, properties, registry); }
Example 9
Source File: JobStateServiceImpl.java From genie with Apache License 2.0 | 5 votes |
/** * Constructor. * * @param jobSubmitterService implementation of the job submitter service * @param scheduler The task scheduler to use to register scheduling of job checkers * @param genieEventBus The event bus to use to publish events * @param registry The metrics registry */ public JobStateServiceImpl( final JobSubmitterService jobSubmitterService, final TaskScheduler scheduler, final GenieEventBus genieEventBus, final MeterRegistry registry ) { this.jobSubmitterService = jobSubmitterService; this.scheduler = scheduler; this.registry = registry; this.genieEventBus = genieEventBus; this.unableToCancel = registry.counter("genie.jobs.unableToCancel.rate"); }
Example 10
Source File: DiskCleanupTask.java From genie with Apache License 2.0 | 5 votes |
/** * Constructor. Schedules this task to be run by the task scheduler. * * @param properties The disk cleanup properties to use. * @param scheduler The scheduler to use to schedule the cron trigger. * @param jobsDir The resource representing the location of the job directory * @param dataServices The {@link DataServices} instance to use * @param jobsProperties The jobs properties to use * @param processExecutor The process executor to use to delete directories * @param registry The metrics registry * @throws IOException When it is unable to open a file reference to the job directory */ public DiskCleanupTask( @NotNull final DiskCleanupProperties properties, @NotNull final TaskScheduler scheduler, @NotNull final Resource jobsDir, @NotNull final DataServices dataServices, @NotNull final JobsProperties jobsProperties, @NotNull final Executor processExecutor, @NotNull final MeterRegistry registry ) throws IOException { // Job Directory is guaranteed to exist by the MvcConfig bean creation but just in case someone overrides if (!jobsDir.exists()) { throw new IOException("Jobs dir " + jobsDir + " doesn't exist. Unable to create task to cleanup."); } this.properties = properties; this.jobsDir = jobsDir.getFile(); this.persistenceService = dataServices.getPersistenceService(); this.runAsUser = jobsProperties.getUsers().isRunAsUserEnabled(); this.processExecutor = processExecutor; this.numberOfDeletedJobDirs = registry.gauge( "genie.tasks.diskCleanup.numberDeletedJobDirs.gauge", new AtomicLong() ); this.numberOfDirsUnableToDelete = registry.gauge( "genie.tasks.diskCleanup.numberDirsUnableToDelete.gauge", new AtomicLong() ); this.unableToGetJobCounter = registry.counter("genie.tasks.diskCleanup.unableToGetJobs.rate"); this.unableToDeleteJobDirCounter = registry.counter("genie.tasks.diskCleanup.unableToDeleteJobsDir.rate"); // Only schedule the task if we don't need sudo while on a non-unix system if (this.runAsUser && !SystemUtils.IS_OS_UNIX) { log.error("System is not UNIX like. Unable to schedule disk cleanup due to needing Unix commands"); } else { final CronTrigger trigger = new CronTrigger(properties.getExpression(), JobConstants.UTC); scheduler.schedule(this, trigger); } }
Example 11
Source File: GreetingServiceBean.java From skeleton-ws-spring-boot with Apache License 2.0 | 5 votes |
/** * Construct a GreetingServiceBean. * * @param greetingRepository A GreetingRepository. * @param meterRegistry A MeterRegistry. */ @Autowired public GreetingServiceBean(final GreetingRepository greetingRepository, final MeterRegistry meterRegistry) { this.greetingRepository = greetingRepository; this.findAllMethodInvocationCounter = meterRegistry.counter("method.invoked.greetingServiceBean.findAll"); this.findOneMethodInvocationCounter = meterRegistry.counter("method.invoked.greetingServiceBean.findOne"); this.createMethodInvocationCounter = meterRegistry.counter("method.invoked.greetingServiceBean.create"); this.updateMethodInvocationCounter = meterRegistry.counter("method.invoked.greetingServiceBean.update"); this.deleteMethodInvocationCounter = meterRegistry.counter("method.invoked.greetingServiceBean.delete"); this.evictCacheMethodInvocationCounter = meterRegistry.counter("method.invoked.greetingServiceBean.evictCache"); }
Example 12
Source File: EventCounter.java From java-dcp-client with Apache License 2.0 | 5 votes |
private EventCounter(MeterRegistry registry, String name, Iterable<Tag> tags, LogLevel logLevel) { this.registry = requireNonNull(registry); this.name = requireNonNull(name); this.logLevel = requireNonNull(logLevel); this.logger = LoggerFactory.getLogger(EventCounter.class.getName() + "." + name); List<Tag> tagList = new ArrayList<>(); tags.forEach(tagList::add); this.baseTags = Collections.unmodifiableList(tagList); this.counter = registry.counter(name, baseTags); }
Example 13
Source File: LanderTaskRunner.java From data-highway with Apache License 2.0 | 5 votes |
public LanderTaskRunner( MeterRegistry registry, OffsetManager offsetManager, String roadName, String topicName, String database, HivePartitionManager hivePartitionManager, Lander.Factory landerFactory, HiveNotificationHandler landingHandler, PatchSetEmitter emitter, Clock clock, long maxRecordsPerPartition, boolean enableServerSideEncryption, int landingTimeoutMinutes) { this.offsetManager = offsetManager; this.roadName = roadName; this.topicName = topicName; this.database = database; this.hivePartitionManager = hivePartitionManager; this.landerFactory = landerFactory; this.landingHandler = landingHandler; this.emitter = emitter; this.clock = clock; this.maxRecordsPerPartition = maxRecordsPerPartition; this.enableServerSideEncryption = enableServerSideEncryption; this.landingTimeoutMinutes = landingTimeoutMinutes; landingTimer = Timer .builder("loading-bay.landing-time") .tag("road", roadName) .publishPercentileHistogram() .register(registry); partitionMutationCounter = registry.counter("loading-bay.partition-mutations", "road", roadName); metaStoreErrorMeter = registry.counter("loading-bay.meta-store-errors", "road", roadName); messagesLandedCounter = registry.counter("loading-bay.messages-landed", "road", roadName); changeState(State.IDLE); }
Example 14
Source File: CounterTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test @DisplayName("increment by a non-negative amount") default void incrementAmount(MeterRegistry registry) { Counter c = registry.counter("myCounter"); c.increment(2); c.increment(0); clock(registry).add(step()); assertEquals(2L, c.count()); }
Example 15
Source File: CounterTest.java From micrometer with Apache License 2.0 | 5 votes |
@DisplayName("multiple increments are maintained") @Test default void increment(MeterRegistry registry) { Counter c = registry.counter("myCounter"); c.increment(); clock(registry).add(step()); assertThat(c.count()).isEqualTo(1.0, offset(1e-12)); c.increment(); c.increment(); clock(registry).add(step()); // in the case of a step aggregating system will be 2, otherwise 3 assertThat(c.count()).isGreaterThanOrEqualTo(2.0); }
Example 16
Source File: S3FileTransferImpl.java From genie with Apache License 2.0 | 5 votes |
/** * Constructor. * * @param s3ClientFactory The S3 client factory to use * @param registry The metrics registry to use * @param s3FileTransferProperties Options */ public S3FileTransferImpl( @NotNull final S3ClientFactory s3ClientFactory, @NotNull final MeterRegistry registry, @NotNull final S3FileTransferProperties s3FileTransferProperties ) { this.s3ClientFactory = s3ClientFactory; this.registry = registry; this.urlFailingStrictValidationCounter = registry.counter(STRICT_VALIDATION_COUNTER_NAME); this.s3FileTransferProperties = s3FileTransferProperties; }
Example 17
Source File: JobRestController.java From genie with Apache License 2.0 | 4 votes |
/** * Constructor. * * @param jobLaunchService The {@link JobLaunchService} implementation to use * @param dataServices The {@link DataServices} instance to use * @param jobCoordinatorService The job coordinator service to use. * @param entityModelAssemblers The encapsulation of all the V3 resource assemblers * @param genieHostInfo Information about the host that the Genie process is running on * @param restTemplate The rest template for http requests * @param jobDirectoryServerService The service to handle serving back job directory resources * @param jobsProperties All the properties associated with jobs * @param registry The metrics registry to use * @param agentRoutingService Agent routing service * @param environment The application environment to pull dynamic properties from * @param attachmentService The attachment service to use to save attachments. * @param jobExecutionModeSelector The execution mode (agent vs. embedded) mode selector */ @Autowired @SuppressWarnings("checkstyle:parameternumber") public JobRestController( final JobLaunchService jobLaunchService, final DataServices dataServices, final JobCoordinatorService jobCoordinatorService, final EntityModelAssemblers entityModelAssemblers, final GenieHostInfo genieHostInfo, @Qualifier("genieRestTemplate") final RestTemplate restTemplate, final JobDirectoryServerService jobDirectoryServerService, final JobsProperties jobsProperties, final MeterRegistry registry, final AgentRoutingService agentRoutingService, final Environment environment, final AttachmentService attachmentService, final JobExecutionModeSelector jobExecutionModeSelector ) { this.jobLaunchService = jobLaunchService; this.jobCoordinatorService = jobCoordinatorService; this.applicationModelAssembler = entityModelAssemblers.getApplicationModelAssembler(); this.clusterModelAssembler = entityModelAssemblers.getClusterModelAssembler(); this.commandModelAssembler = entityModelAssemblers.getCommandModelAssembler(); this.jobModelAssembler = entityModelAssemblers.getJobModelAssembler(); this.jobRequestModelAssembler = entityModelAssemblers.getJobRequestModelAssembler(); this.jobExecutionModelAssembler = entityModelAssemblers.getJobExecutionModelAssembler(); this.jobMetadataModelAssembler = entityModelAssemblers.getJobMetadataModelAssembler(); this.jobSearchResultModelAssembler = entityModelAssemblers.getJobSearchResultModelAssembler(); this.hostname = genieHostInfo.getHostname(); this.restTemplate = restTemplate; this.jobDirectoryServerService = jobDirectoryServerService; this.jobsProperties = jobsProperties; this.agentRoutingService = agentRoutingService; this.persistenceService = dataServices.getPersistenceService(); this.environment = environment; // TODO: V3 Only. Remove. this.attachmentService = attachmentService; this.jobExecutionModeSelector = jobExecutionModeSelector; // Set up the metrics this.submitJobWithoutAttachmentsRate = registry.counter("genie.api.v3.jobs.submitJobWithoutAttachments.rate"); this.submitJobWithAttachmentsRate = registry.counter("genie.api.v3.jobs.submitJobWithAttachments.rate"); }
Example 18
Source File: MicrometerRSocket.java From rsocket-java with Apache License 2.0 | 4 votes |
private static Counter counter( MeterRegistry meterRegistry, String interactionModel, SignalType signalType, Tag... tags) { return meterRegistry.counter( "rsocket." + interactionModel, Tags.of(tags).and("signal.type", signalType.name())); }
Example 19
Source File: RequestMetricSupport.java From armeria with Apache License 2.0 | 4 votes |
DefaultServiceRequestMetrics(MeterRegistry parent, MeterIdPrefix idPrefix) { super(parent, idPrefix); requestTimeouts = parent.counter(idPrefix.name("timeouts"), idPrefix.tags("cause", "RequestTimeoutException")); }
Example 20
Source File: MeterPool.java From data-highway with Apache License 2.0 | 4 votes |
public MeterPool(MeterRegistry registry) { counterPool = new KeyedSharedObjectPool<NameAndTags, Counter>() { @Override protected Counter constructValue(NameAndTags key) { return registry.counter(key.getName(), key.getTags()); } @Override protected void destroyValue(NameAndTags key, Counter value) { registry.remove(value); } }; timeGaugePool = new KeyedSharedObjectPool<NameAndTags, SettableTimeGauge>() { @Override protected SettableTimeGauge constructValue(NameAndTags key) { AtomicLong value = new AtomicLong(); TimeGauge timeGauge = registry .more() .timeGauge(key.getName(), key.getTags(), value, MILLISECONDS, AtomicLong::doubleValue); return new SettableTimeGauge(timeGauge, value); } @Override protected void destroyValue(NameAndTags key, SettableTimeGauge value) { registry.remove(value); } }; timerPool = new KeyedSharedObjectPool<NameAndTags, Timer>() { @Override protected Timer constructValue(NameAndTags key) { return registry.timer(key.getName(), key.getTags()); } @Override protected void destroyValue(NameAndTags key, Timer value) { registry.remove(value); } }; gaugePool = new KeyedSharedObjectPool<MeterPool.NameAndTags, SettableGauge>() { @Override protected SettableGauge constructValue(NameAndTags key) { AtomicLong value = new AtomicLong(); Gauge gauge = Gauge.builder(key.getName(), value, AtomicLong::doubleValue).tags(key.getTags()).register(registry); return new SettableGauge(gauge, value); } @Override protected void destroyValue(NameAndTags key, SettableGauge value) { registry.remove(value); } }; }