com.codahale.metrics.ConsoleReporter Java Examples

The following examples show how to use com.codahale.metrics.ConsoleReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsoleReporterStarter.java    From fluo with Apache License 2.0 6 votes vote down vote up
@Override
public List<AutoCloseable> start(Params params) {
  SimpleConfiguration config =
      new FluoConfiguration(params.getConfiguration()).getReporterConfiguration("console");

  if (!config.getBoolean("enable", false)) {
    return Collections.emptyList();
  }

  TimeUnit rateUnit = TimeUnit.valueOf(config.getString("rateUnit", "seconds").toUpperCase());
  TimeUnit durationUnit =
      TimeUnit.valueOf(config.getString("durationUnit", "milliseconds").toUpperCase());
  PrintStream out = System.out;
  if (config.getString("target", "stdout").equals("stderr")) {
    out = System.err;
  }

  ConsoleReporter reporter = ConsoleReporter.forRegistry(params.getMetricRegistry())
      .convertDurationsTo(durationUnit).convertRatesTo(rateUnit).outputTo(out).build();
  reporter.start(config.getInt("frequency", 60), TimeUnit.SECONDS);

  log.info("Reporting metrics to console");

  return Collections.singletonList((AutoCloseable) reporter);
}
 
Example #2
Source File: SentryMetrics.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
public synchronized void initReporting(Reporting reporting) {
  if(!reportingInitialized) {
    switch(reporting) {
      case CONSOLE:
        final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(SentryMetricsServletContextListener.METRIC_REGISTRY)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
        consoleReporter.start(1, TimeUnit.SECONDS);
        break;
      case JMX:
        final JmxReporter jmxReporter = JmxReporter.forRegistry(SentryMetricsServletContextListener.METRIC_REGISTRY)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
        jmxReporter.start();
        break;
    }
  }
}
 
Example #3
Source File: RecordWriterPerformance.java    From heftydb with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer timer = metrics.timer("writes");

    TestFileHelper.createTestDirectory();
    KeyValueGenerator keyValueGenerator = new KeyValueGenerator();
    Value value = new Value(keyValueGenerator.testValue(100));

    DBState state = ConfigGenerator.perfState();
    TableWriter tableWriter = new TableWriter(state.config(), state.paths(), state.tables(), state.snapshots(),
            state.caches(), new Metrics(state.config()));

    for (int i = 0; i < RECORD_COUNT; i++) {
        value.data().rewind();
        Timer.Context watch = timer.time();
        tableWriter.write(ByteBuffers.fromString(i + ""), value.data(), false);
        watch.stop();
    }

    reporter.report();
    tableWriter.close();

    TestFileHelper.cleanUpTestFiles();
}
 
Example #4
Source File: BenchmarkServer.java    From sofa-jraft with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
    if (args.length < 3) {
        LOG.error("[initialServerList], [configPath] are needed.");
    }
    final String initialServerList = args[1];
    final String configPath = args[2];

    final RheaKVStoreOptions opts = Yaml.readConfig(configPath);
    opts.setInitialServerList(initialServerList);

    final Node node = new Node(opts);
    node.start();

    ConsoleReporter.forRegistry(KVMetrics.metricRegistry()) //
            .build() //
            .start(30, TimeUnit.SECONDS);

    Runtime.getRuntime().addShutdownHook(new Thread(node::stop));
    LOG.info("BenchmarkServer start OK, options: {}", opts);
}
 
Example #5
Source File: RecordBlockPerformance.java    From heftydb with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer timer = metrics.timer("reads");
    TupleGenerator generator = new TupleGenerator();
    List<Tuple> tuples = generator.testRecords(1, 64000, 20, 16, 100);

    TupleBlock.Builder blockBuilder = new TupleBlock.Builder();
    for (Tuple tuple : tuples) {
        blockBuilder.addRecord(tuple);
    }

    TupleBlock block = blockBuilder.build();

    Random random = new Random(System.nanoTime());
    int iterations = 10000000;

    for (int i = 0; i < iterations; i++) {
        Timer.Context watch = timer.time();
        block.get(tuples.get(random.nextInt(tuples.size())).key());
        watch.stop();
    }

    reporter.report();
}
 
Example #6
Source File: SiddhiStatisticsManager.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public void startReporting() {
    if (reporterName.equalsIgnoreCase("console")) {
        reporter = ConsoleReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .build();
        ((ConsoleReporter) reporter).start(interval, TimeUnit.SECONDS);
    } else if (reporterName.equalsIgnoreCase("jmx")) {
        reporter = JmxReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .build();
        ((JmxReporter) reporter).start();
    } else {
        throw new UnsupportedOperationException("Only 'ConsoleReporter' and 'JmxReporter' is supported, Reporter " +
                "type '" + reporter.getClass().getName() + "' is not supported");
    }
}
 
Example #7
Source File: BaseFreonGenerator.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Print out reports from the executed tests.
 */
public void printReport() {
  ScheduledReporter reporter = freonCommand.isInteractive()
      ? ConsoleReporter.forRegistry(metrics).build()
      : Slf4jReporter.forRegistry(metrics).build();
  reporter.report();

  List<String> messages = new LinkedList<>();
  messages.add("Total execution time (sec): " +
      Math.round((System.currentTimeMillis() - startTime) / 1000.0));
  messages.add("Failures: " + failureCounter.get());
  messages.add("Successful executions: " + successCounter.get());

  Consumer<String> print = freonCommand.isInteractive()
      ? System.out::println
      : LOG::info;
  messages.forEach(print);
}
 
Example #8
Source File: DiagnosticMode.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private void startLoggingMetrics(final File diagnosticFolder) {
    final File metricLog = new File(diagnosticFolder, FILE_NAME_METRIC_LOG);

    try {
        final PrintStream logStream = new PrintStream(metricLog, Charset.defaultCharset().name());
        final ConsoleReporter metricReporter = ConsoleReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .outputTo(logStream)
                .build();
        metricReporter.start(1, TimeUnit.SECONDS);

    } catch (final IOException e) {
        log.error("Not able to create metric.log, for {}", e.getCause());
    }
}
 
Example #9
Source File: Bireme.java    From bireme with Apache License 2.0 6 votes vote down vote up
/**
 * Start metrics reporter.
 *
 */
protected void startReporter() {
  switch (cxt.conf.reporter) {
    case "console":
      consoleReporter = ConsoleReporter.forRegistry(cxt.register)
                            .convertRatesTo(TimeUnit.SECONDS)
                            .convertDurationsTo(TimeUnit.MILLISECONDS)
                            .build();
      consoleReporter.start(cxt.conf.report_interval, TimeUnit.SECONDS);
      break;
    case "jmx":
      jmxReporter = JmxReporter.forRegistry(cxt.register).build();
      jmxReporter.start();
      break;
    default:
      break;
  }
}
 
Example #10
Source File: MemoryPerformance.java    From heftydb with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer timer = metrics.timer("allocations");

    Random random = new Random(System.nanoTime());
    int iterations = 1000000;
    MemoryPointer[] pointerArray = new MemoryPointer[iterations];

    for (int i = 0; i < pointerArray.length; i++) {
        Timer.Context watch = timer.time();
        pointerArray[i] = MemoryAllocator.allocate(random.nextInt(16384));
        watch.stop();
    }

    reporter.report();
}
 
Example #11
Source File: GetStarted.java    From metrics-zabbix with Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws IOException, InterruptedException {
	ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS)
			.convertDurationsTo(TimeUnit.MILLISECONDS).build();
	metrics.register("jvm.mem", new MemoryUsageGaugeSet());
	metrics.register("jvm.gc", new GarbageCollectorMetricSet());
	reporter.start(5, TimeUnit.SECONDS);

	String hostName = "192.168.66.29";
	ZabbixSender zabbixSender = new ZabbixSender("192.168.90.102", 10051);
	ZabbixReporter zabbixReporter = ZabbixReporter.forRegistry(metrics).hostName(hostName).prefix("test.")
			.build(zabbixSender);

	zabbixReporter.start(1, TimeUnit.SECONDS);

	TimeUnit.SECONDS.sleep(500);
}
 
Example #12
Source File: BlockCreationPerformance.java    From heftydb with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer timer = metrics.timer("blockCreationTime");

    KeyValueGenerator generator = new KeyValueGenerator();
    List<Key> keys = new ArrayList<Key>();

    for (int i = 0; i < 64000; i++) {
        keys.add(new Key(generator.testKey(32, 0), i));
    }

    Collections.sort(keys);

    IndexBlock.Builder blockBuilder = new IndexBlock.Builder();

    for (Key key : keys) {
        blockBuilder.addRecord(new IndexRecord(key, 0, 128));
    }

    IndexBlock block = blockBuilder.build();
    MemoryPointer blockPointer = block.memory();

    int iterations = 10000000;

    for (int i = 0; i < iterations; i++) {
        Timer.Context watch = timer.time();
        block = new IndexBlock(new SortedByteMap(blockPointer));
        watch.stop();
    }

    reporter.report();
}
 
Example #13
Source File: Metrics.java    From joinery with GNU General Public License v3.0 5 votes vote down vote up
public static void displayMetrics() {
    ConsoleReporter.forRegistry(registry)
            .build()
            .report();
    CsvReporter.forRegistry(registry)
            .build(new File("target/"))
            .report();
}
 
Example #14
Source File: MetricsAspectJMain.java    From tutorials with MIT License 5 votes vote down vote up
private static void startReport() {
    SharedMetricRegistries.add(ObjectRunner.REGISTRY_NAME, REGISTRY);

    ConsoleReporter.forRegistry(REGISTRY)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .outputTo(new PrintStream(System.out))
            .build()
            .start(3, TimeUnit.SECONDS);
}
 
Example #15
Source File: IndexBlockPerformance.java    From heftydb with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer timer = metrics.timer("reads");

    KeyValueGenerator generator = new KeyValueGenerator();
    List<Key> keys = new ArrayList<Key>();

    for (int i = 0; i < 64000; i++) {
        keys.add(new Key(generator.testKey(32, 0), i));
    }

    Collections.sort(keys);

    IndexBlock.Builder blockBuilder = new IndexBlock.Builder();
    for (Key key : keys) {
        blockBuilder.addRecord(new IndexRecord(key, 0, 128));
    }

    IndexBlock block = blockBuilder.build();

    Random random = new Random(System.nanoTime());
    int iterations = 10000000;

    for (int i = 0; i < iterations; i++) {
        Timer.Context watch = timer.time();
        block.get(keys.get(random.nextInt(keys.size())));
        watch.stop();
    }

    reporter.report();
}
 
Example #16
Source File: WritePerformance.java    From heftydb with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    TestFileHelper.createTestDirectory();
    TestFileHelper.cleanUpTestFiles();
    KeyValueGenerator keyValueGenerator = new KeyValueGenerator();
    ByteBuffer testValueBuffer = keyValueGenerator.testValue(100);

    Config config = new Config.Builder().directory(TestFileHelper.TEMP_PATH).memoryTableSize(16384000)
            .tableCacheSize(512000000).indexCacheSize(64000000).tableBlockSize(16384).compactionStrategy
                    (CompactionStrategies.SIZE_TIERED_COMPACTION_STRATEGY).indexBlockSize(32768).maxWriteRate
                    (Integer.MAX_VALUE).build();

    //Write
    DB db = HeftyDB.open(config);

    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer writeTimer = metrics.timer("writes");

    for (int i = 0; i < RECORD_COUNT; i++) {
        Timer.Context watch = writeTimer.time();
        db.put(ByteBuffers.fromString(i + ""), testValueBuffer.slice());
        watch.stop();
    }

    reporter.report();
    db.close();
}
 
Example #17
Source File: ScanPerformance.java    From heftydb with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer scanTimer = metrics.timer("scans");

    TestFileHelper.createTestDirectory();
    KeyValueGenerator keyValueGenerator = new KeyValueGenerator();
    Value value = new Value(keyValueGenerator.testValue(100));

    Config config = ConfigGenerator.defaultConfig();

    //Write
    final DB db = HeftyDB.open(config);

    for (int i = 0; i < RECORD_COUNT; i++) {
        value.data().rewind();
        db.put(ByteBuffers.fromString(i + ""), value.data());
    }

    //Scan
    Iterator<Record> iterator = db.ascendingIterator(Snapshot.MAX);

    while (iterator.hasNext()) {
        Timer.Context watch = scanTimer.time();
        iterator.next();
        watch.stop();
    }

    db.close();

    reporter.report();

    TestFileHelper.cleanUpTestFiles();
}
 
Example #18
Source File: ReadPerformance.java    From heftydb with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Random random = new Random(System.nanoTime());

    Config config = new Config.Builder().directory(TestFileHelper.TEMP_PATH).compactionStrategy
            (CompactionStrategies.SIZE_TIERED_COMPACTION_STRATEGY).tableCacheSize(512000000).indexCacheSize
            (64000000).maxWriteRate(Integer.MAX_VALUE).build();

    MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = PerformanceHelper.consoleReporter(metrics);
    Timer readTimer = metrics.register("reads", new Timer(new ExponentiallyDecayingReservoir()));

    DB db = HeftyDB.open(config);

    db.compact().get();

    //Read
    for (int i = 0; i < RECORD_COUNT * 10; i++) {
        String key = random.nextInt(RECORD_COUNT) + "";
        Timer.Context watch = readTimer.time();
        db.get(ByteBuffers.fromString(key));
        watch.stop();
    }

    reporter.report();
    db.logMetrics();
    db.close();

    System.exit(0);
}
 
Example #19
Source File: Dispatcher.java    From newts with Apache License 2.0 5 votes vote down vote up
Dispatcher(Config config) {
    checkNotNull(config, "config argument");
    m_threads = new Worker[config.getThreads()];
    m_reporter = ConsoleReporter.forRegistry(m_metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
    m_reporter.start(30, TimeUnit.SECONDS);
}
 
Example #20
Source File: StreamingMetrics.java    From kylin with Apache License 2.0 5 votes vote down vote up
public void start() {
    switch (METRICS_OPTION) {
    case "":
        logger.info("Skip streaming metricRegistry because it is empty.");
        break;
    // for test purpose
    case "console":
        logger.info("Use console to collect streaming metricRegistry.");
        ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
        consoleReporter.start(STREAM_METRICS_INTERVAL, TimeUnit.SECONDS);
        break;
    case "csv":
        File metricsFolder = new File("stream_metrics_csv");
        if (!metricsFolder.exists()) {
            boolean res = metricsFolder.mkdirs();
            if (!res) {
                logger.error("Cannot create dir for stream_metrics_csv");
                break;
            }
        }
        logger.info("Collect streaming metricRegistry in csv format.");
        CsvReporter scvReporter = CsvReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build(metricsFolder);
        scvReporter.start(STREAM_METRICS_INTERVAL, TimeUnit.SECONDS);
        break;
    case "jmx":
        final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
        jmxReporter.start();
        break;
    default:
        logger.info("Skip metricRegistry because the option {} is not identified.", METRICS_OPTION);
    }
}
 
Example #21
Source File: MeterTest.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Autowired
void awareMetricRegistry(MetricRegistry metricRegistry) {
    ConsoleReporter
      .forRegistry(metricRegistry)
      .build()
      .start(10, TimeUnit.SECONDS);
}
 
Example #22
Source File: MetricsManager.java    From ache with Apache License 2.0 5 votes vote down vote up
public MetricsManager(MetricRegistry metricsRegistry, boolean startConsoleReporter,
                      String directoryPath) {
    if (directoryPath != null) {
        this.metrics = loadMetrics(metricsRegistry, directoryPath);
    } else {
        this.metrics = metricsRegistry;
    }
    this.storageDirectory = directoryPath;
    if (startConsoleReporter) {
        reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build();
        reporter.start(10, TimeUnit.SECONDS);
    }
}
 
Example #23
Source File: CodahaleMetricsAssembler.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public CodahaleMetricsAssembler withConsoleReporter( PrintStream out, long period, TimeUnit timeunit )
{
    declaration.reportersFactories.add( metricRegistry -> {
        ConsoleReporter reporter = ConsoleReporter.forRegistry( metricRegistry ).outputTo( out ).build();
        reporter.start( period, timeunit );
        return reporter;
    });
    return this;
}
 
Example #24
Source File: MemoryUsageGaugeSetTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Test
public void testJVMMetrics() throws InterruptedException {
    LOG.info("Starting testJVMMetrics");
    final MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build();
    metrics.registerAll(new MemoryUsageGaugeSet());
    metrics.register("sample", (Gauge<Double>) () -> 0.1234);
    reporter.start(1, TimeUnit.SECONDS);
    reporter.close();
}
 
Example #25
Source File: StreamWindowBenchmarkTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Before
    public void setUp() {
        final MetricRegistry metrics = new MetricRegistry();
        metrics.registerAll(new MemoryUsageGaugeSet());
        metrics.registerAll(new GarbageCollectorMetricSet());
        metricReporter = ConsoleReporter.forRegistry(metrics)
            .filter((name, metric) -> name.matches("(.*heap|total).(usage|used)"))
//                .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
        metricReporter.start(60, TimeUnit.SECONDS);
        performanceReport = new TreeMap<>();
    }
 
Example #26
Source File: SendToLocalInfluxDB.java    From dropwizard-metrics-influxdb with Apache License 2.0 5 votes vote down vote up
private static ConsoleReporter startConsoleReporter(MetricRegistry registry) throws Exception {
    final ConsoleReporter reporter = ConsoleReporter
        .forRegistry(registry)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build();
    reporter.start(1, TimeUnit.MINUTES);
    return reporter;
}
 
Example #27
Source File: DropWizardMetricRegistry.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private ConsoleReporter getConsoleReporter() {
    if (consoleReporter == null) {
        consoleReporter = ConsoleReporter.forRegistry(getMetricRegistry())
            .build();
    }
    return consoleReporter;
}
 
Example #28
Source File: MetricsConsoleReporterModule.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configure() {
    bind(ConsoleReporter.class).toProvider(ConsoleReporterProvider.class);
    
    addConfigBeans();
    addInitializer(MetricsConsoleReporterService.class);
}
 
Example #29
Source File: MetricsSetup.java    From quarks with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the metric {@code ConsoleReporter} polling every second.
 */
public MetricsSetup startConsoleReporter() {
    ConsoleReporter reporter = ConsoleReporter.forRegistry(registry()).convertRatesTo(ratesUnit)
            .convertDurationsTo(durationsUnit).build();
    reporter.start(1, TimeUnit.SECONDS);
    return this;
}
 
Example #30
Source File: ConsoleReporterProvider.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ConsoleReporter get() {
    return ConsoleReporter.forRegistry(metricRegistry)
            .formattedFor(configuration.getLocale())
            .formattedFor(configuration.getTimeZone())
            .outputTo(configuration.getOutputStream())
            .convertDurationsTo(configuration.getUnitDurations())
            .convertRatesTo(configuration.getUnitRates())
            .filter(new RegexMetricFilter(configuration.getIncludeMetrics()))
            .build();
}