Search in sources :

Example 1 with MonitorHandler

use of io.gravitee.gateway.services.monitoring.handler.MonitorHandler in project gravitee-gateway by gravitee-io.

the class MonitoringService method doStart.

@Override
protected void doStart() throws Exception {
    if (enabled) {
        super.doStart();
        LOGGER.info("Start gateway monitor");
        Event evt = prepareEvent();
        LOGGER.debug("Sending a {} event", evt.getType());
        heartbeatEvent = eventRepository.create(evt);
        executorService = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "gateway-monitor"));
        MonitorThread monitorThread = new MonitorThread(heartbeatEvent);
        this.applicationContext.getAutowireCapableBeanFactory().autowireBean(monitorThread);
        LOGGER.info("Monitoring scheduled with fixed delay {} {} ", delay, unit.name());
        ((ScheduledExecutorService) executorService).scheduleWithFixedDelay(monitorThread, 0, delay, unit);
        LOGGER.info("Associate a new HTTP handler on {}", PATH);
        // Create and associate handler
        MonitorHandler monitorHandler = new MonitorHandler();
        applicationContext.getAutowireCapableBeanFactory().autowireBean(monitorHandler);
        router.get(PATH).produces(MediaType.APPLICATION_JSON).handler(monitorHandler);
        LOGGER.info("Start gateway monitor : DONE");
    }
}
Also used : Plugin(io.gravitee.gateway.services.monitoring.event.Plugin) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) Router(io.vertx.ext.web.Router) Autowired(org.springframework.beans.factory.annotation.Autowired) MonitorHandler(io.gravitee.gateway.services.monitoring.handler.MonitorHandler) InstanceEventPayload(io.gravitee.gateway.services.monitoring.event.InstanceEventPayload) Value(org.springframework.beans.factory.annotation.Value) InetAddress(java.net.InetAddress) EventType(io.gravitee.repository.management.model.EventType) UUID(io.gravitee.common.utils.UUID) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) EventRepository(io.gravitee.repository.management.api.EventRepository) Logger(org.slf4j.Logger) Event(io.gravitee.repository.management.model.Event) Version(io.gravitee.common.util.Version) PluginRegistry(io.gravitee.plugin.core.api.PluginRegistry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractService(io.gravitee.common.service.AbstractService) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) MediaType(io.gravitee.common.http.MediaType) Node(io.gravitee.common.node.Node) GatewayConfiguration(io.gravitee.gateway.env.GatewayConfiguration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MonitorHandler(io.gravitee.gateway.services.monitoring.handler.MonitorHandler) Event(io.gravitee.repository.management.model.Event)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MediaType (io.gravitee.common.http.MediaType)1 Node (io.gravitee.common.node.Node)1 AbstractService (io.gravitee.common.service.AbstractService)1 Version (io.gravitee.common.util.Version)1 UUID (io.gravitee.common.utils.UUID)1 GatewayConfiguration (io.gravitee.gateway.env.GatewayConfiguration)1 InstanceEventPayload (io.gravitee.gateway.services.monitoring.event.InstanceEventPayload)1 Plugin (io.gravitee.gateway.services.monitoring.event.Plugin)1 MonitorHandler (io.gravitee.gateway.services.monitoring.handler.MonitorHandler)1 PluginRegistry (io.gravitee.plugin.core.api.PluginRegistry)1 EventRepository (io.gravitee.repository.management.api.EventRepository)1 Event (io.gravitee.repository.management.model.Event)1 EventType (io.gravitee.repository.management.model.EventType)1 Router (io.vertx.ext.web.Router)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 java.util (java.util)1 ExecutorService (java.util.concurrent.ExecutorService)1