|
Java example source code file (CustomReporter.java)
The CustomReporter.java Java example source code/* * Copyright 2012 The Netty Project * * The Netty Project licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package io.netty.test.udt.util; import com.yammer.metrics.Metrics; import com.yammer.metrics.core.Clock; import com.yammer.metrics.core.Counter; import com.yammer.metrics.core.Gauge; import com.yammer.metrics.core.Histogram; import com.yammer.metrics.core.Metered; import com.yammer.metrics.core.Metric; import com.yammer.metrics.core.MetricName; import com.yammer.metrics.core.MetricPredicate; import com.yammer.metrics.core.MetricProcessor; import com.yammer.metrics.core.MetricsRegistry; import com.yammer.metrics.core.Timer; import com.yammer.metrics.reporting.AbstractPollingReporter; import com.yammer.metrics.stats.Snapshot; import java.io.PrintStream; import java.text.DateFormat; import java.util.Date; import java.util.Locale; import java.util.Map.Entry; import java.util.SortedMap; import java.util.TimeZone; import java.util.concurrent.TimeUnit; /** * A simple reporters which prints out application metrics to a * {@link PrintStream} periodically. */ public class CustomReporter extends AbstractPollingReporter implements MetricProcessor<PrintStream> { private static final int CONSOLE_WIDTH = 80; /** * Enables the console reporter for the default metrics registry, and causes * it to print to STDOUT with the specified period. */ public static void enable(final long period, final TimeUnit unit) { enable(Metrics.defaultRegistry(), period, unit); } /** * Enables the console reporter for the given metrics registry, and causes * it to print to STDOUT with the specified period and unrestricted output. */ public static void enable(final MetricsRegistry metricsRegistry, final long period, final TimeUnit unit) { final CustomReporter reporter = new CustomReporter( metricsRegistry, System.out, MetricPredicate.ALL); reporter.start(period, unit); } private final PrintStream out; private final MetricPredicate predicate; private final Clock clock; private final TimeZone timeZone; private final Locale locale; /** * Creates a new {@link CustomReporter} for the default metrics * registry, with unrestricted output. */ public CustomReporter(final PrintStream out) { this(Metrics.defaultRegistry(), out, MetricPredicate.ALL); } /** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate) { this(metricsRegistry, out, predicate, Clock.defaultClock(), TimeZone .getDefault()); } /** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate, final Clock clock, final TimeZone timeZone) { this(metricsRegistry, out, predicate, clock, timeZone, Locale .getDefault()); } /** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate, final Clock clock, final TimeZone timeZone, final Locale locale) { super(metricsRegistry, "console-reporter"); this.out = out; this.predicate = predicate; this.clock = clock; this.timeZone = timeZone; this.locale = locale; } @Override public void run() { try { final DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM, locale); format.setTimeZone(timeZone); final String dateTime = format.format(new Date(clock.time())); out.print(dateTime); out.print(' '); for (int i = 0; i < CONSOLE_WIDTH - dateTime.length() - 1; i++) { out.print('='); } out.println(); for (final Entry<String, SortedMap Other Java examples (source code examples)Here is a short list of links related to this Java CustomReporter.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.