@Test public void testStartNoArg() throws Exception { PollScheduler.getInstance().start(); assertTrue(PollScheduler.getInstance().isStarted()); PollScheduler.getInstance().stop(); }
public static void startPoller(){ scheduler.start(); final int heartbeatInterval = 1200; final File metricsDir; try { metricsDir = File.createTempFile("zuul-servo-metrics-", ""); metricsDir.delete(); metricsDir.mkdir(); } catch (IOException e) { throw new RuntimeException(e); } LOG.debug("created metrics dir " + metricsDir.getAbsolutePath()); MetricObserver transform = new CounterToRateMetricTransform( new FileMetricObserver("ZuulMetrics", metricsDir), heartbeatInterval, TimeUnit.SECONDS); PollRunnable task = new PollRunnable( new MonitorRegistryMetricPoller(), BasicMetricFilter.MATCH_ALL, transform); final int samplingInterval = 10; scheduler.addPoller(task, samplingInterval, TimeUnit.SECONDS); }
private static void schedule(MetricPoller poller, List<MetricObserver> observers) { final PollRunnable task = new PollRunnable(poller, BasicMetricFilter.MATCH_ALL, true, observers); PollScheduler.getInstance().addPoller(task, Config.getPollInterval(), TimeUnit.SECONDS); }
@Override protected void initializePlatform() { if (initalized) return; try { PollScheduler scheduler = PollScheduler.getInstance(); scheduler.start(); MetricObserver fileObserver = new FileMetricObserver("stats", new File(".")); MetricObserver transform = new CounterToRateMetricTransform(fileObserver, 2, TimeUnit.MINUTES); PollRunnable task = new PollRunnable(new MonitorRegistryMetricPoller(), BasicMetricFilter.MATCH_ALL, transform); scheduler.addPoller(task, 1, TimeUnit.MINUTES); } catch (Throwable e) { // dont do anything... just eat. logger.error("Epic Plugin was not intialized: ", e); } initalized = true; }
public void init() { PollScheduler scheduler = PollScheduler.getInstance(); if (!scheduler.isStarted()) { scheduler.start(); } if (isRollingFileEnabled()) { MetricObserver fileObserver = new FileOutputMetricObserver(fileOutput, convertor, formatter); MetricObserver fileTransform = new CounterToRateMetricTransform(fileObserver, metricPoll, TimeUnit.SECONDS); PollRunnable fileTask = new PollRunnable(new MonitorRegistryMetricPoller(), BasicMetricFilter.MATCH_ALL, fileTransform); scheduler.addPoller(fileTask, metricPoll, TimeUnit.SECONDS); } }
/** * Starts the polling that will publish metrics at regular intervals. This start() method should be called by * the main() method of the application. Calling this method more than once is allowed, but will have no effect if * the polling has already been started. * * @param graphiteConfig Tells the library how to talk to Graphite */ public void start(GraphiteConfig graphiteConfig) { synchronized (POLL_SCHEDULER) { POLL_SCHEDULER_START_COUNT.addAndGet(1); if(!POLL_SCHEDULER.isStarted()) { POLL_SCHEDULER.start(); final MetricPoller monitorRegistryMetricPoller = factory.createMonitorRegistryMetricPoller(); final List<MetricObserver> observers = Collections.singletonList(createGraphiteObserver(graphiteConfig)); final PollRunnable task = factory.createTask(monitorRegistryMetricPoller, observers); POLL_SCHEDULER.addPoller(task, graphiteConfig.pollintervalseconds(), SECONDS); } } }
private static void initMetricsPublishing() throws Exception { final List<MetricObserver> observers = new ArrayList<>(); if (Config.isFileObserverEnabled()) { observers.add(createFileObserver()); } if (Config.isAtlasObserverEnabled()) { observers.add(createAtlasObserver()); } if (Config.isGraphiteObserverEnabled()) { observers.add(createGraphiteObserver()); } PollScheduler.getInstance().start(); schedule(new MonitorRegistryMetricPoller(), observers); if (Config.isJvmPollerEnabled()) { schedule(new JvmMetricPoller(), observers); } }
/** * Call this method to start collecting the metrics (both Jvm and custom). */ @Override public void start() { final PollScheduler scheduler = PollScheduler.getInstance(); if (monitoringEnabled && !scheduler.isStarted()) { synchronized (scheduler) { if (!scheduler.isStarted()) { scheduler.start(); scheduleTasks(pollRunnables); registerCustomMonitors(); LOG.info("monitoring started."); } } } }
private static void initHttpServer() throws Exception { // Setup default endpoints final HttpServer server = HttpServer.create(); server.createContext("/echo", new EchoHandler()); // Hook to allow for graceful exit final Closeable c = () -> { PollScheduler.getInstance().stop(); server.stop(5); }; server.createContext("/exit", new ExitHandler(c)); // Bind and start server server.bind(new InetSocketAddress(Config.getPort()), 0); server.start(); }
/** * Start scheduling tasks with a default thread pool, sized based on the * number of available processors. */ public void start() { int numThreads = Runtime.getRuntime().availableProcessors(); ThreadFactory factory = ThreadFactories.withName("ServoPollScheduler-%d"); start(Executors.newScheduledThreadPool(numThreads, factory)); }
/** * Call this method to stop collecting all metrics. */ @Override public void stop() { final PollScheduler scheduler = PollScheduler.getInstance(); if (monitoringEnabled && scheduler.isStarted()) { synchronized (scheduler) { if (scheduler.isStarted()) { scheduler.stop(); unregisterCustomMonitors(); LOG.info("monitoring stopped."); } } } }
@Override public boolean isMonitoringStarted() { return PollScheduler.getInstance().isStarted(); }
@Test public void testGetInstance() throws Exception { PollScheduler p = PollScheduler.getInstance(); assertNotNull(p); }
/** * Stops the polling that publishes metrics; for maximum safety, call this method before calling System.exit(). */ public void stop() { // Log4j2 start-up calls start() twice for a particular appender, and therefore calls stop() twice, but (as it // turns out) calls start() twice before the first call to stop()! As a result we have to count the number of // times that start() was called and not actually stop until the last call. The <code><= 0</code> check in this // method allows the unit test to execute the <code>catch(IllegalStateException e)</code> by calling stop() // before ever calling start(). try { if(POLL_SCHEDULER_START_COUNT.decrementAndGet() <= 0) { POLL_SCHEDULER.stop(); } } catch(IllegalStateException e) { // The poller wasn't started; just ignore this error } }
PollScheduler.getInstance().start(); PollScheduler.getInstance().addPoller(registeryTask, 5, TimeUnit.SECONDS); PollScheduler.getInstance().addPoller(jvmTask, 5, TimeUnit.SECONDS);
private void scheduleTasks(final List<PollRunnable> tasks) { if (tasks != null) { for (final PollRunnable task : tasks) { PollScheduler.getInstance().addPoller(task, pollInterval, timeUnit); } } }
private static void doStop() { if (!initialized) { return; } PollScheduler.getInstance().stop(); }
/** * Start scheduling tasks with a default thread pool, sized based on the * number of available processors. */ public void start() { int numThreads = Runtime.getRuntime().availableProcessors(); ThreadFactory factory = ThreadFactories.withName("ServoPollScheduler-%d"); start(Executors.newScheduledThreadPool(numThreads, factory)); }
PollScheduler.getInstance().start(); PollScheduler.getInstance().addPoller(registeryTask, 5, TimeUnit.SECONDS); PollScheduler.getInstance().addPoller(jvmTask, 5, TimeUnit.SECONDS);
@Test public void testStart() throws Exception { ScheduledExecutorService s = Executors.newScheduledThreadPool(2); PollScheduler.getInstance().start(s); assertTrue(PollScheduler.getInstance().isStarted()); //PollScheduler.getInstance().addPoller( ,60, TimeUnit.SECONDS); PollScheduler.getInstance().stop(); }