use of com.codahale.metrics.ConsoleReporter in project atlasdb by palantir.
the class MetricsRule method after.
@Override
protected void after() {
super.after();
MetricRegistry metrics = metrics();
if (metrics != null) {
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).build();
reporter.report();
reporter.close();
SharedMetricRegistries.remove("AtlasDbTest");
}
}
use of com.codahale.metrics.ConsoleReporter in project storm by apache.
the class ConsoleStormReporter method init.
private void init(MetricRegistry registry, MetricRegistryProvider metricRegistryProvider, Map<String, Object> reporterConf) {
LOG.debug("Preparing ConsoleReporter");
ConsoleReporter.Builder builder = ConsoleReporter.forRegistry(registry);
builder.outputTo(System.out);
Locale locale = ClientMetricsUtils.getMetricsReporterLocale(reporterConf);
if (locale != null) {
builder.formattedFor(locale);
}
TimeUnit rateUnit = ClientMetricsUtils.getMetricsRateUnit(reporterConf);
if (rateUnit != null) {
builder.convertRatesTo(rateUnit);
}
TimeUnit durationUnit = ClientMetricsUtils.getMetricsDurationUnit(reporterConf);
if (durationUnit != null) {
builder.convertDurationsTo(durationUnit);
}
StormMetricsFilter filter = getMetricsFilter(reporterConf);
if (filter != null) {
builder.filter(filter);
}
// defaults to 10
reportingPeriod = getReportPeriod(reporterConf);
// defaults to seconds
reportingPeriodUnit = getReportPeriodUnit(reporterConf);
ScheduledReporter consoleReporter = builder.build();
boolean reportDimensions = isReportDimensionsEnabled(reporterConf);
if (reportDimensions) {
if (metricRegistryProvider == null) {
throw new RuntimeException("MetricRegistryProvider is required to enable reporting dimensions");
}
if (rateUnit == null) {
rateUnit = TimeUnit.SECONDS;
}
if (durationUnit == null) {
durationUnit = TimeUnit.MILLISECONDS;
}
DimensionalReporter dimensionalReporter = new DimensionalReporter(metricRegistryProvider, consoleReporter, this, "ConsoleDimensionalReporter", filter, rateUnit, durationUnit, null, true);
reporter = dimensionalReporter;
} else {
reporter = consoleReporter;
}
}
use of com.codahale.metrics.ConsoleReporter in project hbase by apache.
the class WALPerformanceEvaluation method run.
@Override
public int run(String[] args) throws Exception {
Path rootRegionDir = null;
int numThreads = 1;
long numIterations = 1000000;
int numFamilies = 1;
int syncInterval = 0;
boolean noSync = false;
boolean verify = false;
boolean verbose = false;
boolean cleanup = true;
boolean noclosefs = false;
long roll = Long.MAX_VALUE;
boolean compress = false;
String cipher = null;
int numRegions = 1;
// Process command line args
for (int i = 0; i < args.length; i++) {
String cmd = args[i];
try {
if (cmd.equals("-threads")) {
numThreads = Integer.parseInt(args[++i]);
} else if (cmd.equals("-iterations")) {
numIterations = Long.parseLong(args[++i]);
} else if (cmd.equals("-path")) {
rootRegionDir = new Path(args[++i]);
} else if (cmd.equals("-families")) {
numFamilies = Integer.parseInt(args[++i]);
} else if (cmd.equals("-qualifiers")) {
numQualifiers = Integer.parseInt(args[++i]);
} else if (cmd.equals("-keySize")) {
keySize = Integer.parseInt(args[++i]);
} else if (cmd.equals("-valueSize")) {
valueSize = Integer.parseInt(args[++i]);
} else if (cmd.equals("-syncInterval")) {
syncInterval = Integer.parseInt(args[++i]);
} else if (cmd.equals("-nosync")) {
noSync = true;
} else if (cmd.equals("-verify")) {
verify = true;
} else if (cmd.equals("-verbose")) {
verbose = true;
} else if (cmd.equals("-nocleanup")) {
cleanup = false;
} else if (cmd.equals("-noclosefs")) {
noclosefs = true;
} else if (cmd.equals("-roll")) {
roll = Long.parseLong(args[++i]);
} else if (cmd.equals("-compress")) {
compress = true;
} else if (cmd.equals("-encryption")) {
cipher = args[++i];
} else if (cmd.equals("-regions")) {
numRegions = Integer.parseInt(args[++i]);
} else if (cmd.equals("-traceFreq")) {
// keep it here for compatible
System.err.println("-traceFreq is not supported any more");
} else if (cmd.equals("-h")) {
printUsageAndExit();
} else if (cmd.equals("--help")) {
printUsageAndExit();
} else {
System.err.println("UNEXPECTED: " + cmd);
printUsageAndExit();
}
} catch (Exception e) {
printUsageAndExit();
}
}
if (compress) {
Configuration conf = getConf();
conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true);
}
if (cipher != null) {
// Set up WAL for encryption
Configuration conf = getConf();
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
conf.setClass("hbase.regionserver.hlog.reader.impl", SecureProtobufLogReader.class, WAL.Reader.class);
conf.setClass("hbase.regionserver.hlog.writer.impl", SecureProtobufLogWriter.class, Writer.class);
conf.setBoolean(HConstants.ENABLE_WAL_ENCRYPTION, true);
conf.set(HConstants.CRYPTO_WAL_ALGORITHM_CONF_KEY, cipher);
}
if (numThreads < numRegions) {
LOG.warn("Number of threads is less than the number of regions; some regions will sit idle.");
}
// Internal config. goes off number of threads; if more threads than handlers, stuff breaks.
// In regionserver, number of handlers == number of threads.
getConf().setInt(HConstants.REGION_SERVER_HANDLER_COUNT, numThreads);
if (rootRegionDir == null) {
TEST_UTIL = new HBaseTestingUtil(getConf());
rootRegionDir = TEST_UTIL.getDataTestDirOnTestFS("WALPerformanceEvaluation");
}
// Run WAL Performance Evaluation
// First set the fs from configs. In case we are on hadoop1
CommonFSUtils.setFsDefault(getConf(), CommonFSUtils.getRootDir(getConf()));
FileSystem fs = FileSystem.get(getConf());
LOG.info("FileSystem={}, rootDir={}", fs, rootRegionDir);
Span span = TraceUtil.getGlobalTracer().spanBuilder("WALPerfEval").startSpan();
try (Scope scope = span.makeCurrent()) {
rootRegionDir = rootRegionDir.makeQualified(fs.getUri(), fs.getWorkingDirectory());
cleanRegionRootDir(fs, rootRegionDir);
CommonFSUtils.setRootDir(getConf(), rootRegionDir);
final WALFactory wals = new WALFactory(getConf(), "wals");
final HRegion[] regions = new HRegion[numRegions];
final Runnable[] benchmarks = new Runnable[numRegions];
final MockRegionServerServices mockServices = new MockRegionServerServices(getConf());
final LogRoller roller = new LogRoller(mockServices);
Threads.setDaemonThreadRunning(roller, "WALPerfEval.logRoller");
try {
for (int i = 0; i < numRegions; i++) {
// Initialize Table Descriptor
// a table per desired region means we can avoid carving up the key space
final TableDescriptor htd = createHTableDescriptor(i, numFamilies);
regions[i] = openRegion(fs, rootRegionDir, htd, wals, roll, roller);
benchmarks[i] = new WALPutBenchmark(regions[i], htd, numIterations, noSync, syncInterval);
}
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).outputTo(System.out).convertRatesTo(TimeUnit.SECONDS).filter(MetricFilter.ALL).build();
reporter.start(30, TimeUnit.SECONDS);
long putTime = runBenchmark(benchmarks, numThreads);
logBenchmarkResult("Summary: threads=" + numThreads + ", iterations=" + numIterations + ", syncInterval=" + syncInterval, numIterations * numThreads, putTime);
for (int i = 0; i < numRegions; i++) {
if (regions[i] != null) {
closeRegion(regions[i]);
regions[i] = null;
}
}
if (verify) {
LOG.info("verifying written log entries.");
Path dir = new Path(CommonFSUtils.getRootDir(getConf()), AbstractFSWALProvider.getWALDirectoryName("wals"));
long editCount = 0;
FileStatus[] fsss = fs.listStatus(dir);
if (fsss.length == 0)
throw new IllegalStateException("No WAL found");
for (FileStatus fss : fsss) {
Path p = fss.getPath();
if (!fs.exists(p))
throw new IllegalStateException(p.toString());
editCount += verify(wals, p, verbose);
}
long expected = numIterations * numThreads;
if (editCount != expected) {
throw new IllegalStateException("Counted=" + editCount + ", expected=" + expected);
}
}
} finally {
mockServices.stop("test clean up.");
for (int i = 0; i < numRegions; i++) {
if (regions[i] != null) {
closeRegion(regions[i]);
}
}
if (null != roller) {
LOG.info("shutting down log roller.");
roller.close();
}
wals.shutdown();
// Remove the root dir for this test region
if (cleanup)
cleanRegionRootDir(fs, rootRegionDir);
}
} finally {
span.end();
// We may be called inside a test that wants to keep on using the fs.
if (!noclosefs) {
fs.close();
}
}
return 0;
}
use of com.codahale.metrics.ConsoleReporter in project newts by OpenNMS.
the class MergeSort method execute.
public void execute(String... args) throws IOException {
CmdLineParser parser = createCmdLineParser();
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
// handling of wrong arguments
System.err.println(e.getMessage());
parser.printUsage(System.err);
return;
}
final MetricRegistry metrics = new MetricRegistry();
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).outputTo(System.err).convertRatesTo(SECONDS).convertDurationsTo(MILLISECONDS).build();
reporter.start(10, SECONDS);
Meter linesMeter = metrics.meter("lines");
Meter filesMeter = metrics.meter("files");
Meter dirsMeter = metrics.meter("dirs");
Meter batchMeter = metrics.meter("batches");
Path root = m_source.toPath();
if (m_targetDir == null) {
m_targetDir = Files.createTempDir();
System.err.println("Working Directory: " + m_targetDir);
}
LOG.debug("Scanning {} for GSOD data files...", root);
FluentIterable<KeyedIterable<Path, Path>> dirs = FileIterable.groupFilesByDir(root);
for (KeyedIterable<Path, Path> filesInDir : dirs) {
Path subdir = root.relativize(filesInDir.getKey());
String dirName = subdir.getFileName().toString();
System.err.println("Sorted dir: " + subdir);
FluentIterable<Iterable<String>> contentIterables = filesInDir.transform(this.<Path>meter(filesMeter)).transform(lines("YEARMODA"));
FluentIterable<List<Iterable<String>>> batches = FluentIterable.from(Iterables.partition(contentIterables, m_mergeCount));
FluentIterable<Iterable<GSODLine>> sortedBatches = batches.transform(lift2GsodLines()).transform(mergeSorter());
Path sortedDir = m_targetDir.toPath().resolve(subdir);
sortedDir.toFile().mkdirs();
int count = 1;
for (Iterable<GSODLine> batch : sortedBatches) {
Path sortedFile = sortedDir.resolve(dirName + "-batch-" + (count++) + ".gz");
System.err.println("Creating " + sortedFile);
try (PrintStream out = open(sortedFile)) {
out.println(HDR);
for (GSODLine line : batch) {
out.println(line);
linesMeter.mark();
}
}
batchMeter.mark();
}
dirsMeter.mark();
}
}
use of com.codahale.metrics.ConsoleReporter in project Dempsy by Dempsy.
the class ConsoleRegistrar method registerReporter.
@Override
public Reporter registerReporter(final MetricRegistry registry, final String metricsPrefix) {
final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(registry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
consoleReporter.start(period, unit);
return consoleReporter;
}
Aggregations