Skip to main content

HealthChecks

  • As you move your applications to cloud native and orchestrated platform, everything must be accessed via specific apis, the platforms control plane apis are used to manage the deployments while the application must be configured to expose healthcheck and metrics endpoint, with necessary information such as health status, uptime, and version etc.

  • This is very useful in case of using orchestrated platforms like Kubernetes or Openshift, where the healthcheck metrics are used to check and mark app failures and attempt restarts, graceful shutdowns and smooth transition of traffic.

  • Application Healthcheck must be available on /health or /actuator/health path.

caution

Failure to setup healthcheck endpoints that return status 200 when successful may lead to failure in app startup

Following Documentation will walk you through different pre-packaged healthcheck extensions for your app frameworks:

NodeJs

For NodeJS one of the most popular healthcheck library available is express-actuator. This middleware creates a series of endpoints to help you monitor and manage your application when it's pushed to production. It's useful when you run your application on kubernetes and you are in need of endpoints for readiness/liveness probe.

  • Installation
npm install --save express-actuator
  • Configuration Example
app.js
const actuator = require('express-actuator');
const app = express();
const port = 3000
const options = {
infoGitMode: 'full'
};
app.use(actuator(options));

app.get('/', (req, res) => {
res.send('Hello World!')
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

Java : Spring Boot

Spring Boot Actuator is a sub-project of Spring Boot. It adds several production grade services to your application with little effort on your part. Following is the basic configuration to get started with actuator in spring boot.

  • Add Dependency to pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  • Configure health endpoint to show details
# Show details of health endpoint
management.endpoint.health.show-details=always

References