Search in sources :

Example 11 with ConsoleReporter

use of com.codahale.metrics.ConsoleReporter in project newts by OpenNMS.

the class ImportRunner method execute.

public void execute(String... args) throws Exception {
    CmdLineParser parser = new CmdLineParser(this);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        // handling of wrong arguments
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        return;
    }
    // Setup the slf4j metrics reporter
    MetricRegistry metrics = new MetricRegistry();
    final long start = System.currentTimeMillis();
    metrics.register("elapsed-seconds", new Gauge<Double>() {

        @Override
        public Double getValue() {
            return (System.currentTimeMillis() - start) / 1000.0;
        }
    });
    final ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).outputTo(System.err).convertRatesTo(SECONDS).convertDurationsTo(MILLISECONDS).build();
    reporter.start(10, SECONDS);
    if (m_restUrl == null) {
        // we are using a direct importer so use a NewtsReporter for storing metrics
        NewtsReporter newtsReporter = NewtsReporter.forRegistry(metrics).name("importer").convertRatesTo(SECONDS).convertDurationsTo(MILLISECONDS).build(repository());
        newtsReporter.start(1, SECONDS);
    }
    LOG.debug("Scanning {} for GSOD data files...", m_source);
    // walk the files in the directory given
    Observable<Sample> samples = fileTreeWalker(m_source.toPath()).subscribeOn(Schedulers.io()).map(meter(metrics.meter("files"), Path.class)).map(reportFile()).mergeMap(lines()).filter(exclude("YEARMODA")).mergeMap(samples()).map(adjustTime()).map(meter(metrics.meter("samples"), Sample.class));
    Observable<List<Sample>> batches = samples.buffer(m_samplesPerBatch);
    Observable<Boolean> doImport = m_restUrl != null ? restPoster(batches, metrics) : directPoster(batches, metrics);
    System.err.println("doImport = " + doImport);
    // GO!!!
    final AtomicReference<Subscription> subscription = new AtomicReference<>();
    final AtomicBoolean failed = new AtomicBoolean(false);
    final CountDownLatch latch = new CountDownLatch(1);
    Subscription s = doImport.subscribe(new Observer<Boolean>() {

        @Override
        public void onCompleted() {
            System.err.println("Finished Importing Everything!");
            reporter.report();
            latch.countDown();
            System.exit(0);
        }

        @Override
        public void onError(Throwable e) {
            failed.set(true);
            System.err.println("Error importing!");
            e.printStackTrace();
            try {
                // latch.await();
                Subscription s = subscription.get();
                if (s != null)
                    s.unsubscribe();
            } catch (Exception ex) {
                System.err.println("Failed to close httpClient!");
                ex.printStackTrace();
            } finally {
            // dumpThreads();
            }
        }

        @Override
        public void onNext(Boolean t) {
            System.err.println("Received a boolen: " + t);
        }
    });
    subscription.set(s);
    if (failed.get()) {
        s.unsubscribe();
    }
    // latch.countDown();
    System.err.println("Return from Subscribe!");
    latch.await();
// dumpThreads();
}
Also used : Path(java.nio.file.Path) CmdLineParser(org.kohsuke.args4j.CmdLineParser) ConsoleReporter(com.codahale.metrics.ConsoleReporter) Sample(org.opennms.newts.api.Sample) MetricRegistry(com.codahale.metrics.MetricRegistry) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ParseException(java.text.ParseException) CmdLineException(org.kohsuke.args4j.CmdLineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) List(java.util.List) NewtsReporter(org.opennms.newts.reporter.metrics.NewtsReporter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscription(rx.Subscription) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 12 with ConsoleReporter

use of com.codahale.metrics.ConsoleReporter in project opennms by OpenNMS.

the class HeartbeatSinkPerfIT method longRun.

@Ignore
public void longRun() throws Exception {
    // Here we enable console logging of the metrics we gather
    // To see these, you'll want to turn down the logging
    // You can do this by setting the following system property
    // on the JVM when running the tests:
    // -Dorg.opennms.core.test.mockLogger.defaultLogLevel=WARN
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    try {
        reporter.start(15, TimeUnit.SECONDS);
        Thread.sleep(5 * 60 * 1000);
    } finally {
        reporter.stop();
    }
}
Also used : ConsoleReporter(com.codahale.metrics.ConsoleReporter) Ignore(org.junit.Ignore)

Example 13 with ConsoleReporter

use of com.codahale.metrics.ConsoleReporter in project sling by apache.

the class MetricWebConsolePlugin method print.

//~--------------------------------------------< InventoryPrinter >
@Override
public void print(PrintWriter printWriter, Format format, boolean isZip) {
    if (format == Format.TEXT) {
        MetricRegistry registry = getConsolidatedRegistry();
        ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).outputTo(new PrintStream(new WriterOutputStream(printWriter))).build();
        reporter.report();
        reporter.close();
    } else if (format == Format.JSON) {
        MetricRegistry registry = getConsolidatedRegistry();
        JSONReporter reporter = JSONReporter.forRegistry(registry).outputTo(new PrintStream(new WriterOutputStream(printWriter))).build();
        reporter.report();
        reporter.close();
    }
}
Also used : PrintStream(java.io.PrintStream) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 14 with ConsoleReporter

use of com.codahale.metrics.ConsoleReporter in project hono by eclipse.

the class MetricConfig method consoleMetricReporter.

/**
 * Gets a new instance for a console reporter.
 *
 * @param period The period to update the state on console in milliseconds.
 * @return The new console reporter instance.
 */
@Bean
@ConditionalOnProperty(prefix = "hono.metric.reporter.console", name = "active", havingValue = "true")
public ConsoleReporter consoleMetricReporter(@Value("${hono.metric.reporter.console.period:5000}") final Long period) {
    LOG.info("metrics - console reporter activated");
    final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build();
    consoleReporter.start(period, TimeUnit.MILLISECONDS);
    return consoleReporter;
}
Also used : ConsoleReporter(com.codahale.metrics.ConsoleReporter) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 15 with ConsoleReporter

use of com.codahale.metrics.ConsoleReporter in project opennms by OpenNMS.

the class StressCommand method execute.

@Override
public Void execute() throws Exception {
    // Apply sane lower bounds to all of the configurable options
    intervalInSeconds = Math.max(1, intervalInSeconds);
    numberOfNodes = Math.max(1, numberOfNodes);
    numberOfInterfacesPerNode = Math.max(1, numberOfInterfacesPerNode);
    numberOfGroupsPerInterface = Math.max(1, numberOfGroupsPerInterface);
    numberOfNumericAttributesPerGroup = Math.max(0, numberOfNumericAttributesPerGroup);
    numberOfStringAttributesPerGroup = Math.max(0, numberOfStringAttributesPerGroup);
    reportIntervalInSeconds = Math.max(1, reportIntervalInSeconds);
    numberOfGeneratorThreads = Math.max(1, numberOfGeneratorThreads);
    stringVariationFactor = Math.max(0, stringVariationFactor);
    if (stringVariationFactor > 0) {
        stringAttributesVaried = metrics.meter("string-attributes-varied");
    }
    // Display the effective settings and rates
    double attributesPerSecond = (1 / (double) intervalInSeconds) * numberOfGroupsPerInterface * numberOfInterfacesPerNode * numberOfNodes;
    System.out.printf("Generating collection sets every %d seconds\n", intervalInSeconds);
    System.out.printf("\t for %d nodes\n", numberOfNodes);
    System.out.printf("\t with %d interfaces\n", numberOfInterfacesPerNode);
    System.out.printf("\t with %d attribute groups\n", numberOfGroupsPerInterface);
    System.out.printf("\t with %d numeric attributes\n", numberOfNumericAttributesPerGroup);
    System.out.printf("\t with %d string attributes\n", numberOfStringAttributesPerGroup);
    System.out.printf("Across %d threads\n", numberOfGeneratorThreads);
    if (stringVariationFactor > 0) {
        System.out.printf("With string variation factor %d\n", stringVariationFactor);
    }
    System.out.printf("Which will yield an effective\n");
    System.out.printf("\t %.2f numeric attributes per second\n", numberOfNumericAttributesPerGroup * attributesPerSecond);
    System.out.printf("\t %.2f string attributes per second\n", numberOfStringAttributesPerGroup * attributesPerSecond);
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    // Setup the executor
    ThreadFactory threadFactoy = new ThreadFactoryBuilder().setNameFormat("Metrics Stress Tool Generator #%d").build();
    ExecutorService executor = Executors.newFixedThreadPool(numberOfGeneratorThreads, threadFactoy);
    // Setup auxiliary objects needed by the persister
    ServiceParameters params = new ServiceParameters(Collections.emptyMap());
    RrdRepository repository = new RrdRepository();
    repository.setStep(Math.max(intervalInSeconds, 1));
    repository.setHeartBeat(repository.getStep() * 2);
    if (rras != null && rras.size() > 0) {
        repository.setRraList(rras);
    } else {
        repository.setRraList(Lists.newArrayList(// Use the default list of RRAs we provide in our stock configuration files
        "RRA:AVERAGE:0.5:1:2016", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:288:366", "RRA:MAX:0.5:288:366", "RRA:MIN:0.5:288:366"));
    }
    repository.setRrdBaseDir(Paths.get(System.getProperty("opennms.home"), "share", "rrd", "snmp").toFile());
    // Calculate how we fast we should insert the collection sets
    int sleepTimeInMillisBetweenNodes = 0;
    int sleepTimeInSecondsBetweenIterations = 0;
    System.out.printf("Sleeping for\n");
    if (burst) {
        sleepTimeInSecondsBetweenIterations = intervalInSeconds;
        System.out.printf("\t %d seconds between batches\n", sleepTimeInSecondsBetweenIterations);
    } else {
        // We want to "stream" the collection sets
        sleepTimeInMillisBetweenNodes = Math.round((((float) intervalInSeconds * 1000) / numberOfNodes) * numberOfGeneratorThreads);
        System.out.printf("\t %d milliseconds between nodes\n", sleepTimeInMillisBetweenNodes);
    }
    // Start generating, and keep generating until we're interrupted
    try {
        reporter.start(reportIntervalInSeconds, TimeUnit.SECONDS);
        while (true) {
            final Context context = batchTimer.time();
            try {
                // Split the tasks up among the threads
                List<Future<Void>> futures = new ArrayList<>();
                for (int generatorThreadId = 0; generatorThreadId < numberOfGeneratorThreads; generatorThreadId++) {
                    futures.add(executor.submit(generateAndPersistCollectionSets(params, repository, generatorThreadId, sleepTimeInMillisBetweenNodes)));
                }
                // Wait for all the tasks to complete before starting others
                for (Future<Void> future : futures) {
                    future.get();
                }
            } catch (InterruptedException | ExecutionException e) {
                break;
            } finally {
                context.stop();
            }
            try {
                Thread.sleep(sleepTimeInSecondsBetweenIterations * 1000L);
            } catch (InterruptedException e) {
                break;
            }
        }
    } finally {
        reporter.stop();
        abort.set(true);
        executor.shutdownNow();
    }
    return null;
}
Also used : Context(com.codahale.metrics.Timer.Context) ThreadFactory(java.util.concurrent.ThreadFactory) ConsoleReporter(com.codahale.metrics.ConsoleReporter) ArrayList(java.util.ArrayList) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(java.util.concurrent.Future) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ConsoleReporter (com.codahale.metrics.ConsoleReporter)20 MetricRegistry (com.codahale.metrics.MetricRegistry)6 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)4 ExecutorService (java.util.concurrent.ExecutorService)4 ThreadFactory (java.util.concurrent.ThreadFactory)4 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Counter (com.codahale.metrics.Counter)2 Histogram (com.codahale.metrics.Histogram)2 Context (com.codahale.metrics.Timer.Context)2 PrintStream (java.io.PrintStream)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 Ignore (org.junit.Ignore)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 EchoRequest (org.opennms.core.rpc.echo.EchoRequest)2 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)2