Health Monitoring of Mule Applications
All APIs developed using Mule must be built with a health check endpoint. This template will help you maintain a uniform structure across all the APIs and their layers.
Join the DZone community and get the full member experience.
Join For FreeHealth check of an APIs allows near-real-time information about the state of your containers and APIs/microservices. It is critical to multiple aspects of operating APIs and is especially important when orchestrators perform partial application upgrades in phases. It also helps to determine if a running API instance is unable to handle requests.
The health check API operation performs a variety of internal metrics including:
- the status of the connections to the dependent system(s) used by the API instance.
- the resource utilization of the dependent system(s) (e.g., memory, CPU).
- the performance (e.g., average response time) of the dependent system(s).
- application-specific logic.
An API monitoring tool periodically invokes the endpoint to check the overall status of the API.
- Rules can be added at the monitoring layer to proactively identify potential errors:
- Resource exhaustion (e.g., memory, thread, connections, compute).
- Increasing dependent system response times or response payload sizes.
Logical View
Development View
Health check endpoint developed for each experience, process, and system API. Endpoint prepares the status of an API and also include the status of all the calling APIs and downstream system.
API Definition (RAML)
API
#%RAML 1.0
title: health-check-api
description: This API is used to check system's health
types:
HealthCheck: !include DataType/healthCheckDataType.raml
/healthCheck:
get:
description: get system health check data
responses:
200:
body:
application/json:
type: HealthCheck
example: !include Examples/healthCheckMultipleDependencyExample.raml
Data Type
xxxxxxxxxx
#%RAML 1.0 DataType
properties:
name?: string
status?:
type: string
enum: ['up', 'down', 'unknown']
xxxxxxxxxx
#%RAML 1.0 DataType
type: !include BasicHealthCheckDataType.raml
properties:
dependency?:
items: !include BasicHealthCheckDataType.raml
Example
x
#%RAML 1.0 NamedExample
{
name: "System",
status: "up",
dependency: [
{
name: "Database",
status: "up",
responseTimeAvg: "813",
connectionPoolSize: "100",
connectionInUse: "90",
connectionInUseAvg: "90"
}
]
}
Implementation:
There are two ways to implement this health check API.
- Add as a dependency in implementation API (System, Process, and Experience API) and build health check response by calling flow reference of health check API.
- Build health check API as Mule project and export as a jar file:
Add jar file in pom.xml file of implementation project as a dependency:
XML
x
1<dependency>
2<groupId>com.healthcheck</groupId>
3<artifactId>health-check-test-application</artifactId>
4<version>1.0.0</version>
5</dependency>
Import xml file:
- Prepare health response as health check API and call flow as flow ref.
- Implement health check API and data structure as per the above specification in each API.
Opinions expressed by DZone contributors are their own.
Comments