use of fish.payara.nucleus.healthcheck.configuration.MonitoredMetric in project Payara by payara.
the class SetHealthCheckServiceConfiguration method updateProperties.
private <C extends Checker> Checker updateProperties(Checker config, Class<C> type) throws PropertyVetoException, TransactionFailure {
if (enabled != null) {
updateProperty(config, "enabled", config.getEnabled(), enabled.toString(), Checker::setEnabled);
}
updateProperty(config, "checker-name", config.getName(), checkerName, Checker::setName);
updateProperty(config, "add-to-microprofile-health", config.getAddToMicroProfileHealth(), addToMicroProfileHealth.toString(), Checker::setAddToMicroProfileHealth);
updateProperty(config, "time", config.getTime(), time, Checker::setTime);
updateProperty(config, "time-unit", config.getUnit(), timeUnit, Checker::setUnit);
updateProperty(config, "checker-name", config.getName(), checkerName, Checker::setName);
if (HoggingThreadsChecker.class.isAssignableFrom(type)) {
HoggingThreadsChecker hoggingThreadsConfig = (HoggingThreadsChecker) config;
updateProperty(hoggingThreadsConfig, "hogging-threads-threshold", hoggingThreadsConfig.getThresholdPercentage(), hogginThreadsThreshold, HoggingThreadsChecker::setThresholdPercentage);
updateProperty(hoggingThreadsConfig, "hogging-threads-retry-count", hoggingThreadsConfig.getRetryCount(), hogginThreadsRetryCount, HoggingThreadsChecker::setRetryCount);
}
if (StuckThreadsChecker.class.isAssignableFrom(type)) {
StuckThreadsChecker stuckThreadsConfig = (StuckThreadsChecker) config;
updateProperty(stuckThreadsConfig, "stuck-threads-threshold", stuckThreadsConfig.getThreshold(), stuckThreadsThreshold, StuckThreadsChecker::setThreshold);
updateProperty(stuckThreadsConfig, "stuck-threads-threshold-unit", stuckThreadsConfig.getThresholdTimeUnit(), stuckThreadsThresholdUnit, StuckThreadsChecker::setThresholdTimeUnit);
}
if (MicroProfileMetricsChecker.class.isAssignableFrom(type)) {
MicroProfileMetricsChecker microProfileMetricsConfig = (MicroProfileMetricsChecker) config;
// This is required as the child resources is not created if the name is not set.
microProfileMetricsConfig.setName(config.getName());
List<MonitoredMetric> metrics = microProfileMetricsConfig.getMonitoredMetrics();
if (metricsToRemove != null && !metricsToRemove.isEmpty()) {
for (String metricToRemove : metricsToRemove) {
MonitoredMetric monitoredMetric = parseToMonitoredMetric(metricToRemove, microProfileMetricsConfig.createChild(MonitoredMetric.class));
boolean removed = false;
for (MonitoredMetric metric : metrics) {
if (metric.equals(monitoredMetric)) {
metrics.remove(metric);
report.appendMessage("Metric 'metricName=" + monitoredMetric.getMetricName() + "' successfully deleted." + "\n");
removed = true;
break;
}
}
if (!removed) {
report.appendMessage("Metric 'metricName=" + monitoredMetric.getMetricName() + "' doesn't exist, so was ignored." + "\n");
}
}
}
if (metricsToAdd != null && !metricsToAdd.isEmpty()) {
for (String metricToAdd : metricsToAdd) {
MonitoredMetric monitoredMetric = parseToMonitoredMetric(metricToAdd, microProfileMetricsConfig.createChild(MonitoredMetric.class));
boolean metricExists = false;
for (MonitoredMetric metric : metrics) {
if (metric.equals(monitoredMetric)) {
metricExists = true;
report.appendMessage("Metric 'metricName=" + monitoredMetric.getMetricName() + "' already exists, so was ignored." + "\n");
break;
}
}
if (!metricExists) {
metrics.add(monitoredMetric);
report.appendMessage("Metric 'metricName=" + monitoredMetric.getMetricName() + "' successfully added." + "\n");
}
}
}
}
return config;
}
use of fish.payara.nucleus.healthcheck.configuration.MonitoredMetric in project Payara by payara.
the class GetHealthCheckConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ActionReport mainActionReport = context.getActionReport();
// subReport(0)
ActionReport baseActionReport = mainActionReport.addSubActionsReport();
// subReport(1)
ActionReport hoggingThreadsActionReport = mainActionReport.addSubActionsReport();
// subReport(2)
ActionReport thresholdDiagnosticsActionReport = mainActionReport.addSubActionsReport();
// subReport(3)
ActionReport stuckThreadsActionReport = mainActionReport.addSubActionsReport();
// subReport(4)
ActionReport mpHealthcheckCheckerActionReport = mainActionReport.addSubActionsReport();
// subReport(5)
ActionReport microProfileMetricsActionReport = mainActionReport.addSubActionsReport();
// subReport(6)
ActionReport monitoredMicroProfileMetricsActionReport = mainActionReport.addSubActionsReport();
ColumnFormatter baseColumnFormatter = new ColumnFormatter(baseHeaders);
ColumnFormatter hoggingThreadsColumnFormatter = new ColumnFormatter(hoggingThreadsHeaders);
ColumnFormatter stuckThreadsColumnFormatter = new ColumnFormatter(stuckThreadsHeaders);
ColumnFormatter thresholdDiagnosticsColumnFormatter = new ColumnFormatter(thresholdDiagnosticsHeaders);
ColumnFormatter mpHealthCheckColumnFormatter = new ColumnFormatter(MPHealthCheckHeaders);
ColumnFormatter microProfileMetricsColumnFormatter = new ColumnFormatter(microProfileMetricsCheckHeaders);
ColumnFormatter monitoredMicroProfileMetricsColumnFormatter = new ColumnFormatter(monitoredMicroProfileMetricHeaders);
ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(notifierHeaders);
HealthCheckServiceConfiguration configuration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
List<ServiceHandle<BaseHealthCheck>> allServiceHandles = habitat.getAllServiceHandles(BaseHealthCheck.class);
List<ServiceHandle<PayaraNotifier>> allNotifierServiceHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
mainActionReport.appendMessage("Health Check Service Configuration is enabled?: " + configuration.getEnabled() + "\n");
if (Boolean.parseBoolean(configuration.getEnabled())) {
mainActionReport.appendMessage("Historical Tracing Enabled?: " + configuration.getHistoricalTraceEnabled() + "\n");
if (Boolean.parseBoolean(configuration.getHistoricalTraceEnabled())) {
mainActionReport.appendMessage("Historical Tracing Store Size: " + configuration.getHistoricalTraceStoreSize() + "\n");
}
if (StringUtils.ok(configuration.getHistoricalTraceStoreTimeout())) {
mainActionReport.appendMessage("Health Check Historical Tracing Store Timeout in Seconds: " + configuration.getHistoricalTraceStoreTimeout() + "\n");
}
}
// Create the extraProps map for the general healthcheck configuration
Properties mainExtraProps = new Properties();
Map<String, Object> mainExtraPropsMap = new HashMap<>();
mainExtraPropsMap.put("enabled", configuration.getEnabled());
mainExtraPropsMap.put("historicalTraceEnabled", configuration.getHistoricalTraceEnabled());
mainExtraPropsMap.put("historicalTraceStoreSize", configuration.getHistoricalTraceStoreSize());
mainExtraPropsMap.put("historicalTraceStoreTimeout", configuration.getHistoricalTraceStoreTimeout());
mainExtraProps.put("healthcheckConfiguration", mainExtraPropsMap);
mainActionReport.setExtraProperties(mainExtraProps);
final List<String> notifiers = configuration.getNotifierList();
if (!notifiers.isEmpty()) {
Properties extraProps = new Properties();
for (ServiceHandle<PayaraNotifier> serviceHandle : allNotifierServiceHandles) {
final String notifierClassName = serviceHandle.getActiveDescriptor().getImplementationClass().getSimpleName();
final String notifierName = NotifierUtils.getNotifierName(serviceHandle.getActiveDescriptor());
Object[] values = new Object[2];
values[0] = notifierName;
values[1] = notifiers.contains(notifierName);
notifiersColumnFormatter.addRow(values);
Map<String, Object> map = new HashMap<>(2);
map.put("notifierName", values[0]);
map.put("notifierEnabled", values[1]);
extraProps.put("notifierList" + notifierClassName, map);
}
mainActionReport.getExtraProperties().putAll(extraProps);
mainActionReport.appendMessage(notifiersColumnFormatter.toString());
mainActionReport.appendMessage(StringUtils.EOL);
}
mainActionReport.appendMessage("Below are the list of configuration details of each checker listed by its name.");
mainActionReport.appendMessage(StringUtils.EOL);
Properties baseExtraProps = new Properties();
Properties hoggingThreadsExtraProps = new Properties();
Properties stuckThreadsExtrasProps = new Properties();
Properties thresholdDiagnosticsExtraProps = new Properties();
Properties mpHealthcheckExtrasProps = new Properties();
Properties microProfileMetricsExtrasProps = new Properties();
Properties monitoredMicroProfileMetricsExtrasProps = new Properties();
for (ServiceHandle<BaseHealthCheck> serviceHandle : allServiceHandles) {
Checker checker = configuration.getCheckerByType(serviceHandle.getService().getCheckerType());
if (checker instanceof HoggingThreadsChecker) {
HoggingThreadsChecker hoggingThreadsChecker = (HoggingThreadsChecker) checker;
Object[] values = new Object[7];
values[0] = hoggingThreadsChecker.getName();
values[1] = hoggingThreadsChecker.getEnabled();
values[2] = hoggingThreadsChecker.getTime();
values[3] = hoggingThreadsChecker.getUnit();
values[4] = hoggingThreadsChecker.getAddToMicroProfileHealth();
values[5] = hoggingThreadsChecker.getThresholdPercentage();
values[6] = hoggingThreadsChecker.getRetryCount();
hoggingThreadsColumnFormatter.addRow(values);
// Create the extra props map for a hogging thread checker
addHoggingThreadsCheckerExtraProps(hoggingThreadsExtraProps, hoggingThreadsChecker);
} else if (checker instanceof ThresholdDiagnosticsChecker) {
ThresholdDiagnosticsChecker thresholdDiagnosticsChecker = (ThresholdDiagnosticsChecker) checker;
Object[] values = new Object[8];
values[0] = thresholdDiagnosticsChecker.getName();
values[1] = thresholdDiagnosticsChecker.getEnabled();
values[2] = thresholdDiagnosticsChecker.getTime();
values[3] = thresholdDiagnosticsChecker.getUnit();
values[4] = thresholdDiagnosticsChecker.getAddToMicroProfileHealth();
Property thresholdCriticalProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_CRITICAL);
values[5] = thresholdCriticalProperty != null ? thresholdCriticalProperty.getValue() : "-";
Property thresholdWarningProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_WARNING);
values[6] = thresholdWarningProperty != null ? thresholdWarningProperty.getValue() : "-";
Property thresholdGoodProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_GOOD);
values[7] = thresholdGoodProperty != null ? thresholdGoodProperty.getValue() : "-";
thresholdDiagnosticsColumnFormatter.addRow(values);
// Create the extra props map for a checker with thresholds
addThresholdDiagnosticsCheckerExtraProps(thresholdDiagnosticsExtraProps, thresholdDiagnosticsChecker);
} else if (checker instanceof StuckThreadsChecker) {
StuckThreadsChecker stuckThreadsChecker = (StuckThreadsChecker) checker;
Object[] values = new Object[7];
values[0] = stuckThreadsChecker.getName();
values[1] = stuckThreadsChecker.getEnabled();
values[2] = stuckThreadsChecker.getTime();
values[3] = stuckThreadsChecker.getUnit();
values[4] = stuckThreadsChecker.getAddToMicroProfileHealth();
values[5] = stuckThreadsChecker.getThreshold();
values[6] = stuckThreadsChecker.getThresholdTimeUnit();
stuckThreadsColumnFormatter.addRow(values);
addStuckThreadsCheckerExtrasProps(stuckThreadsExtrasProps, stuckThreadsChecker);
} else if (checker instanceof MicroProfileHealthCheckerConfiguration) {
MicroProfileHealthCheckerConfiguration mpHealthcheckChecker = (MicroProfileHealthCheckerConfiguration) checker;
Object[] values = new Object[6];
values[0] = mpHealthcheckChecker.getName();
values[1] = mpHealthcheckChecker.getEnabled();
values[2] = mpHealthcheckChecker.getTime();
values[3] = mpHealthcheckChecker.getUnit();
values[4] = mpHealthcheckChecker.getAddToMicroProfileHealth();
values[5] = mpHealthcheckChecker.getTimeout();
mpHealthCheckColumnFormatter.addRow(values);
addMPHealthcheckCheckerExtrasProps(mpHealthcheckExtrasProps, mpHealthcheckChecker);
} else if (checker instanceof MicroProfileMetricsChecker) {
MicroProfileMetricsChecker microProfileMetricsChecker = (MicroProfileMetricsChecker) checker;
Object[] values = new Object[5];
values[0] = microProfileMetricsChecker.getName();
values[1] = microProfileMetricsChecker.getEnabled();
values[2] = microProfileMetricsChecker.getTime();
values[3] = microProfileMetricsChecker.getUnit();
values[4] = microProfileMetricsChecker.getAddToMicroProfileHealth();
microProfileMetricsColumnFormatter.addRow(values);
addMicroProfileMetricsCheckerExtrasProps(microProfileMetricsExtrasProps, microProfileMetricsChecker);
Map<String, String> monitoredAttributes = new HashMap<>();
List<MonitoredMetric> metrics = microProfileMetricsChecker.getMonitoredMetrics();
if (!metrics.isEmpty()) {
for (MonitoredMetric monitoredBean : metrics) {
Object[] metricValues = new Object[2];
metricValues[0] = monitoredBean.getMetricName();
metricValues[1] = monitoredBean.getDescription();
monitoredMicroProfileMetricsColumnFormatter.addRow(metricValues);
monitoredAttributes.put("MetricsName", monitoredBean.getMetricName());
}
monitoredMicroProfileMetricsExtrasProps.put("monitoredMetrics", monitoredAttributes);
}
} else if (checker != null) {
Object[] values = new Object[5];
values[0] = checker.getName();
values[1] = checker.getEnabled();
values[2] = checker.getTime();
values[3] = checker.getUnit();
values[4] = checker.getAddToMicroProfileHealth();
baseColumnFormatter.addRow(values);
// Create the extra props map for a base checker
addBaseCheckerExtraProps(baseExtraProps, checker);
}
}
if (!baseColumnFormatter.getContent().isEmpty()) {
baseActionReport.setMessage(baseColumnFormatter.toString());
baseActionReport.appendMessage(StringUtils.EOL);
}
if (!hoggingThreadsColumnFormatter.getContent().isEmpty()) {
hoggingThreadsActionReport.setMessage(hoggingThreadsColumnFormatter.toString());
hoggingThreadsActionReport.appendMessage(StringUtils.EOL);
}
if (!thresholdDiagnosticsColumnFormatter.getContent().isEmpty()) {
thresholdDiagnosticsActionReport.setMessage(thresholdDiagnosticsColumnFormatter.toString());
thresholdDiagnosticsActionReport.appendMessage(StringUtils.EOL);
}
if (!stuckThreadsColumnFormatter.getContent().isEmpty()) {
stuckThreadsActionReport.setMessage(stuckThreadsColumnFormatter.toString());
stuckThreadsActionReport.appendMessage(StringUtils.EOL);
}
if (!mpHealthCheckColumnFormatter.getContent().isEmpty()) {
mpHealthcheckCheckerActionReport.setMessage(mpHealthCheckColumnFormatter.toString());
mpHealthcheckCheckerActionReport.appendMessage(StringUtils.EOL);
}
if (!microProfileMetricsColumnFormatter.getContent().isEmpty()) {
microProfileMetricsActionReport.setMessage(microProfileMetricsColumnFormatter.toString());
microProfileMetricsActionReport.appendMessage(StringUtils.EOL);
}
if (!monitoredMicroProfileMetricsColumnFormatter.getContent().isEmpty()) {
monitoredMicroProfileMetricsActionReport.setMessage(monitoredMicroProfileMetricsColumnFormatter.toString());
monitoredMicroProfileMetricsActionReport.appendMessage(StringUtils.EOL);
}
// Populate the extraProps with defaults for any checker that isn't present
baseExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, garbageCollectorPropertyName);
hoggingThreadsExtraProps = checkCheckerPropertyPresence(hoggingThreadsExtraProps, hoggingThreadsPropertyName);
stuckThreadsExtrasProps = checkCheckerPropertyPresence(stuckThreadsExtrasProps, stuckThreadsPropertyName);
thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, cpuUsagePropertyName);
thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, connectionPoolPropertyName);
thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, heapMemoryUsagePropertyName);
thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, machineMemoryUsagePropertyName);
mpHealthcheckExtrasProps = checkCheckerPropertyPresence(mpHealthcheckExtrasProps, mpHealthcheckPropertyName);
microProfileMetricsExtrasProps = checkCheckerPropertyPresence(microProfileMetricsExtrasProps, microProfileMetricsPropertyName);
// Add the extra props to their respective action reports
baseActionReport.setExtraProperties(baseExtraProps);
hoggingThreadsActionReport.setExtraProperties(hoggingThreadsExtraProps);
thresholdDiagnosticsActionReport.setExtraProperties(thresholdDiagnosticsExtraProps);
stuckThreadsActionReport.setExtraProperties(stuckThreadsExtrasProps);
mpHealthcheckCheckerActionReport.setExtraProperties(mpHealthcheckExtrasProps);
microProfileMetricsActionReport.setExtraProperties(microProfileMetricsExtrasProps);
monitoredMicroProfileMetricsActionReport.setExtraProperties(monitoredMicroProfileMetricsExtrasProps);
mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.nucleus.healthcheck.configuration.MonitoredMetric in project Payara by payara.
the class MicroProfileMetricsCheck method constructOptions.
@Override
public synchronized HealthCheckMicroProfileMetricstExecutionOptions constructOptions(MicroProfileMetricsChecker checker) {
Set<String> metricNames = new HashSet<>();
for (MonitoredMetric metric : checker.getMonitoredMetrics()) {
metricNames.add(metric.getMetricName());
}
this.buffer = new StringWriterProxy();
this.writer = new MetricsWriterImpl(new FilteredMetricsExporter(buffer, metricNames), metricsService.getContextNames(), metricsService::getContext);
return new HealthCheckMicroProfileMetricstExecutionOptions(Boolean.valueOf(checker.getEnabled()), Long.parseLong(checker.getTime()), asTimeUnit(checker.getUnit()), Boolean.valueOf(checker.getAddToMicroProfileHealth()), checker.getMonitoredMetrics());
}
use of fish.payara.nucleus.healthcheck.configuration.MonitoredMetric in project Payara by payara.
the class MicroProfileMetricsCheck method doCheckInternal.
@Override
protected HealthCheckResult doCheckInternal() {
List<MonitoredMetric> monitoredMetrics = options.getMonitoredMetrics();
HealthCheckResult result = new HealthCheckResult();
try {
if (monitoredMetrics != null && !monitoredMetrics.isEmpty()) {
final String data = write();
result.add(new HealthCheckResultEntry(data.isEmpty() ? WARNING : GOOD, data.isEmpty() ? "The metrics you have added for monitoring doesn't exist" : data));
} else {
result.add(new HealthCheckResultEntry(CRITICAL, "No metric has been added for monitoring."));
}
} catch (IOException ex) {
result.add(new HealthCheckResultEntry(CRITICAL, "Failed to write metrics to stream."));
}
return result;
}
Aggregations