My webMethods Server 10.7 | My webMethods Server Webhelp | 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"
},
"MyFavIndicator" : {
"enabled": "true",
"properties": {
"myIndicatorProperty": "propValue"
}
}
}
}
where MyFavIndicator 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: MyFavIndicatorConfig.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.CustomHealthIndicatorProj.customhealthindicatorportlet;

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

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;
}

public void setProperties(Map<String, Object> properties) {
this.properties = properties;
// Modify according to your specific data types
this.myIndicatorProperty = getConfigProperty("myIndicatorProperty", String.class); //$NON-NLS-1$
}

protected <T extends Object> T getConfigProperty(String key, Class<T> returnType) {
return Optional.ofNullable(this.properties.get(key)).map(returnType::cast).orElse(null);
}

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

// Implement for all custom properties, listed in healthCheck.json
public String getMyIndicatorProperty() {
return this.myIndicatorProperty;
}
}
Example: MyFavIndicator.java
A sample class that creates a custom health indicator for My webMethods Server containers.
package caf.war.CustomHealthIndicatorProj.customhealthindicatorportlet;

import java.util.HashMap;
import java.util.Map;

import org.osgi.service.component.annotations.Component;
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;

@Component(
service = {
IHealthIndicator.class
},
property = {
"name:String=myfavindicator",
"service.ranking:Integer=1"
}
)
public class MyFavIndicator implements IHealthIndicator<MyFavIndicatorConfig> {

private MyFavIndicatorConfig config;

private Class<MyFavIndicatorConfig> configClass;

public MyFavIndicator() {
this.configClass = MyFavIndicatorConfig.class;
}

@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;
}

// Implement custom indicator properties and their values
@Override
public Health health() {
Map<String, Object> details = new HashMap<>();
if (config != null) {
details.put("myProp is", config.getMyIndicatorProperty()); //$NON-NLS-1$
}
return Health.status(new Status(HealthStatus.STATUS_OK.getKey())).withDetail(getName(), details).build();
}
}