/** * 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; } }
public static void main(String... args) { MetricRegistry metricRegistry = new MetricRegistry(); final ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(); GitHub github = Feign.builder().invocationHandlerFactory( new FeignOutboundMetricsDecorator(new InvocationHandlerFactory.Default(), metricRegistry)) .decoder(new GsonDecoder()).target(GitHub.class, "https://api.github.com"); // Fetch and print a list of the contributors to this library. List<Contributor> contributors = github.contributors("mwiede", "metrics-feign"); for (Contributor contributor : contributors) { System.out.println(contributor.login + " (" + contributor.contributions + ")"); } reporter.report(); }
private void run(PrintStream printStream) { long sleepPeriodMillis = config.getMetricsOutputPeriodSeconds() * 1000; ConsoleReporter consoleReporter = ConsoleReporter .forRegistry(metricRegistry) .outputTo(printStream) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); while (true) { try { Thread.sleep(sleepPeriodMillis); consoleReporter.report(); } catch (InterruptedException ignored) { interrupt(); LOGGER.trace("interrupted"); break; } } }
/** * @param uri Uri where one instance of Grakn Engine is running * @param keyspace The {@link Keyspace} where the data should be persisted */ public Migrator(SimpleURI uri, Keyspace keyspace, int retries, boolean failFast, int maxDelayMs, int maxLines) { this.uri = uri; this.keyspace = keyspace; this.retries = retries; this.failFast = failFast; this.maxDelayMs = maxDelayMs; this.maxLines = maxLines; this.metricRegistry = new MetricRegistry(); this.totalMeter = metricRegistry.meter(name(this.getClass(), "total")); this.successMeter = metricRegistry.meter(name(this.getClass(), "success")); this.parseTemplate = metricRegistry.timer(name(this.getClass(), "parse", "template")); this.reporter = ConsoleReporter.forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(MILLISECONDS) .build(); }
public static void addTimerForPdxTypeMetrics(final ClientCache clientCache) { Region temp = clientCache.getRegion("PdxTypes"); if (temp == null) { temp = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("PdxTypes"); } final Region pdxRegions = temp; metricRegistry.register(MetricRegistry.name("PdxTypes", "count"), (Gauge<Integer>) () -> pdxRegions.keySetOnServer().size()); ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.MINUTES); }
public static void main(String[] args) throws InterruptedException { MemoryConsumer consumer = new MemoryConsumer(); GcMonitor gcMonitor = GcMonitor.builder() .addRollingWindow("15min", Duration.ofMinutes(15)) .build(); gcMonitor.start(); MetricRegistry registry = new MetricRegistry(); registry.registerAll(DropwizardAdapter.toMetricSet("jvm-gc-monitor", gcMonitor)); ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(registry).build(); consoleReporter.start(10, TimeUnit.SECONDS); try { while (true) { consumer.consume(ThreadLocalRandom.current().nextInt(10) + 1, 1); consumer.consume(ThreadLocalRandom.current().nextInt(20) + 100, 1); TimeUnit.SECONDS.sleep(5); } } finally { consumer.close(); gcMonitor.stop(); } }
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); }
@Override public void run(ExampleConfiguration configuration, Environment environment) throws Exception { if(configuration.metricsEnabled()) { final Graphite graphite = new Graphite(new InetSocketAddress("graphite.example.com", 2003)); final GraphiteReporter reporter = GraphiteReporter.forRegistry(environment.metrics()) .prefixedWith("prefix") .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .build(graphite); reporter.start(5, TimeUnit.SECONDS); final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(environment.metrics()).build(); consoleReporter.start(5, TimeUnit.SECONDS); } final ExampleResource exampleResource = new ExampleResource(environment.metrics()); environment.jersey().register(exampleResource); }
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"); } }
@Override public void configureReporters(MetricRegistry metricRegistry) { ConsoleReporter .forRegistry(metricRegistry) .build() .start(1, TimeUnit.MINUTES); // final Graphite graphite = new Graphite(new InetSocketAddress("graphite.example.com", 2003)); // final GraphiteReporter reporter = GraphiteReporter.forRegistry(registry) // .prefixedWith("web1.example.com") // .convertRatesTo(TimeUnit.SECONDS) // .convertDurationsTo(TimeUnit.MILLISECONDS) // .filter(MetricFilter.ALL) // .build(graphite); // reporter.start(1, TimeUnit.MINUTES); }
@Test @Ignore("ad-hoc") public void testRegister() throws Exception { // reporterAgent.allowedBeans= new ImmutableMap.Builder<String, String>().put("java.lang:type=Memory.HeapMemoryUsage","sssswww").build(); String file = this.getClass().getResource("/test2.json").getFile(); reporterAgent.readConfig(file); reporterAgent.initLogger(); reporterAgent.registerPlatformBeans(); reporterAgent.addBeanNotificationListener(); ConsoleReporter reporter= ConsoleReporter.forRegistry(reporterAgent.metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.SECONDS); while(true) { // eat some memory String s = ""; for (int i = 0; i < 100000; i++) { s+="asdasdasd"; } } }
@Test public void register() throws Exception { new MockUnit(MetricRegistry.class, Metric.class, Reporter.class, ConsoleReporter.class) .expect(unit -> { MetricRegistry registry = unit.get(MetricRegistry.class); expect(registry.register("m", unit.get(Metric.class))) .andReturn(unit.get(Metric.class)); }) .expect(unit -> { unit.get(ConsoleReporter.class).close(); }) .run(unit -> { Map<String, Metric> metrics = ImmutableMap.of("m", unit.get(Metric.class)); Set<Reporter> reporters = ImmutableSet.of(unit.get(Reporter.class), unit.get(ConsoleReporter.class)); MetricRegistryInitializer mri = new MetricRegistryInitializer( unit.get(MetricRegistry.class), metrics, reporters); mri.close(); }); }
@Test public void closeWithError() throws Exception { new MockUnit(MetricRegistry.class, Metric.class, Reporter.class, ConsoleReporter.class) .expect(unit -> { MetricRegistry registry = unit.get(MetricRegistry.class); expect(registry.register("m", unit.get(Metric.class))) .andReturn(unit.get(Metric.class)); }) .expect(unit -> { unit.get(ConsoleReporter.class).close(); expectLastCall().andThrow(new IllegalStateException("intentional err")); }) .run(unit -> { Map<String, Metric> metrics = ImmutableMap.of("m", unit.get(Metric.class)); Set<Reporter> reporters = ImmutableSet.of(unit.get(Reporter.class), unit.get(ConsoleReporter.class)); MetricRegistryInitializer mri = new MetricRegistryInitializer( unit.get(MetricRegistry.class), metrics, reporters); mri.close(); }); }
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(); }
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(); }
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(); }
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; } } }
@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); }
@Before public void init() { MetricRegistry metricRegistry = new MetricRegistry(); this.logReporter = ConsoleReporter .forRegistry(metricRegistry) .build(); logReporter.start(1, TimeUnit.MINUTES); timer = metricRegistry.timer("connection"); }
public AbstractBulkInsertBenchmark(Configuration cfg, Database database, DocumentCollection collection) throws DocumentClientException { this.cfg = cfg; this.database = database; this.collection = collection; this.reporter = ConsoleReporter.forRegistry(metricsRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); this.logger = LoggerFactory.getLogger(this.getClass()); }
protected void startReport() { ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.SECONDS); }
@Override public void report(MetricRegistry metricRegistry) { final ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.MINUTES); }
/** * Add metrics reporters based on the configuration. */ private void addMetricsReporters() { if (getB("reporter.es", false)) { try { logger.info("OneOps metrics elastic search reporting is enabled!"); esReporter = ElasticsearchReporter.forRegistry(ooMetricsRegistry).build(getSearchHost()); esReporter.start(getI("reporter.timeout", 60), TimeUnit.SECONDS); } catch (IOException e) { logger.error("Can't start elastic search reporting.", e); } } else { logger.warn("OneOps metrics elastic search reporting is disabled!"); } if (getB("reporter.jmx", true)) { logger.info("OneOps metrics JMX reporting is enabled!"); jmxReporter = JmxReporter.forRegistry(ooMetricsRegistry).build(); jmxReporter.start(); } else { logger.warn("OneOps metrics JMX reporting is disabled!"); } if (getB("reporter.console", false)) { consoleReporter = ConsoleReporter.forRegistry(ooMetricsRegistry).build(); consoleReporter.start(getI("reporter.timeout", 30), TimeUnit.SECONDS); } else { logger.warn("OneOps metrics console reporting is disabled!"); } }
public static void main(String... args) throws Exception { ws(); proto(); ConsoleReporter.forRegistry(Main.METRICS).convertDurationsTo(TimeUnit.MILLISECONDS) .convertRatesTo(TimeUnit.SECONDS).outputTo(System.out).build().report(); System.out.println("FYI, " + Runtime.getRuntime().availableProcessors() + " CPUs"); externalTest(); System.exit(0); }
@Override public ScheduledReporter getIfEnabled() { if (!config.isDebugReportingEnabled()) { return null; } return ConsoleReporter.forRegistry(registry) .build(); }
private void reportMetric() { System.out.println(); System.out.println(); ConsoleReporter .forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build() .report(); }
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() ); metrics.register("jvm.threads", new ThreadStatesGaugeSet() ); reporter.start(30, TimeUnit.SECONDS); TimeUnit.SECONDS.sleep(500); }
private void registerMetrics(final ResourceConfig resourceConfig) { logger.info("Registering Metrics service"); MetricRegistry metricsReg = MetricsUtil.getMetricsRegistry(); resourceConfig.register(new InstrumentedResourceMethodApplicationListener(metricsReg)); if (config.isConsoleMetrics()) { logger.info("Enabling console Metrics reporting"); ConsoleReporter.forRegistry(metricsReg).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build() .start(10, TimeUnit.SECONDS); } logger.info("Registered Metrics service"); }
@Before public void setUp() { ConsoleReporter reporter = ConsoleReporter.forRegistry(METRIC_REGISTRY) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.SECONDS); }
static void startReport() { ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.SECONDS); }
@Before public void setUp(TestContext context) { String graphiteHost = System.getProperty("graphiteHost"); final String registryName = "okapi"; MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName); // Note the setEnabled (true or false) DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions(). setEnabled(false).setRegistryName(registryName); vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(metricsOpt)); reporter1 = ConsoleReporter.forRegistry(registry).build(); reporter1.start(1, TimeUnit.SECONDS); if (graphiteHost != null) { Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, 2003)); reporter2 = GraphiteReporter.forRegistry(registry) .prefixedWith("okapiserver") .build(graphite); reporter2.start(1, TimeUnit.MILLISECONDS); } DeploymentOptions opt = new DeploymentOptions() .setConfig(new JsonObject().put("port", Integer.toString(port))); vertx.deployVerticle(MainVerticle.class.getName(), opt, context.asyncAssertSuccess()); httpClient = vertx.createHttpClient(); }
@TearDown public void dumpMetrics() throws Exception { // enable when using yourkit for single runs // if (controller != null) { // controller.captureSnapshot(Controller.SNAPSHOT_WITH_HEAP); // } final MetricRegistry metrics = injector.getInstance(MetricRegistry.class); // make the registry available to the profiler metricRegistry = metrics; final ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) .outputTo(new PrintStream("/tmp/bench-" + directoryName + ".txt")) .build(); reporter.report(); }
@Override public synchronized Reporter getReporter(MetricRegistry registry) { if (null == reporter) { reporter = ConsoleReporter.forRegistry(registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); } return reporter; }
@ProvidesIntoMap @StringMapKey("consoleReporter") public ScheduledReporter consoleReporter() { return ConsoleReporter .forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.SECONDS) .build(); }
@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; }
public ConsoleReporter consoleReporter( MetricRegistry registry ) { ConsoleReporter reporter = ConsoleReporter.forRegistry(registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(10, TimeUnit.SECONDS); return reporter; }
/** * Starts the console reporter if not already running * @param secs The frequency to report in seconds, defaults to 5 * @param ps The print stream to report to , defaults to System.out */ public void startConsoleReporter(final Long secs, final PrintStream ps) { if(consoleReporterEnabled.compareAndSet(false, true)) { consoleReporter = ConsoleReporter.forRegistry(this).outputTo(ps==null ? System.out : ps).build(); consoleReporter.start(secs==null ? 5 : secs, TimeUnit.SECONDS); } }
public void acceptVisitor(ServerVisitor serverVisitor){ //MetricRegistry to string try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos,false, "UTF-8"); ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).outputTo(ps).build(); consoleReporter.report(); consoleReporter.stop(); serverVisitor.jettyReport=new String(baos.toByteArray(), StandardCharsets.UTF_8); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }