/** * Gets the JMX services. * * @param config the Collectd's configuration * @return the list of JMX services */ private List<String> getJmxServices(CollectdConfiguration config) { List<String> services = new ArrayList<>(); for (Collector c : config.getCollectors()) { // The following code has been made that way to avoid a dependency with opennms-services // TODO Depends on opennms-services is not that bad, considering that some customers could have different implementations. if (c.getClassName().matches(".*(JBoss|JMXSecure|Jsr160|MX4J)Collector$")) { services.add(c.getService()); } } return services; }
/** * <p>visit</p> * * @param visitor a {@link org.opennms.netmgt.dao.jaxb.collector.CollectdConfigVisitor} object. */ public void visit(CollectdConfigVisitor visitor) { CollectdConfiguration collectdConfiguration = getCollectdConfiguration(); visitor.visitCollectdConfiguration(collectdConfiguration); for (Iterator<Collector> it = collectdConfiguration.getCollectors().iterator(); it.hasNext();) { Collector collector = it.next(); doVisit(collector, visitor); } visitor.completeCollectdConfiguration(collectdConfiguration); }
private void rebuildScheduler() { for (Collector collector : m_collectdConfigFactory.getCollectdConfig().getCollectors()) { String svcName = collector.getService(); configuredCollectors.add(svcName);
private void instantiateCollectors() { LOG.debug("instantiateCollectors: Loading collectors"); /* * Load up an instance of each collector from the config * so that the event processor will have them for * new incoming events to create collectable service objects. */ Collection<Collector> collectors = m_collectdConfigFactory.getCollectdConfig().getCollectors(); for (Collector collector : collectors) { String svcName = collector.getService(); try { LOG.debug("instantiateCollectors: Loading collector {}, classname {}", svcName, collector.getClassName()); final ServiceCollector sc = m_serviceCollectorRegistry.getCollectorByClassName(collector.getClassName()); if (sc == null) { throw new IllegalArgumentException(String.format("No collector found with class name '%s'. Available collectors include: %s", collector.getClassName(), m_serviceCollectorRegistry.getCollectorClassNames())); } sc.initialize(); setServiceCollector(svcName, sc); } catch (Throwable t) { LOG.warn("instantiateCollectors: Failed to load collector {} for service {}", collector.getClassName(), svcName, t); } } }
public CollectdConfiguration getCollectdConfigurationForPackages(List<String> collectionPackageNames) { if (collectionPackageNames == null || collectionPackageNames.size() < 1) return null; final Set<String> seenCollectors = new HashSet<>(); final CollectdConfiguration newConfig = new CollectdConfiguration(); newConfig.setThreads(getThreads()); // Add all requested polling packages to the config boolean foundPackage = false; for (String packageName : collectionPackageNames) { final Package pkg = getPackage(packageName); if (pkg != null) { newConfig.addPackage(pkg); foundPackage = true; for (final Service service : pkg.getServices()) { seenCollectors.add(service.getName()); } } } // If the list of polling packages doesn't match anything, then return null if (!foundPackage) return null; for (final Collector collector : getCollectors()) { if (seenCollectors.contains(collector.getService())) { newConfig.addCollector(collector); } } return newConfig; }
private void setupCollector(String svcName, ServiceCollector svcCollector) throws CollectionInitializationException { MockServiceCollector.setDelegate(svcCollector); // Tell the config to use the MockServiceCollector for the specified service Collector collector = new Collector(); collector.setService(svcName); collector.setClassName(MockServiceCollector.class.getName()); m_collectdConfigFactory = m_easyMockUtils.createMock(CollectdConfigFactory.class); m_collectdConfig = m_easyMockUtils.createMock(CollectdConfiguration.class); expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfig).anyTimes(); expect(m_collectdConfig.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes(); expect(m_collectdConfig.getThreads()).andReturn(1).anyTimes(); m_collectd.setCollectdConfigFactory(m_collectdConfigFactory); } }
m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class); EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes(); EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes(); EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(1).anyTimes();
m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class); EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes(); EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes(); EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(2).anyTimes();