io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics Java Examples
The following examples show how to use
io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics.
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: CentralDogma.java From centraldogma with Apache License 2.0 | 7 votes |
private void configureMetrics(ServerBuilder sb, PrometheusMeterRegistry registry) { sb.meterRegistry(registry); sb.service(METRICS_PATH, new PrometheusExpositionService(registry.getPrometheusRegistry())); sb.decorator(MetricCollectingService.newDecorator(MeterIdPrefixFunction.ofDefault("api"))); // Bind system metrics. new FileDescriptorMetrics().bindTo(registry); new ProcessorMetrics().bindTo(registry); new ClassLoaderMetrics().bindTo(registry); new UptimeMetrics().bindTo(registry); new DiskSpaceMetrics(cfg.dataDir()).bindTo(registry); new JvmGcMetrics().bindTo(registry); new JvmMemoryMetrics().bindTo(registry); new JvmThreadMetrics().bindTo(registry); // Bind global thread pool metrics. ExecutorServiceMetrics.monitor(registry, ForkJoinPool.commonPool(), "commonPool"); }
Example #2
Source File: ExecutorServiceSample.java From micrometer with Apache License 2.0 | 5 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor(); new ExecutorServiceMetrics(es, "executor.sample", emptyList()).bindTo(registry); es.scheduleWithFixedDelay(() -> Mono.delay(Duration.ofMillis(20)).block(), 0, 10, TimeUnit.MILLISECONDS); while (true) { } }
Example #3
Source File: MeteredExecutorServiceWrapper.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public ScheduledExecutorService wrap( ScheduledExecutorService executor, String name, String... tags) { monitorThreadPoolExecutor(executor, name, tags); return ExecutorServiceMetrics.monitor(meterRegistry, executor, name, Tags.of(tags)); }
Example #4
Source File: MeteredExecutorServiceWrapper.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public CronExecutorService wrap(CronExecutorService executor, String name, String... tags) { monitorThreadPoolExecutor(executor, name, tags); new io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics( executor, name, Tags.of(tags)) .bindTo(meterRegistry); return new TimedCronExecutorService(meterRegistry, executor, name, Tags.of(tags)); }
Example #5
Source File: CentralDogma.java From centraldogma with Apache License 2.0 | 4 votes |
private void doStart() throws Exception { boolean success = false; ExecutorService repositoryWorker = null; ScheduledExecutorService purgeWorker = null; ProjectManager pm = null; CommandExecutor executor = null; PrometheusMeterRegistry meterRegistry = null; Server server = null; SessionManager sessionManager = null; try { meterRegistry = PrometheusMeterRegistries.newRegistry(); logger.info("Starting the Central Dogma .."); final ThreadPoolExecutor repositoryWorkerImpl = new ThreadPoolExecutor( cfg.numRepositoryWorkers(), cfg.numRepositoryWorkers(), 60, TimeUnit.SECONDS, new LinkedTransferQueue<>(), new DefaultThreadFactory("repository-worker", true)); repositoryWorkerImpl.allowCoreThreadTimeOut(true); repositoryWorker = ExecutorServiceMetrics.monitor(meterRegistry, repositoryWorkerImpl, "repositoryWorker"); logger.info("Starting the project manager: {}", cfg.dataDir()); purgeWorker = Executors.newSingleThreadScheduledExecutor( new DefaultThreadFactory("purge-worker", true)); pm = new DefaultProjectManager(cfg.dataDir(), repositoryWorker, purgeWorker, meterRegistry, cfg.repositoryCacheSpec()); logger.info("Started the project manager: {}", pm); logger.info("Current settings:\n{}", cfg); sessionManager = initializeSessionManager(); logger.info("Starting the command executor .."); executor = startCommandExecutor(pm, repositoryWorker, purgeWorker, meterRegistry, sessionManager); if (executor.isWritable()) { logger.info("Started the command executor."); initializeInternalProject(executor); // Migrate tokens and create metadata files if it does not exist. MigrationUtil.migrate(pm, executor); } logger.info("Starting the RPC server."); server = startServer(pm, executor, meterRegistry, sessionManager); logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully."); success = true; } finally { if (success) { this.repositoryWorker = repositoryWorker; this.purgeWorker = purgeWorker; this.pm = pm; this.executor = executor; this.meterRegistry = meterRegistry; this.server = server; this.sessionManager = sessionManager; } else { doStop(server, executor, pm, repositoryWorker, purgeWorker, sessionManager); } } }
Example #6
Source File: ManualConfiguration.java From riptide with MIT License | 4 votes |
@Bean public MeterBinder executorServiceMetrics(final ExecutorService executor) { return new ExecutorServiceMetrics(executor, "http-example", singleton(Tag.of("clientId", "example"))); }
Example #7
Source File: MeteredExecutorServiceWrapper.java From che with Eclipse Public License 2.0 | 4 votes |
@Override public ExecutorService wrap(ExecutorService executor, String name, String... tags) { monitorThreadPoolExecutor(executor, name, tags); return ExecutorServiceMetrics.monitor(meterRegistry, executor, name, Tags.of(tags)); }
Example #8
Source File: SchedulerMetricDecorator.java From reactor-core with Apache License 2.0 | 4 votes |
@Override public synchronized ScheduledExecutorService apply(Scheduler scheduler, ScheduledExecutorService service) { //this is equivalent to `toString`, a detailed name like `parallel("foo", 3)` String schedulerName = Scannable .from(scheduler) .scanOrDefault(Attr.NAME, scheduler.getClass().getName()); //we hope that each NAME is unique enough, but we'll differentiate by Scheduler String schedulerId = seenSchedulers.computeIfAbsent(scheduler, s -> { int schedulerDifferentiator = this.schedulerDifferentiator .computeIfAbsent(schedulerName, k -> new AtomicInteger(0)) .getAndIncrement(); return (schedulerDifferentiator == 0) ? schedulerName : schedulerName + "#" + schedulerDifferentiator; }); //we now want an executorId unique to a given scheduler String executorId = schedulerId + "-" + executorDifferentiator.computeIfAbsent(scheduler, key -> new AtomicInteger(0)) .getAndIncrement(); Tags tags = Tags.of(TAG_SCHEDULER_ID, schedulerId); /* Design note: we assume that a given Scheduler won't apply the decorator twice to the same ExecutorService. Even though, it would simply create an extraneous meter for that ExecutorService, which we think is not that bad (compared to paying the price upfront of also tracking executors instances to deduplicate). The main goal is to detect Scheduler instances that have already started decorating their executors, in order to avoid consider two calls in a row as duplicates (yet still being able to distinguish between two instances with the same name and configuration). */ class MetricsRemovingScheduledExecutorService extends DelegatingScheduledExecutorService { MetricsRemovingScheduledExecutorService() { super(ExecutorServiceMetrics.monitor(globalRegistry, service, executorId, tags)); } @Override public List<Runnable> shutdownNow() { removeMetrics(); return super.shutdownNow(); } @Override public void shutdown() { removeMetrics(); super.shutdown(); } void removeMetrics() { Search.in(globalRegistry) .tag("name", executorId) .meters() .forEach(globalRegistry::remove); } } return new MetricsRemovingScheduledExecutorService(); }