use of java.lang.management.RuntimeMXBean in project storm by apache.
the class SystemBolt method prepare.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void prepare(final Map topoConf, TopologyContext context, OutputCollector collector) {
if (_prepareWasCalled && !"local".equals(topoConf.get(Config.STORM_CLUSTER_MODE))) {
throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
}
_prepareWasCalled = true;
int bucketSize = Utils.getInt(topoConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
context.registerMetric("uptimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getUptime() / 1000.0;
}
}, bucketSize);
context.registerMetric("startTimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getStartTime() / 1000.0;
}
}, bucketSize);
context.registerMetric("newWorkerEvent", new IMetric() {
boolean doEvent = true;
@Override
public Object getValueAndReset() {
if (doEvent) {
doEvent = false;
return 1;
} else
return 0;
}
}, bucketSize);
final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
context.registerMetric("memory/heap", new MemoryUsageMetric(jvmMemRT::getHeapMemoryUsage), bucketSize);
context.registerMetric("memory/nonHeap", new MemoryUsageMetric(jvmMemRT::getNonHeapMemoryUsage), bucketSize);
for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
}
registerMetrics(context, (Map<String, String>) topoConf.get(Config.WORKER_METRICS), bucketSize, topoConf);
registerMetrics(context, (Map<String, String>) topoConf.get(Config.TOPOLOGY_WORKER_METRICS), bucketSize, topoConf);
}
use of java.lang.management.RuntimeMXBean in project hazelcast by hazelcast.
the class TimedMemberStateFactoryHelper method createRuntimeProps.
static void createRuntimeProps(MemberStateImpl memberState) {
Runtime runtime = Runtime.getRuntime();
ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean();
MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
MemoryUsage heapMemory = memoryMxBean.getHeapMemoryUsage();
MemoryUsage nonHeapMemory = memoryMxBean.getNonHeapMemoryUsage();
Map<String, Long> map = new HashMap<String, Long>();
map.put("runtime.availableProcessors", Integer.valueOf(runtime.availableProcessors()).longValue());
map.put("date.startTime", runtimeMxBean.getStartTime());
map.put("seconds.upTime", runtimeMxBean.getUptime());
map.put("memory.maxMemory", runtime.maxMemory());
map.put("memory.freeMemory", runtime.freeMemory());
map.put("memory.totalMemory", runtime.totalMemory());
map.put("memory.heapMemoryMax", heapMemory.getMax());
map.put("memory.heapMemoryUsed", heapMemory.getUsed());
map.put("memory.nonHeapMemoryMax", nonHeapMemory.getMax());
map.put("memory.nonHeapMemoryUsed", nonHeapMemory.getUsed());
map.put("runtime.totalLoadedClassCount", clMxBean.getTotalLoadedClassCount());
map.put("runtime.loadedClassCount", Integer.valueOf(clMxBean.getLoadedClassCount()).longValue());
map.put("runtime.unloadedClassCount", clMxBean.getUnloadedClassCount());
map.put("runtime.totalStartedThreadCount", threadMxBean.getTotalStartedThreadCount());
map.put("runtime.threadCount", Integer.valueOf(threadMxBean.getThreadCount()).longValue());
map.put("runtime.peakThreadCount", Integer.valueOf(threadMxBean.getPeakThreadCount()).longValue());
map.put("runtime.daemonThreadCount", Integer.valueOf(threadMxBean.getDaemonThreadCount()).longValue());
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
map.put("osMemory.freePhysicalMemory", get(osMxBean, "getFreePhysicalMemorySize", 0L));
map.put("osMemory.committedVirtualMemory", get(osMxBean, "getCommittedVirtualMemorySize", 0L));
map.put("osMemory.totalPhysicalMemory", get(osMxBean, "getTotalPhysicalMemorySize", 0L));
map.put("osSwap.freeSwapSpace", get(osMxBean, "getFreeSwapSpaceSize", 0L));
map.put("osSwap.totalSwapSpace", get(osMxBean, "getTotalSwapSpaceSize", 0L));
map.put("os.maxFileDescriptorCount", get(osMxBean, "getMaxFileDescriptorCount", 0L));
map.put("os.openFileDescriptorCount", get(osMxBean, "getOpenFileDescriptorCount", 0L));
map.put("os.processCpuLoad", get(osMxBean, "getProcessCpuLoad", -1L));
map.put("os.systemLoadAverage", get(osMxBean, "getSystemLoadAverage", -1L));
map.put("os.systemCpuLoad", get(osMxBean, "getSystemCpuLoad", -1L));
map.put("os.processCpuTime", get(osMxBean, "getProcessCpuTime", 0L));
map.put("os.availableProcessors", get(osMxBean, "getAvailableProcessors", 0L));
memberState.setRuntimeProps(map);
}
use of java.lang.management.RuntimeMXBean in project hazelcast by hazelcast.
the class RuntimeMetricSet method register.
/**
* Registers all the metrics in this metrics pack.
*
* @param metricsRegistry the MetricsRegistry upon which the metrics are registered.
*/
public static void register(MetricsRegistry metricsRegistry) {
checkNotNull(metricsRegistry, "metricsRegistry");
Runtime runtime = Runtime.getRuntime();
RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
metricsRegistry.register(runtime, "runtime.freeMemory", MANDATORY, new LongProbeFunction<Runtime>() {
@Override
public long get(Runtime runtime) {
return runtime.freeMemory();
}
});
metricsRegistry.register(runtime, "runtime.totalMemory", MANDATORY, new LongProbeFunction<Runtime>() {
@Override
public long get(Runtime runtime) {
return runtime.totalMemory();
}
});
metricsRegistry.register(runtime, "runtime.maxMemory", MANDATORY, new LongProbeFunction<Runtime>() {
@Override
public long get(Runtime runtime) {
return runtime.maxMemory();
}
});
metricsRegistry.register(runtime, "runtime.usedMemory", MANDATORY, new LongProbeFunction<Runtime>() {
@Override
public long get(Runtime runtime) {
return runtime.totalMemory() - runtime.freeMemory();
}
});
metricsRegistry.register(runtime, "runtime.availableProcessors", MANDATORY, new LongProbeFunction<Runtime>() {
@Override
public long get(Runtime runtime) {
return runtime.availableProcessors();
}
});
metricsRegistry.register(mxBean, "runtime.uptime", MANDATORY, new LongProbeFunction<RuntimeMXBean>() {
@Override
public long get(RuntimeMXBean runtimeMXBean) {
return runtimeMXBean.getUptime();
}
});
}
use of java.lang.management.RuntimeMXBean in project hazelcast by hazelcast.
the class ClusterPropsRequest method writeResponse.
@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
Runtime runtime = Runtime.getRuntime();
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
IPartitionService partitionService = mcs.getHazelcastInstance().node.getPartitionService();
JsonObject properties = new JsonObject();
properties.add("hazelcast.cl_version", mcs.getHazelcastInstance().node.getBuildInfo().getVersion());
properties.add("date.cl_startTime", Long.toString(runtimeMxBean.getStartTime()));
properties.add("seconds.cl_upTime", Long.toString(runtimeMxBean.getUptime()));
properties.add("memory.cl_freeMemory", Long.toString(runtime.freeMemory()));
properties.add("memory.cl_totalMemory", Long.toString(runtime.totalMemory()));
properties.add("memory.cl_maxMemory", Long.toString(runtime.maxMemory()));
properties.add("return.hasOngoingMigration", Boolean.toString(partitionService.hasOnGoingMigration()));
properties.add("data.cl_migrationTasksCount", Long.toString(partitionService.getMigrationQueueSize()));
root.add("result", properties);
}
use of java.lang.management.RuntimeMXBean in project cassandra by apache.
the class HeapUtils method getHeapDumpPathOption.
/**
* Retrieves the value of the <code>HeapDumpPath</code> JVM option.
* @return the value of the <code>HeapDumpPath</code> JVM option or <code>null</code> if the value has not been
* specified.
*/
private static String getHeapDumpPathOption() {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> inputArguments = runtimeMxBean.getInputArguments();
String heapDumpPathOption = null;
for (String argument : inputArguments) {
if (argument.startsWith("-XX:HeapDumpPath=")) {
heapDumpPathOption = argument;
// We do not break in case the option has been specified several times.
// In general it seems that JVMs use the right-most argument as the winner.
}
}
if (heapDumpPathOption == null)
return null;
return heapDumpPathOption.substring(17, heapDumpPathOption.length());
}
Aggregations