use of com.codahale.metrics.jvm.MemoryUsageGaugeSet in project dropwizard by dropwizard.
the class Bootstrap method registerMetrics.
/**
* Registers the JVM metrics to the metric registry and start to report
* the registry metrics via JMX.
*/
public void registerMetrics() {
if (metricsAreRegistered) {
return;
}
getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet());
getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet());
getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge());
getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet());
getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet());
getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet());
JmxReporter.forRegistry(metricRegistry).build().start();
metricsAreRegistered = true;
}
use of com.codahale.metrics.jvm.MemoryUsageGaugeSet in project spaceships-demo by puniverse.
the class Spaceships method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
System.out.println("COMPILER: " + System.getProperty("java.vm.name"));
System.out.println("VERSION: " + System.getProperty("java.version"));
System.out.println("OS: " + System.getProperty("os.name"));
System.out.println("PROCESSORS: " + Runtime.getRuntime().availableProcessors());
System.out.println();
Properties props = new Properties();
props.load(new InputStreamReader(ClassLoader.getSystemResourceAsStream("spaceships.properties")));
Metrics.register("cpu", new CpuUsageGaugeSet());
Metrics.register("memory", new MemoryUsageGaugeSet());
int glxNode = args.length > 0 ? Integer.parseInt(args[0]) : -1;
if (glxNode < 0)
glxNode = Integer.parseInt(props.getProperty("galaxy.nodeId", "-1"));
if (glxNode >= 0) {
if (glxNode == 0)
throw new IllegalArgumentException("Node cannot be 0. Reserved for Galaxy server.");
System.out.println("Connecting to Galaxy cluster...");
System.setProperty("co.paralleluniverse.flightRecorderDumpFile", "spaceships-" + glxNode + ".log");
System.setProperty("galaxy.nodeId", Integer.toString(glxNode));
System.setProperty("galaxy.port", props.getProperty("galaxy.port", Integer.toString(7050 + glxNode)));
System.setProperty("galaxy.slave_port", props.getProperty("galaxy.port", Integer.toString(8050 + glxNode)));
Grid.getInstance();
}
System.out.println("Initializing...");
spaceships = new Spaceships(glxNode, props);
System.out.println("Running...");
spaceships.run();
Thread.sleep(100000);
}
use of com.codahale.metrics.jvm.MemoryUsageGaugeSet in project cassandra by apache.
the class CassandraDaemon method setup.
/**
* This is a hook for concrete daemons to initialize themselves suitably.
*
* Subclasses should override this to finish the job (listening on ports, etc.)
*/
protected void setup() {
FileUtils.setFSErrorHandler(new DefaultFSErrorHandler());
// Delete any failed snapshot deletions on Windows - see CASSANDRA-9658
if (FBUtilities.isWindows)
WindowsFailedSnapshotTracker.deleteOldSnapshots();
maybeInitJmx();
Mx4jTool.maybeLoad();
ThreadAwareSecurityManager.install();
logSystemInfo();
CLibrary.tryMlockall();
try {
startupChecks.verify();
} catch (StartupException e) {
exitOrFail(e.returnCode, e.getMessage(), e.getCause());
}
// We need to persist this as soon as possible after startup checks.
// This should be the first write to SystemKeyspace (CASSANDRA-11742)
SystemKeyspace.persistLocalMetadata();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
StorageMetrics.exceptions.inc();
logger.error("Exception in thread " + t, e);
Tracing.trace("Exception in thread {}", t, e);
for (Throwable e2 = e; e2 != null; e2 = e2.getCause()) {
JVMStabilityInspector.inspectThrowable(e2);
if (e2 instanceof FSError) {
if (// make sure FSError gets logged exactly once.
e2 != e)
logger.error("Exception in thread " + t, e2);
FileUtils.handleFSError((FSError) e2);
}
if (e2 instanceof CorruptSSTableException) {
if (e2 != e)
logger.error("Exception in thread " + t, e2);
FileUtils.handleCorruptSSTable((CorruptSSTableException) e2);
}
}
}
});
// Populate token metadata before flushing, for token-aware sstable partitioning (#6696)
StorageService.instance.populateTokenMetadata();
// load schema from disk
Schema.instance.loadFromDisk();
// clean up debris in the rest of the keyspaces
for (String keyspaceName : Schema.instance.getKeyspaces()) {
// Skip system as we've already cleaned it
if (keyspaceName.equals(SchemaConstants.SYSTEM_KEYSPACE_NAME))
continue;
for (TableMetadata cfm : Schema.instance.getTablesAndViews(keyspaceName)) {
try {
ColumnFamilyStore.scrubDataDirectories(cfm);
} catch (StartupException e) {
exitOrFail(e.returnCode, e.getMessage(), e.getCause());
}
}
}
Keyspace.setInitialized();
// initialize keyspaces
for (String keyspaceName : Schema.instance.getKeyspaces()) {
if (logger.isDebugEnabled())
logger.debug("opening keyspace {}", keyspaceName);
// disable auto compaction until commit log replay ends
for (ColumnFamilyStore cfs : Keyspace.open(keyspaceName).getColumnFamilyStores()) {
for (ColumnFamilyStore store : cfs.concatWithIndexes()) {
store.disableAutoCompaction();
}
}
}
try {
loadRowAndKeyCacheAsync().get();
} catch (Throwable t) {
JVMStabilityInspector.inspectThrowable(t);
logger.warn("Error loading key or row cache", t);
}
try {
GCInspector.register();
} catch (Throwable t) {
JVMStabilityInspector.inspectThrowable(t);
logger.warn("Unable to start GCInspector (currently only supported on the Sun JVM)");
}
// Replay any CommitLogSegments found on disk
try {
CommitLog.instance.recoverSegmentsOnDisk();
} catch (IOException e) {
throw new RuntimeException(e);
}
// Re-populate token metadata after commit log recover (new peers might be loaded onto system keyspace #10293)
StorageService.instance.populateTokenMetadata();
// enable auto compaction
for (Keyspace keyspace : Keyspace.all()) {
for (ColumnFamilyStore cfs : keyspace.getColumnFamilyStores()) {
for (final ColumnFamilyStore store : cfs.concatWithIndexes()) {
if (store.getCompactionStrategyManager().shouldBeEnabled())
store.enableAutoCompaction();
}
}
}
SystemKeyspace.finishStartup();
ActiveRepairService.instance.start();
// Prepared statements
QueryProcessor.preloadPreparedStatement();
// Metrics
String metricsReporterConfigFile = System.getProperty("cassandra.metricsReporterConfigFile");
if (metricsReporterConfigFile != null) {
logger.info("Trying to load metrics-reporter-config from file: {}", metricsReporterConfigFile);
try {
// enable metrics provided by metrics-jvm.jar
CassandraMetricsRegistry.Metrics.register("jvm.buffers.", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
CassandraMetricsRegistry.Metrics.register("jvm.gc.", new GarbageCollectorMetricSet());
CassandraMetricsRegistry.Metrics.register("jvm.memory.", new MemoryUsageGaugeSet());
CassandraMetricsRegistry.Metrics.register("jvm.fd.usage", new FileDescriptorRatioGauge());
// initialize metrics-reporter-config from yaml file
URL resource = CassandraDaemon.class.getClassLoader().getResource(metricsReporterConfigFile);
if (resource == null) {
logger.warn("Failed to load metrics-reporter-config, file does not exist: {}", metricsReporterConfigFile);
} else {
String reportFileLocation = resource.getFile();
ReporterConfig.loadFromFile(reportFileLocation).enableAll(CassandraMetricsRegistry.Metrics);
}
} catch (Exception e) {
logger.warn("Failed to load metrics-reporter-config, metric sinks will not be activated", e);
}
}
// start server internals
StorageService.instance.registerDaemon(this);
try {
StorageService.instance.initServer();
} catch (ConfigurationException e) {
System.err.println(e.getMessage() + "\nFatal configuration error; unable to start server. See log for stacktrace.");
exitOrFail(1, "Fatal configuration error", e);
}
// Because we are writing to the system_distributed keyspace, this should happen after that is created, which
// happens in StorageService.instance.initServer()
Runnable viewRebuild = () -> {
for (Keyspace keyspace : Keyspace.all()) {
keyspace.viewManager.buildAllViews();
}
logger.debug("Completed submission of build tasks for any materialized views defined at startup");
};
ScheduledExecutors.optionalTasks.schedule(viewRebuild, StorageService.RING_DELAY, TimeUnit.MILLISECONDS);
if (!FBUtilities.getBroadcastAddress().equals(InetAddress.getLoopbackAddress()))
Gossiper.waitToSettle();
// schedule periodic background compaction task submission. this is simply a backstop against compactions stalling
// due to scheduling errors or race conditions
ScheduledExecutors.optionalTasks.scheduleWithFixedDelay(ColumnFamilyStore.getBackgroundCompactionTaskSubmitter(), 5, 1, TimeUnit.MINUTES);
// schedule periodic dumps of table size estimates into SystemKeyspace.SIZE_ESTIMATES_CF
// set cassandra.size_recorder_interval to 0 to disable
int sizeRecorderInterval = Integer.getInteger("cassandra.size_recorder_interval", 5 * 60);
if (sizeRecorderInterval > 0)
ScheduledExecutors.optionalTasks.scheduleWithFixedDelay(SizeEstimatesRecorder.instance, 30, sizeRecorderInterval, TimeUnit.SECONDS);
// Native transport
nativeTransportService = new NativeTransportService();
completeSetup();
}
use of com.codahale.metrics.jvm.MemoryUsageGaugeSet in project chassis by Kixeye.
the class ChassisConfiguration method metricRegistry.
/**
* Initializes the metrics registry
*
* @return metric registry bean
*/
@Bean
public MetricRegistry metricRegistry() {
final MetricRegistry bean = new MetricRegistry();
// add JVM metrics
bean.register("jvm.gc", new GarbageCollectorMetricSet());
bean.register("jvm.memory", new MemoryUsageGaugeSet());
bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
bean.register("jvm.fd", new FileDescriptorRatioGauge());
bean.register("jvm.load-average", new Gauge<Double>() {
private OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
public Double getValue() {
try {
return mxBean.getSystemLoadAverage();
} catch (Exception e) {
// not supported
return -1d;
}
}
});
// add Logback metrics
final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
final InstrumentedAppender appender = new InstrumentedAppender(bean);
appender.setContext(root.getLoggerContext());
appender.start();
root.addAppender(appender);
return bean;
}
use of com.codahale.metrics.jvm.MemoryUsageGaugeSet in project cas by apereo.
the class CasMetricsConfiguration method metrics.
/**
* Metric registry metric registry.
*
* @return the metric registry
*/
@RefreshScope
@Bean
public MetricRegistry metrics() {
final MetricRegistry metrics = new MetricRegistry();
metrics.register("jvm.gc", new GarbageCollectorMetricSet());
metrics.register("jvm.memory", new MemoryUsageGaugeSet());
metrics.register("thread-states", new ThreadStatesGaugeSet());
metrics.register("jvm.fd.usage", new FileDescriptorRatioGauge());
return metrics;
}
Aggregations