Paola explains what is a Health Monitoring app and the importance of implementing these checks for your applications. She demonstrates how to create a monitoring library in a Mule application (from scratch!) and how to install it to get it up and ready.
Cómo generar e implementar monitoreo para aplicaciones de Mule
1. May 26th, 2021
¿Cómo generar e implementar
monitoreo para aplicaciones de
Mule?
Paola Alcantar Valdes
2. 2
● About me
● What is a Health Monitoring
● Importance of implementing a Health Monitoring
● Health Monitoring application objectives
● Application metricts to watch
● Building a basic Health Monitoring for Mule Application
● How to implement a Health Monitoring Library in a Mule Application
● DEMO – Basic Health Monitoring for Mule Application
● Questions
Agenda
3. 3
●Paola Alcantar Valdes
○ Jr. Integration Engineer with Mulesoft at Twitter
○ Mulesoft Certified Developer – Level 1 (Mule 4)
○ Over two years of experience as a Managed Services
About me
5. 5
● What is a Health Monitoring?
○ It is an application that continually checks the status of an integration that is running.
● Differences between Application Health Monitoring and Application Health Checks:
○ Application Health Monitoring:
○ It is a good practice that allows collecting key metrics about different aspects of an application to
watch how it's working over time.
○ Application Health Checks:
○ Definition of “healthy” parameters based on regular checks information to ensure the system is
working the way it’s expected to.
○ Based on a business logic criteria, this should not be just “black“ or “white“
Health Monitoring
6. 6
● Importance of implementing a Health Monitoring:
○ It allows you to detect issues before they become complete outages. It will help you to detect
incidents before they affect customers.
○ Building and implementing a health monitoring application will help you create an action plan if an
incident does pop up.
○ A health monitoring application will allow helping you to understand better the behavior of
applications, servers, external systems. Also, to close visibility and performance gaps, correct
processes, and ensure you're getting total value from your applications.
Health Monitoring
8. 8
● There is no single way to build health monitoring for your applications. It is why different IT
teams will have different perspectives about the thing you need to care about. However, a
basic and useful health monitoring application might consider the following aspects.
○ Application’s general information: Get application name, application version, application environment,
mule runtime version, etc.
○ Memory Information: Get Heap Memory, Non-Heap Memory, Garbage Collection information from JVM.
○ Thread information: Return the number of demon threads, non-demon threads, and peak threads.
○ Overall availability (External systems): Retrieve the status of the external system with which the
application interacts (Know if external systems are up-and-running or not).
Health Monitoring application objectives
10. 10
● Memory Information :
Health Monitoring application objectives
public static void heapMemoryDetails() {
MemoryMXBean memBean = ManagementFactory.getMemoryMXBean() ;
MemoryUsage heapMemoryUsage = memBean.getHeapMemoryUsage();
long heapInitSize = heapMemoryUsage.getInit();
long heapUsedSize = heapMemoryUsage.getUsed();
long heapCommitedSize = heapMemoryUsage.getCommitted();
long heapMaxSize = heapMemoryUsage.getMax();
}
11. 11
● Garbage Collection Information :
Health Monitoring application objectives
public static ArrayList<GarbageCollection> garbageCollection(){
ArrayList<GarbageCollectorMXBean> memBean =
(ArrayList<GarbageCollectorMXBean>)
ManagementFactory.getGarbageCollectorMXBeans();
ArrayList<GarbageCollection> gc = new
ArrayList<GarbageCollection>();
for (GarbageCollectorMXBean garbageCollectorMXBean : memBean)
{
gc.add(new
GarbageCollection(garbageCollectorMXBean.getName(),
garbageCollectorMXBean.getCollectionCount(),
garbageCollectorMXBean.getCollectionTime()));
}
return gc;
}
12. 12
● Thread information :
Health Monitoring application objectives
public static void threadInformation() {
int demonThreads =
ManagementFactory.getThreadMXBean().getDaemonThreadCount();
int peakThreads =
ManagementFactory.getThreadMXBean().getPeakThreadCount();
int threadCount =
ManagementFactory.getThreadMXBean().getThreadCount();
long startedThreadCount =
ManagementFactory.getThreadMXBean().getTotalStartedThreadCount();
}
14. 14
1. Create a Mule 4 application.
2. Update the pom.xml file to define the “classifier” of the mule application as a “mule-plugin”.
3. Define the endpoints for the health monitoring library in a RAML Definition file. For example:
○ /health/application
○ /health/server
○ /health/thirdParty
○ /health/general
Walkthrough: How to build a Health Monitoring for
Mule Applications
See Health Monitoring RAML Definition
File
15. 15
4. Define the response for each endpoint.
5. Generate Flows based on RAML Definition file.
6. Remove auto-generated HTTP Configuration.
7. Set “config-ref” value on HTTP Listener Configuration with “${health.http.config}”
Walkthrough: How to build a Health Monitoring for
Mule Applications
See Health Monitoring application
objectives
Note: Value of “health.http.config” property will be defined in each mule
application that implements health monitoring library.
16. 16
8. Get objective keys related to each endpoint.
9. Generate dataweave scripts to format endpoint responses. For example:
10. Install our health monitoring plugin into a repository using command mvn clean install.
11. Implement health monitoring library following next steps.
Walkthrough: How to build a Health Monitoring for
Mule Applications
See Health Monitoring RAML Definition
File
%dw 2.0
output application/json
---
{
apiName: app.name,
apiVersion: p("apiVersion") default "",
env: p("env") default "",
runtimeVersion: mule.version,
startDate: ((app.muleContext.startDate default now()) as DateTime {unit: "milliseconds"}),
timeZone: server.timeZone,
traceId: correlationId,
}
17. How to implement a Health
Monitoring Library in a Mule
Application
18. Walkthrough: How to implement a Health
Monitoring Library
1. Add the Health Monitoring library dependency to our mule application pom.xml file.
2. Import into our mule application the mule configuration files from the library.
3. Define the following properties into our mule application. The thirdPartyFlows property is
optional and does not need to be defined.
18
19. Walkthrough to implement the Health Monitoring
Library
4. Optional. Define subflows that will be used to ´ping´ external systems.
19
Important: The subflows are in charge of calling external systems
to validate that service is up and running. Those subflows are
defined in our mule application, and they are called from the
health monitoring library through the property “thirdPartyFlows”.
20. DEMO – Basic Health Monitoring
of Mule Application