public static void registerWorkerHealthCheck(String name, HealthCheck healthCheck) { workerHealthCheck.register(name, healthCheck); }
public static void registerTaskHealthCheck(int taskId, String name, HealthCheck healthCheck) { HealthCheckRegistry healthCheckRegister = taskHealthCheckMap.get(taskId); if (healthCheckRegister == null) { healthCheckRegister = new HealthCheckRegistry(); taskHealthCheckMap.put(taskId, healthCheckRegister); } healthCheckRegister.register(name, healthCheck); }
@Override public void register(String name, HealthCheck healthCheck) { super.unregister(name); super.register(name, healthCheck); }
private static Set<StagemonitorPlugin> getPluginsToInit(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) { Set<StagemonitorPlugin> notYetInitialized = new HashSet<StagemonitorPlugin>(); for (StagemonitorPlugin stagemonitorPlugin : plugins) { final String pluginName = stagemonitorPlugin.getClass().getSimpleName(); if (disabledPlugins.contains(pluginName)) { logger.info("Not initializing disabled plugin {}", pluginName); healthCheckRegistry.register(pluginName, ImmediateResult.of(HealthCheck.Result.unhealthy("disabled via configuration"))); } else { notYetInitialized.add(stagemonitorPlugin); } } return notYetInitialized; }
/** * Register Dropwizard health checks. * * @param pool the pool to register health checks for * @param hikariConfig the pool configuration * @param registry the HealthCheckRegistry into which checks will be registered */ public static void registerHealthChecks(final HikariPool pool, final HikariConfig hikariConfig, final HealthCheckRegistry registry) { final Properties healthCheckProperties = hikariConfig.getHealthCheckProperties(); final MetricRegistry metricRegistry = (MetricRegistry) hikariConfig.getMetricRegistry(); final long checkTimeoutMs = Long.parseLong(healthCheckProperties.getProperty("connectivityCheckTimeoutMs", String.valueOf(hikariConfig.getConnectionTimeout()))); registry.register(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "ConnectivityCheck"), new ConnectivityHealthCheck(pool, checkTimeoutMs)); final long expected99thPercentile = Long.parseLong(healthCheckProperties.getProperty("expected99thPercentileMs", "0")); if (metricRegistry != null && expected99thPercentile > 0) { SortedMap<String,Timer> timers = metricRegistry.getTimers((name, metric) -> name.equals(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "Wait"))); if (!timers.isEmpty()) { final Timer timer = timers.entrySet().iterator().next().getValue(); registry.register(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "Connection99Percent"), new Connection99Percent(timer, expected99thPercentile)); } } }
"For more details take a look at the javadoc.", alreadyRegisteredVersion, currentVersion); healthCheckRegistry.register("Agent attachment", ImmediateResult.of(HealthCheck.Result.unhealthy(msg))); return false;
private static MaxwellMetrics.Registries getMetricsRegistries(MaxwellContext context) throws IOException { MaxwellConfig config = context.getConfig(); String reportingType = config.metricsReportingType; if (reportingType != null && reportingType.contains(reportingTypeHttp)) { config.healthCheckRegistry.register("MaxwellHealth", new MaxwellHealthCheck(context.getProducer())); return new MaxwellMetrics.Registries(config.metricRegistry, config.healthCheckRegistry); } else { return null; } }
private static boolean initInstrumentation() { healthCheckRegistry.register("Agent attachment", ImmediateResult.of(HealthCheck.Result.unhealthy("Unknown error"))); try { instrumentation = getInstrumentation(); healthCheckRegistry.register("Agent attachment", ImmediateResult.of(HealthCheck.Result.healthy())); ensureDispatcherIsAppendedToBootstrapClasspath(instrumentation); Dispatcher.getValues().putIfAbsent(IGNORED_CLASSLOADERS_KEY, Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>())); hashCodesOfClassLoadersToIgnore = Dispatcher.get(IGNORED_CLASSLOADERS_KEY); return true; } catch (Throwable e) { final String msg = "Failed to perform runtime attachment of the stagemonitor agent. Make sure that you run your " + "application with a JDK (not a JRE)." + "To make stagemonitor work with a JRE, you have to add the following command line argument to the " + "start of the JVM: -javaagent:/path/to/byte-buddy-agent-<version>.jar. " + "The version of the agent depends on the version of stagemonitor. " + "You can download the appropriate agent for the stagemonitor version you are using here: " + getByteBuddyAgentDownloadUrl(); healthCheckRegistry.register("Agent attachment", ImmediateResult.of(HealthCheck.Result.unhealthy(msg))); logger.warn(msg, e); return false; } }
private static void initializePlugin(final StagemonitorPlugin stagemonitorPlugin) { final String pluginName = stagemonitorPlugin.getClass().getSimpleName(); try { stagemonitorPlugin.initializePlugin(new StagemonitorPlugin.InitArguments(metric2Registry, getConfiguration(), measurementSession, healthCheckRegistry)); stagemonitorPlugin.initialized = true; for (Runnable onInitCallback : stagemonitorPlugin.onInitCallbacks) { onInitCallback.run(); } stagemonitorPlugin.registerWidgetTabPlugins(new StagemonitorPlugin.WidgetTabPluginsRegistry(pathsOfWidgetTabPlugins)); stagemonitorPlugin.registerWidgetMetricTabPlugins(new StagemonitorPlugin.WidgetMetricTabPluginsRegistry(pathsOfWidgetMetricTabPlugins)); healthCheckRegistry.register(pluginName, ImmediateResult.of(HealthCheck.Result.healthy("version " + stagemonitorPlugin.getVersion()))); } catch (final Exception e) { healthCheckRegistry.register(pluginName, ImmediateResult.of(HealthCheck.Result.unhealthy(e))); logger.warn("Error while initializing plugin " + pluginName + " (this exception is ignored)", e); } }
@Override public final void run(T configuration, Environment environment) throws Exception { final PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration); this.sessionFactory = requireNonNull(sessionFactoryFactory.build(this, environment, dbConfig, entities, name())); registerUnitOfWorkListenerIfAbsent(environment).registerSessionFactory(name(), sessionFactory); environment.healthChecks().register(name(), new SessionFactoryHealthCheck( environment.getHealthCheckExecutorService(), dbConfig.getValidationQueryTimeout().orElse(Duration.seconds(5)), sessionFactory, dbConfig.getValidationQuery())); }
@Override public void onFirstOperation(SpanWrapper spanWrapper) { final CacheManager cacheManager = CacheManager.getCacheManager(ehCacheNameOption.getValue()); final HealthCheck check; if (cacheManager != null) { monitorCaches(cacheManager); check = ImmediateResult.of(HealthCheck.Result.healthy("CacheManager found after first operation")); } else { check = ImmediateResult.of(HealthCheck.Result.unhealthy("CacheManager not found after first operation")); } healthCheckRegistry.register("EhCache CacheManager", check); }
@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }
/** * Creates a new {@link AdminEnvironment}. * * @param handler a servlet context handler * @param healthChecks a health check registry */ public AdminEnvironment(MutableServletContextHandler handler, HealthCheckRegistry healthChecks, MetricRegistry metricRegistry) { super(handler); this.healthChecks = healthChecks; this.healthChecks.register("deadlocks", new ThreadDeadlockHealthCheck()); this.tasks = new TaskServlet(metricRegistry); tasks.add(new GarbageCollectionTask()); tasks.add(new LogConfigurationTask()); addServlet("tasks", tasks).addMapping("/tasks/*"); handler.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStarting(LifeCycle event) { logTasks(); logHealthChecks(); } }); }
/** * Should only be used outside of this class by the internal unit tests */ @Deprecated public static void reset(MeasurementSession measurementSession) { started = false; disabled = false; if (configuration == null) { reloadPluginsAndConfiguration(); } if (measurementSession == null) { CorePlugin corePlugin = getPlugin(CorePlugin.class); measurementSession = new MeasurementSession(corePlugin.getApplicationName(), corePlugin.getHostName(), corePlugin.getInstanceName()); } onShutdownActions.add(AgentAttacher.performRuntimeAttachment()); startMonitoring(measurementSession); healthCheckRegistry.register("Startup", new HealthCheck() { @Override protected Result check() throws Exception { if (started) { return Result.healthy(); } else { return Result.unhealthy("stagemonitor is not started"); } } }); logStatus(); new ConfigurationLogger().logConfiguration(configuration); }
@Override public void initializePlugin(StagemonitorPlugin.InitArguments initArguments) { this.metricRegistry = initArguments.getMetricRegistry(); healthCheckRegistry = initArguments.getHealthCheckRegistry(); TracingPlugin tracingPlugin = initArguments.getPlugin(TracingPlugin.class); final CacheManager cacheManager = CacheManager.getCacheManager(ehCacheNameOption.getValue()); if (cacheManager == null) { tryAgainWhenFirstRequestComesIn(tracingPlugin); } else { monitorCaches(cacheManager); healthCheckRegistry.register("EhCache CacheManager", ImmediateResult.of(HealthCheck.Result.healthy())); } final CorePlugin corePlugin = initArguments.getPlugin(CorePlugin.class); corePlugin.getGrafanaClient().sendGrafanaDashboardAsync("grafana/ElasticsearchEhCache.json"); }
environment.healthChecks().register("graphhopper-storage", new GraphHopperStorageHealthCheck(graphHopperStorage));
environment.healthChecks().register(name, new JdbiHealthCheck( environment.getHealthCheckExecutorService(), configuration.getValidationQueryTimeout().orElseGet(() -> Duration.seconds(5)),
environment.healthChecks().register(name, new DBIHealthCheck( environment.getHealthCheckExecutorService(), configuration.getValidationQueryTimeout().orElseGet(() -> Duration.seconds(5)),
private void runRegularGraphHopper(CmdArgs configuration, Environment environment) { final GraphHopperManaged graphHopperManaged = new GraphHopperManaged(configuration, environment.getObjectMapper()); environment.lifecycle().manage(graphHopperManaged); environment.jersey().register(new AbstractBinder() { @Override protected void configure() { bind(configuration).to(CmdArgs.class); bind(graphHopperManaged).to(GraphHopperManaged.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopper.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopperAPI.class); bindFactory(HasElevation.class).to(Boolean.class).named("hasElevation"); bindFactory(LocationIndexFactory.class).to(LocationIndex.class); bindFactory(TranslationMapFactory.class).to(TranslationMap.class); bindFactory(EncodingManagerFactory.class).to(EncodingManager.class); bindFactory(GraphHopperStorageFactory.class).to(GraphHopperStorage.class); bindFactory(RasterHullBuilderFactory.class).to(DelaunayTriangulationIsolineBuilder.class); } }); if (configuration.getBool("web.change_graph.enabled", false)) { environment.jersey().register(ChangeGraphResource.class); } environment.jersey().register(NearestResource.class); environment.jersey().register(RouteResource.class); environment.jersey().register(IsochroneResource.class); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); environment.healthChecks().register("graphhopper", new GraphHopperHealthCheck(graphHopperManaged.getGraphHopper())); }
@Override public void run(HelloWorldConfiguration configuration, Environment environment) { final PersonDAO dao = new PersonDAO(hibernateBundle.getSessionFactory()); final Template template = configuration.buildTemplate(); environment.healthChecks().register("template", new TemplateHealthCheck(template)); environment.admin().addTask(new EchoTask()); environment.jersey().register(DateRequiredFeature.class); environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<User>() .setAuthenticator(new ExampleAuthenticator()) .setAuthorizer(new ExampleAuthorizer()) .setRealm("SUPER SECRET STUFF") .buildAuthFilter())); environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); environment.jersey().register(RolesAllowedDynamicFeature.class); environment.jersey().register(new HelloWorldResource(template)); environment.jersey().register(new ViewResource()); environment.jersey().register(new ProtectedResource()); environment.jersey().register(new PeopleResource(dao)); environment.jersey().register(new PersonResource(dao)); environment.jersey().register(new FilteredResource()); } }