use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class OsgiScriptBindingsProviderTest method testInactiveBundles.
@Test
public void testInactiveBundles() throws Exception {
final BundleContext ctx = Mockito.mock(BundleContext.class);
final Bundle[] bundles = { mockBundle(false, true), mockBundle(false, false), mockBundle(false, true), mockBundle(true, false) };
Mockito.when(ctx.getBundles()).thenReturn(bundles);
final FormattingResultLog resultLog = new FormattingResultLog();
final OsgiScriptBindingsProvider.OsgiBinding b = new OsgiScriptBindingsProvider.OsgiBinding(ctx, resultLog);
assertEquals(1, b.inactiveBundlesCount());
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class DefaultLoginsHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
int checked = 0;
int failures = 0;
for (String login : logins) {
final String[] parts = login.split(":");
if (parts.length != 2) {
resultLog.warn("Expected login in the form username:password, got [{}]", login);
continue;
}
checked++;
final String username = parts[0].trim();
final String password = parts[1].trim();
final Credentials creds = new SimpleCredentials(username, password.toCharArray());
Session s = null;
try {
s = repository.login(creds);
if (s != null) {
failures++;
resultLog.warn("Login as [{}] succeeded, was expecting it to fail", username);
} else {
resultLog.debug("Login as [{}] didn't throw an Exception but returned null Session", username);
}
} catch (RepositoryException re) {
resultLog.debug("Login as [{}] failed, as expected", username);
} finally {
if (s != null) {
s.logout();
}
}
}
if (checked == 0) {
resultLog.warn("Did not check any logins, configured logins={}", logins);
} else if (failures != 0) {
resultLog.warn("Checked {} logins, {} failures", checked, failures);
} else {
resultLog.debug("Checked {} logins, all successful", checked, failures);
}
return new Result(resultLog);
}
use of org.apache.sling.hc.util.FormattingResultLog 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 org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class JmxScriptBindingsProviderTest method testJmxAttribute.
@Test
public void testJmxAttribute() throws Exception {
final FormattingResultLog resultLog = new FormattingResultLog();
final JmxScriptBindingsProvider.AttributeBinding b = new JmxScriptBindingsProvider.AttributeBinding(ManagementFactory.getPlatformMBeanServer(), resultLog);
final Object value = b.attribute("java.lang:type=ClassLoading", "LoadedClassCount");
assertNotNull("Expecting non-null attribute value", value);
assertTrue("Expecting non-empty value", value.toString().length() > 0);
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class JUnitHealthCheck method execute.
public Result execute() {
final String extension = "json";
final FormattingResultLog resultLog = new FormattingResultLog();
final CustomRunListener listener = new CustomRunListener(resultLog);
final Renderer r = new CustomRenderer(listener, extension, resultLog);
final Collection<String> testNames = testsManager.getTestNames(testSelector);
if (testNames.isEmpty()) {
resultLog.warn("No tests found for selector {}", testSelector);
} else {
try {
testsManager.executeTests(testNames, r, testSelector);
if (listener.nTests == 0) {
resultLog.warn("No tests executed by {}", testSelector);
}
} catch (Exception e) {
resultLog.warn("Exception while executing tests (" + testSelector + ")" + e);
}
}
return new Result(resultLog);
}
Aggregations