Search in sources :

Example 1 with SampleRepository

use of org.opennms.newts.api.SampleRepository in project newts by OpenNMS.

the class ImportRunner method directPoster.

private Observable<Boolean> directPoster(Observable<List<Sample>> samples, MetricRegistry metrics) {
    final SampleRepository repository = repository();
    final Timer timer = metrics.timer("writes");
    final Meter completions = metrics.meter("samples-completed");
    Func1<List<Sample>, Boolean> insert = new Func1<List<Sample>, Boolean>() {

        @Override
        public Boolean call(List<Sample> s) {
            int sz = s.size();
            try (Context timerCtx = timer.time()) {
                repository.insert(s);
                return true;
            } finally {
                completions.mark(sz);
            }
        }
    };
    return (m_threadCount == 1 ? samples.map(insert) : parMap(samples, metrics, insert)).all(Functions.<Boolean>identity());
}
Also used : SampleRepository(org.opennms.newts.api.SampleRepository) Context(com.codahale.metrics.Timer.Context) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) Sample(org.opennms.newts.api.Sample) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Func1(rx.functions.Func1)

Example 2 with SampleRepository

use of org.opennms.newts.api.SampleRepository in project newts by OpenNMS.

the class NewtsService method run.

@Override
public void run(final NewtsConfig config, Environment environment) throws Exception {
    // Filters
    configureCors(environment);
    configureUIRedirect(environment);
    configureAuthentication(environment, config);
    final Injector injector = Guice.createInjector(new NewtsGuiceModule(), new CassandraGuiceModule(config), new GraphiteGuiceModule(config));
    MetricRegistry metricRegistry = injector.getInstance(MetricRegistry.class);
    // Create/start a JMX reporter for our MetricRegistry
    final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain("newts").build();
    // Create (and start if so configured), a Graphite line-protocol listener
    final GraphiteListenerThread listener = new GraphiteListenerThread(injector.getInstance(GraphiteListener.class));
    environment.lifecycle().manage(new Managed() {

        @Override
        public void stop() throws Exception {
            reporter.stop();
        }

        @Override
        public void start() throws Exception {
            reporter.start();
            if (config.getGraphiteConfig().isEnabled()) {
                listener.start();
            }
        }
    });
    SampleRepository repository = injector.getInstance(SampleRepository.class);
    Indexer indexer = injector.getInstance(Indexer.class);
    // Rest resources
    environment.jersey().register(new MeasurementsResource(repository, config.getReports()));
    environment.jersey().register(new SamplesResource(repository, indexer));
    // Add search resource only if search is enabled
    if (config.getSearchConfig().isEnabled()) {
        environment.jersey().register(new SearchResource(injector.getInstance(Searcher.class)));
    }
    // Health checks
    environment.healthChecks().register("repository", new RepositoryHealthCheck(repository));
    // Mapped exceptions
    environment.jersey().register(IllegalArgumentExceptionMapper.class);
}
Also used : SampleRepository(org.opennms.newts.api.SampleRepository) MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.JmxReporter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Indexer(org.opennms.newts.api.search.Indexer) Injector(com.google.inject.Injector) GraphiteListener(org.opennms.newts.graphite.GraphiteListener) Managed(io.dropwizard.lifecycle.Managed)

Example 3 with SampleRepository

use of org.opennms.newts.api.SampleRepository in project newts by OpenNMS.

the class ImportRunner method repository.

private SampleRepository repository() {
    if (m_repository == null) {
        Injector injector = Guice.createInjector(new Config());
        m_repository = injector.getInstance(SampleRepository.class);
    }
    return m_repository;
}
Also used : SampleRepository(org.opennms.newts.api.SampleRepository) Injector(com.google.inject.Injector)

Aggregations

SampleRepository (org.opennms.newts.api.SampleRepository)3 Injector (com.google.inject.Injector)2 JmxReporter (com.codahale.metrics.JmxReporter)1 Meter (com.codahale.metrics.Meter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 Context (com.codahale.metrics.Timer.Context)1 Managed (io.dropwizard.lifecycle.Managed)1 IOException (java.io.IOException)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ServletException (javax.servlet.ServletException)1 Sample (org.opennms.newts.api.Sample)1 Indexer (org.opennms.newts.api.search.Indexer)1 GraphiteListener (org.opennms.newts.graphite.GraphiteListener)1 Func1 (rx.functions.Func1)1