@BeforeClass public static void init() { registry = new DefaultRegistry(); Spectator.globalRegistry().add(registry); }
@Inject StaticManager(Registry registry) { this.registry = registry; Spectator.globalRegistry().add(registry); }
@Inject StaticManager(Registry registry) { this.registry = registry; Spectator.globalRegistry().add(registry); }
public RegistryInitializer(Registry registry, boolean enableJmxLogging) { this.registry = registry; Spectator.globalRegistry().add(registry); if (enableJmxLogging) { Jmx.registerStandardMXBeans(registry); } gcLogger = new GcLogger(); gcLogger.start(null); }
/** Entry point for the agent. */ public static void premain(String arg, Instrumentation instrumentation) throws Exception { // Setup logging Config config = loadConfig(arg); LOGGER.debug("loaded configuration: {}", config.root().render()); createDependencyProperties(config); // Setup Registry AtlasRegistry registry = new AtlasRegistry(Clock.SYSTEM, new AgentAtlasConfig(config)); // Add to global registry for http stats and GC logger Spectator.globalRegistry().add(registry); // Enable GC logger GcLogger gcLogger = new GcLogger(); if (config.getBoolean("collection.gc")) { gcLogger.start(null); } // Enable JVM data collection if (config.getBoolean("collection.jvm")) { Jmx.registerStandardMXBeans(registry); } // Enable JMX query collection if (config.getBoolean("collection.jmx")) { for (Config cfg : config.getConfigList("jmx.mappings")) { Jmx.registerMappingsFromConfig(registry, cfg); } } // Start collection for the registry registry.start(); // Shutdown registry Runtime.getRuntime().addShutdownHook(new Thread(registry::stop, "spectator-agent-shutdown")); }
@Test public void properties() { Spectator.globalRegistry().add(registry); Properties props = new Properties(); props.setProperty("log4j.rootLogger", "ALL, A1"); props.setProperty("log4j.appender.A1", "com.netflix.spectator.log4j.SpectatorAppender"); PropertyConfigurator.configure(props); Counter c = registry.counter("log4j.numStackTraces", "loglevel", "5_DEBUG", "exception", "IllegalArgumentException", "file", "SpectatorAppenderTest.java"); Assertions.assertEquals(0, c.count()); Exception e = new IllegalArgumentException("foo"); e.fillInStackTrace(); Logger.getLogger(getClass()).debug("foo", e); Assertions.assertEquals(1, c.count()); } }
/** * Create a new instance. Spark looks for a constructor with all three parameters, so the * {@code SecurityManager} needs to be in the signature even though it isn't used. */ @SuppressWarnings("PMD.UnusedFormalParameter") public SparkSink( Properties properties, MetricRegistry registry, org.apache.spark.SecurityManager manager) throws MalformedURLException { final Config config = loadConfig(); sidecarRegistry = new SidecarRegistry(); reporter = SpectatorReporter.forRegistry(registry) .withSpectatorRegistry(sidecarRegistry) .withNameFunction(SparkNameFunction.fromConfig(config, sidecarRegistry)) .withValueFunction(SparkValueFunction.fromConfig(config)) .withGaugeCounters(Pattern.compile(config.getString("spectator.spark.gauge-counters"))) .build(); pollPeriod = getPeriod(properties); pollUnit = getUnit(properties); url = URI.create(properties.getProperty("url", DEFAULT_URL)).toURL(); // If there is a need to collect application metrics from jobs running on Spark, then // this should be enabled. The apps can report to the global registry and it will get // picked up by the Spark integration. if (shouldAddToGlobal(properties)) { Spectator.globalRegistry().add(sidecarRegistry); } }
public void globalIterator(Function<Registry, Meter> createMeter) { Registry dflt = new ServoRegistry(); CompositeRegistry global = Spectator.globalRegistry(); global.removeAll(); global.add(dflt); boolean found = false; Id expected = createMeter.apply(dflt).id(); for (Meter m : global) { found |= m.id().equals(expected); } Assertions.assertTrue(found, "id for sub-registry could not be found in global iterator"); }
private Registry newRegistry(int n, boolean warnings) { CompositeRegistry registry = new CompositeRegistry(clock); for (int i = 0; i < n; ++i) { registry.add(new DefaultRegistry(clock, new TestRegistryConfig(warnings, 10000))); } return registry; }
@Test public void globalIteratorWithDifferences() { Registry r1 = new DefaultRegistry(); Registry r2 = new DefaultRegistry(); CompositeRegistry global = Spectator.globalRegistry(); global.removeAll(); global.add(r1); global.add(r2); boolean found = false; Counter counter = r2.counter("testCounter"); for (Meter m : global) { found |= m.id().equals(counter.id()); } Assertions.assertTrue(found, "id for sub-registry could not be found in global iterator"); } }
@Test public void globalIterator() { Registry dflt = new DefaultRegistry(); CompositeRegistry global = Spectator.globalRegistry(); global.removeAll(); global.add(dflt); boolean found = false; Counter counter = dflt.counter("testCounter"); for (Meter m : global) { found |= m.id().equals(counter.id()); } Assertions.assertTrue(found, "id for sub-registry could not be found in global iterator"); }
@BeforeEach public void before() { registry = new DefaultRegistry(); client = HttpClient.create(new IpcLogger(registry)); Spectator.globalRegistry().removeAll(); Spectator.globalRegistry().add(registry); }
@BeforeEach public void before() { registry = new DefaultRegistry(); client = HttpClient.create(new IpcLogger(registry)); Spectator.globalRegistry().removeAll(); Spectator.globalRegistry().add(registry); }
@Test public void resurrectExpiredUsingCompositeCachedRef() { ManualClock clock = new ManualClock(); ExpiringRegistry registry = new ExpiringRegistry(clock); CompositeRegistry cr = Spectator.globalRegistry(); cr.removeAll(); cr.add(registry); Counter c = cr.counter("test"); c.increment(); clock.setWallTime(60000 * 30); registry.removeExpiredMeters(); Assertions.assertEquals(0, registry.counters().count()); c.increment(); Assertions.assertEquals(1, registry.counters().count()); }
@Test public void resurrectExpiredUsingComposite() { ManualClock clock = new ManualClock(); ExpiringRegistry registry = new ExpiringRegistry(clock); CompositeRegistry cr = Spectator.globalRegistry(); cr.removeAll(); cr.add(registry); cr.counter("test").increment(); clock.setWallTime(60000 * 30); registry.removeExpiredMeters(); Assertions.assertEquals(0, registry.counters().count()); cr.counter("test").increment(); Assertions.assertEquals(1, registry.counters().count()); }
@Test public void testAddGauges() { CompositeRegistry r = new CompositeRegistry(clock); Id id = r.createId("id1"); DefaultCounter c1 = new DefaultCounter(clock, id); c1.increment(); Registry r1 = new DefaultRegistry(clock); r.add(r1); for (Meter meter : r1) { for (Measurement m : meter.measure()) { Assertions.assertEquals(id, m.id()); } } }
@Test public void testHasExpired() { CompositeRegistry r = new CompositeRegistry(clock); Counter c1 = r.counter("id1"); Assertions.assertFalse(c1.hasExpired()); Registry r1 = new DefaultRegistry(clock); r.add(r1); // depends on registry type, some will be expired until first increment Assertions.assertFalse(c1.hasExpired()); c1.increment(); Assertions.assertFalse(c1.hasExpired()); }
@Test public void testAddAndRemove() { CompositeRegistry r = new CompositeRegistry(clock); Counter c1 = r.counter("id1"); c1.increment(); Assertions.assertEquals(0, c1.count()); Registry r1 = new DefaultRegistry(clock); r.add(r1); c1.increment(); Assertions.assertEquals(1, c1.count()); Registry r2 = new DefaultRegistry(clock); r.add(r2); c1.increment(); Assertions.assertEquals(2, r1.counter("id1").count()); Assertions.assertEquals(1, r2.counter("id1").count()); r.remove(r1); c1.increment(5); Assertions.assertEquals(2, r1.counter("id1").count()); Assertions.assertEquals(6, r2.counter("id1").count()); }