use of java.lang.management.ThreadMXBean in project sling by apache.
the class ThreadUsageHealthCheck method execute.
@Override
public Result execute() {
FormattingResultLog log = new FormattingResultLog();
log.debug("Checking threads for exceeding {}% CPU time within time period of {}ms", cpuTimeThresholdWarn, samplePeriodInMs);
try {
ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
List<ThreadTimeInfo> threadTimeInfos = collectThreadTimeInfos(log, threadMxBean);
Collections.sort(threadTimeInfos);
float totalCpuTimePercentage = 0;
for (int i = 0; i < threadTimeInfos.size(); i++) {
ThreadTimeInfo threadInfo = threadTimeInfos.get(i);
float cpuTimePercentage = ((float) threadInfo.getCpuTime() / ((float) samplePeriodInMs * 1000000)) * 100f;
totalCpuTimePercentage += cpuTimePercentage;
String msg = String.format("%4.1f", cpuTimePercentage) + "% used by thread \"" + threadInfo.name + "\"";
if (i < 3 || (i < 10 && cpuTimePercentage > 15)) {
log.info(msg);
} else {
log.debug(msg);
}
}
log.info(threadTimeInfos.size() + " threads using " + String.format("%4.1f", totalCpuTimePercentage) + "% CPU Time");
boolean isHighCpuTime = totalCpuTimePercentage > cpuTimeThresholdWarn;
if (isHighCpuTime) {
log.warn("Threads are consuming significant CPU time " + (cpuTimeThresholdWarnIsConfigured ? "(more than configured " + cpuTimeThresholdWarn + "% within " + samplePeriodInMs + "ms)" : "(more than " + availableProcessors + " cores * 90% = " + cpuTimeThresholdWarn + "%)"));
}
checkForDeadlock(log, threadMxBean);
} catch (Exception e) {
LOG.error("Could not analyse thread usage " + e, e);
log.healthCheckError("Could not analyse thread usage", e);
}
return new Result(log);
}
use of java.lang.management.ThreadMXBean in project gerrit by GerritCodeReview.
the class ProcMetricModule method procJvmThread.
private void procJvmThread(MetricMaker metrics) {
ThreadMXBean thread = ManagementFactory.getThreadMXBean();
metrics.newCallbackMetric("proc/jvm/thread/num_live", Integer.class, new Description("Current live thread count").setGauge().setUnit("threads"), () -> thread.getThreadCount());
}
use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.
the class JvmThreadingImpl method checkJvmThreadContentionMonitoring.
/**
* Checker for the "JvmThreadContentionMonitoring" variable.
*/
public void checkJvmThreadContentionMonitoring(EnumJvmThreadContentionMonitoring x) throws SnmpStatusException {
//Can't be set externaly to unsupported state.
if (JvmThreadContentionMonitoringUnsupported.intValue() == x.intValue()) {
log.debug("checkJvmThreadContentionMonitoring", "Try to set to illegal unsupported value");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
if ((JvmThreadContentionMonitoringEnabled.intValue() == x.intValue()) || (JvmThreadContentionMonitoringDisabled.intValue() == x.intValue())) {
// The value is valid, but is the feature supported ?
ThreadMXBean mbean = getThreadMXBean();
if (mbean.isThreadContentionMonitoringSupported())
return;
log.debug("checkJvmThreadContentionMonitoring", "Unsupported operation, can't set state");
throw new SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
}
log.debug("checkJvmThreadContentionMonitoring", "Try to set to unknown value");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.
the class JvmThreadInstanceEntryImpl method getJvmThreadInstBlockTimeMs.
/**
* Getter for the "JvmThreadInstBlockTimeMs" variable.
*/
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
long l = 0;
final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
if (tmb.isThreadContentionMonitoringSupported()) {
l = info.getBlockedTime();
//Monitoring is disabled
if (l == -1)
l = 0;
}
return new Long(l);
}
use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.
the class JvmThreadInstanceEntryImpl method getJvmThreadInstCpuTimeNs.
/**
* Getter for the "JvmThreadInstCpuTimeNs" variable.
*/
public Long getJvmThreadInstCpuTimeNs() throws SnmpStatusException {
long l = 0;
final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
try {
if (tmb.isThreadCpuTimeSupported()) {
l = tmb.getThreadCpuTime(info.getThreadId());
log.debug("getJvmThreadInstCpuTimeNs", "Cpu time ns : " + l);
//Cpu time measurement is disabled or the id is not valid.
if (l == -1)
l = 0;
}
} catch (UnsatisfiedLinkError e) {
// XXX Revisit: catch TO BE EVENTUALLY REMOVED
log.debug("getJvmThreadInstCpuTimeNs", "Operation not supported: " + e);
}
return new Long(l);
}
Aggregations