Software AG Products 10.11 | Running Business Processes and Composite Applications | Administering My webMethods Server | Startup and Configuration | Using My webMethods Server with Docker | Monitoring My webMethods Server Containers | Implementing Custom Health Indicators | Container Health Check Samples
 
Container Health Check Samples
Example: healthCheck.json
Create a healthCheck.json file using the following example and include your custom health indicator together with the default indicators. The configuration that you specify with a healthCheck.json file overrides all health check indicator settings. Changes that you make to the healthCheck.json file apply when starting or restarting the container.
{
"enabled": "true",
"indicators": {
"MemoryHealthIndicator": {
"enabled": "true",
"properties": {
"memoryAvailable": 20
}
},
"JettyThreadHealthIndicator": {
"enabled": "true",
"properties": {
"currentToMaxThreadRatioThreshold": 20
}
},
"DiskspaceHealthIndicator": {
"enabled": "true",
"properties": {
"diskSpaceAvailable": 20
}
},
"DatabaseConnectivityHealthIndicator": {
"enabled": "true"
},
"AXSRFTGenerationHealthIndicator": {
"enabled": "true"
},
"CustomDataSourceHealthIndicator": {
"enabled": "true"
},
"DirServiceConnectivityHealthIndicator": {
"enabled": "true"
},
"ProcessEngineConnectivityHealthIndicator": {
"enabled": "true"
},
"RulesEngineConnectivityHealthIndicator": {
"enabled": "true"
},
"UmConnectionHealthIndicator": {
"enabled": "true"
}
"MyFavIndicatorConfig" : {
"enabled": "true",
"properties": {
"myIndicatorProperty": "propValue"
}
}
}
where MyFavIndicatorConfig is the name of your custom health check class, and myIndicatorProperty is a custom configuration property, defined in your code. Add an entry in the healthCheck.json file for each indicator property you define in the code.
Example: MyCustomIndicatorConfig.java
A sample class that defines the configuration properties of a custom health indicator for My webMethods Server containers. This class is required to map the configuration, supplied through the healthCheck.json file and transfer it to the My webMethods Server runtime.
package caf.war.TestHealthIndicators.healthtest;

import java.util.Map;
import java.util.Optional;

import com.webmethods.portal.system.init.InitializationException;
import com.webmethods.rtl.container.health.IHealthIndicatorConfig;

public class MyFavIndicatorConfig implements IHealthIndicatorConfig {

private boolean enabled;

private Map<String, Object> properties;

@Override
public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public Map<String, Object> getProperties() {
return this.properties;
}

// Implement for all custom properties, listed in healthCheck.json
private String myIndicatorValue;

// Implement for all custom properties, listed in healthCheck.json
public String getMyIndicatorValue() {
return this.myIndicatorValue;
}

public void setProperties(Map<String, Object> properties) throws InitializationException {
// Modify according to your specific data types
this.myIndicatorValue = getConfigProperty("myIndicatorValue", String.class);
}

protected <T extends Object> T getConfigProperty(String key, Class<T> returnType) throws InitializationException {
Object result = Optional.ofNullable(this.properties.get(key));
return returnType.cast(result);
}
}
Example: MyCustomIndicator.java
A sample class that creates a custom health indicator for My webMethods Server containers.
package caf.war.TestHealthIndicators.healthtest;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.webmethods.rtl.container.health.IHealthIndicator;

public class MyFavIndicator implements IHealthIndicator<MyFavIndicatorConfig> {

private MyFavIndicatorConfig config;

private Class<MyFavIndicatorConfig> configClass;

@Override
public void configure(JsonNode configNode) throws Exception {
if (configNode != null) {
this.config = new ObjectMapper().treeToValue(configNode, this.configClass);
}
}

@Override
public MyFavIndicatorConfig getConfiguration() {
return this.config;
}

// Define custom indicator values and measurement logic
@Override
public Health health() {
// Determine healthStatus using the options in the HealthStatus enum in
// IHealthIndicator, or define custom health statuses.
// Include additional health check code here.
// ...

return Health.status(new Status(HealthStatus.STATUS_OK.getKey())).build();
}

}