use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class SynchronizedClocksHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
resultLog.debug("Checking cluster internal clocks");
try {
final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
ObjectName n = new ObjectName(DOCUMENT_NODE_STORE_MBEAN);
Set<ObjectName> names = jmxServer.queryNames(n, null);
if (names.size() == 0) {
resultLog.info("Intra-cluster test n/a (No DocumentNodeStore MBean found)");
} else {
ObjectName firstName = names.iterator().next();
final Object value = jmxServer.invoke(firstName, TIME_DIFF_METHOD_NAME, new Object[0], new String[0]);
logger.debug("{} returns {}", new Object[] { firstName, TIME_DIFF_METHOD_NAME, value });
resultLog.debug("{} returns {}", firstName, TIME_DIFF_METHOD_NAME, value);
if (value != null && (value instanceof Long)) {
Long diffMillis = (Long) value;
if (Math.abs(diffMillis) >= INTRA_CLUSTER_HIGH_WATER_MARK) {
logger.warn("execute: clocks in local cluster out of sync by {}ms " + "which is equal or higher than the high-water mark of {}ms.", diffMillis, INTRA_CLUSTER_HIGH_WATER_MARK);
resultLog.critical("Clocks heavily out of sync in local cluster: " + "time difference of this VM with DocumentStore server: " + "{}ms is equal or larger than high-water mark of {}ms", diffMillis, INTRA_CLUSTER_HIGH_WATER_MARK);
} else if (Math.abs(diffMillis) >= INTRA_CLUSTER_LOW_WATER_MARK) {
logger.warn("execute: clocks in local cluster out of sync by {}ms" + "ms which is equal or higher than the low-water mark of {}ms.", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
resultLog.warn("Clocks noticeably out of sync in local cluster: " + "time difference of this VM with DocumentStore server: " + "{}ms is equal or larger than low-water mark of {}ms", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
} else {
logger.debug("execute: clocks in local cluster in sync. diff is {}ms" + "ms which is within low-water mark of {}ms.", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
resultLog.info("Clocks in sync in local cluster: time difference of this VM with DocumentStore server: " + "{}ms is within low-water mark of {}ms", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
}
}
}
} catch (final Exception e) {
logger.warn("execute: {}, JMX method {} invocation failed: {}", new Object[] { DOCUMENT_NODE_STORE_MBEAN, TIME_DIFF_METHOD_NAME, e });
resultLog.healthCheckError("{}, JMX method {} invocation failed: {}", DOCUMENT_NODE_STORE_MBEAN, TIME_DIFF_METHOD_NAME, e);
}
final String slingId = settingsService == null ? "n/a" : settingsService.getSlingId();
if (announcementRegistry == null) {
logger.warn("execute: no announcementRegistry ({}) set", announcementRegistry);
resultLog.warn("Cannot determine topology clocks since no announcementRegistry ({}) set", announcementRegistry);
} else {
final Collection<Announcement> localAnnouncements = announcementRegistry.listLocalAnnouncements();
if (localAnnouncements.isEmpty()) {
logger.info("execute: no topology connectors connected to local instance.");
resultLog.info("No topology connectors connected to local instance.");
}
for (Announcement ann : localAnnouncements) {
final String peerSlingId = ann.getOwnerId();
final long originallyCreatedAt = ann.getOriginallyCreatedAt();
final long receivedAt = ann.getReceivedAt();
long diffMillis = Math.abs(originallyCreatedAt - receivedAt);
if (Math.abs(diffMillis) >= INTER_CLUSTER_HIGH_WATER_MARK) {
logger.warn("execute: clocks between local instance (slingId: {}) and remote instance (slingId: {}) out of sync by {}ms" + "ms which is equal or higher than the high-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
resultLog.critical("Clocks heavily out of sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "by {}ms which is equal or larger than high-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
} else if (Math.abs(diffMillis) >= INTER_CLUSTER_LOW_WATER_MARK) {
logger.warn("execute: clocks out of sync between local instance (slingId: {}) and remote instance (slingId: {}) by {}ms " + "ms which is equal or higher than the low-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
resultLog.warn("Clocks noticeably out of sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "by {}ms which is equal or larger than low-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
} else {
logger.debug("execute: clocks in sync between local instance (slingId: {}) and remote instance (slingId: {}). " + "diff is {}ms which is within low-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
resultLog.info("Clocks in sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "diff is {}ms which is within low-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
}
}
}
return new Result(resultLog);
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class SlingRequestStatusHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
ResourceResolver resolver = null;
int checked = 0;
int failed = 0;
String lastPath = null;
try {
resolver = resolverFactory.getAdministrativeResourceResolver(null);
for (String p : paths) {
lastPath = p;
final PathSpec ps = new PathSpec(p, resultLog);
final HttpServletRequest request = new InternalRequest(ps.path);
final InternalResponse response = new InternalResponse();
requestProcessor.processRequest(request, response, resolver);
final int status = response.getStatus();
if (status != ps.status) {
failed++;
resultLog.warn("[{}] returns status {}, expected {}", new Object[] { ps.path, status, ps.status });
} else {
resultLog.debug("[{}] returns status {} as expected", ps.path, status);
}
checked++;
}
} catch (Exception e) {
resultLog.warn("Exception while executing request [{}]: {}", lastPath, e);
} finally {
if (resolver != null) {
resolver.close();
}
}
if (checked == 0) {
resultLog.warn("No paths checked, empty paths list?");
} else {
resultLog.info("{} paths checked, {} failures", checked, failed);
}
return new Result(resultLog);
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class DistributionQueueHealthCheck method execute.
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
Map<String, Integer> failures = new HashMap<String, Integer>();
if (distributionAgents.size() > 0) {
for (DistributionAgent distributionAgent : distributionAgents) {
for (String queueName : distributionAgent.getQueueNames()) {
try {
DistributionQueue q = distributionAgent.getQueue(queueName);
DistributionQueueEntry entry = q.getHead();
if (entry != null) {
DistributionQueueItemStatus status = entry.getStatus();
if (status.getAttempts() <= numberOfRetriesAllowed) {
resultLog.debug("Queue: [{}], first item: [{}], number of retries: {}", q.getName(), entry.getId(), status.getAttempts());
} else {
// the no. of attempts is higher than the configured threshold
resultLog.warn("Queue: [{}], first item: [{}], number of retries: {}, expected number of retries <= {}", q.getName(), entry.getId(), status.getAttempts(), numberOfRetriesAllowed);
failures.put(q.getName(), status.getAttempts());
}
} else {
resultLog.debug("No items in queue [{}]", q.getName());
}
} catch (Exception e) {
resultLog.warn("Exception while inspecting distribution queue [{}]: {}", queueName, e);
}
}
}
} else {
resultLog.debug("No distribution queue providers found");
}
if (failures.size() > 0) {
// a specific log entry (using markdown) to provide a recommended user action
for (Map.Entry<String, Integer> entry : failures.entrySet()) {
resultLog.warn("Distribution queue {}'s first item in the default queue has been retried {} times (threshold: {})", entry.getKey(), entry.getValue(), numberOfRetriesAllowed);
}
}
return new Result(resultLog);
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class OsgiInstallerHealthCheck method execute.
@Override
public Result execute() {
InstallationState installationState = infoProvider.getInstallationState();
FormattingResultLog hcLog = new FormattingResultLog();
int numCheckedConfigurations = 0;
int numCheckedBundles = 0;
// go through all resource groups of the OSGi Installer
for (final ResourceGroup group : installationState.getInstalledResources()) {
String type = evaluateGroup(group, hcLog);
switch(type) {
case InstallableResource.TYPE_CONFIG:
numCheckedConfigurations++;
break;
case InstallableResource.TYPE_BUNDLE:
numCheckedBundles++;
break;
}
}
hcLog.info("Checked {} OSGi bundles and {} configurations.", numCheckedBundles, numCheckedConfigurations);
if (hcLog.getAggregateStatus().ordinal() >= Result.Status.WARN.ordinal()) {
hcLog.info("Refer to the OSGi installer's documentation page at {} for further details on how to fix those issues.", DOCUMENTATION_URL);
}
return new Result(hcLog);
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class ScriptableHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
resultLog.debug("Checking expression [{}], language extension=[{}]", expression, languageExtension);
try {
final ScriptEngine engine = scriptEngineManager.getEngineByExtension(languageExtension);
if (engine == null) {
resultLog.healthCheckError("No ScriptEngine available for extension {}", languageExtension);
} else {
// Set Bindings, with our ResultLog as a binding first, so that other bindings can use it
final Bindings b = engine.createBindings();
b.put(FormattingResultLog.class.getName(), resultLog);
synchronized (bindingsValuesProviders) {
for (BindingsValuesProvider bvp : bindingsValuesProviders) {
log.debug("Adding Bindings provided by {}", bvp);
bvp.addBindings(b);
}
}
log.debug("All Bindings added: {}", b.keySet());
final Object value = engine.eval(expression, b);
if (value != null && "true".equals(value.toString().toLowerCase())) {
resultLog.debug("Expression [{}] evaluates to true as expected", expression);
} else {
resultLog.warn("Expression [{}] does not evaluate to true as expected, value=[{}]", expression, value);
}
}
} catch (final Exception e) {
resultLog.healthCheckError("Exception while evaluating expression [{}] with language extension [{}]: {}", expression, languageExtension, e);
}
return new Result(resultLog);
}
Aggregations