Fix context "deadline exceeded error" in Prometheus Operator

After installing Prometheus Operator on Kubernetes cluster, node exporter runs on each cluster nodes to report metrics about the node. However, in the targets UI of Prometheus, I can only see one node exporter is UP, all other node exporters are failing with context deadline exceeded error. The only node exporter that works is running on the same node as Prometheus itself. So it’s network issue that blocks the communication between node exporters and Prometheus itself.

Read More

Collect Kubernetes Resource Usage Metrics in Prometheus

Starting from Kubernetes 1.8, resource usage metrics, such as container CPU and memory usage, are available in Kubernetes through the Metrics API. With Metrics Server installed in Kubernetes cluster, you can access the API to get the metrics. Metrics API doesn’t store metric values, you need to use tools like Prometheus to store metrics data. This post uses Prometheus Operator to install and configure Prometheus. Please refer to Monitor Spring Boot Apps using Prometheus on Kubernetes for installation and configuration of Prometheus Operator.

Read More

Get random elements from lists

Sometimes we may need to get a number of random elements from lists. To do this, we can use a function to get the indices of these elements first.

The function getIndices takes two parameters: num is the number of elements to get, max is the maximum value of index.

Read More

Fixing Spring Boot error 'Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean'

I was building a new Spring WebFlux application with Spring Boot. After downloading the project template from, I added some third-party dependencies and tried to start the application. Then I met the error org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. Actually this is a common issue when I searched the solution. All the solutions are related to missing dependencies of Spring Boot starter spring-boot-starter-web.

Read More

Use Private NPM Registry and Packages

When building large-scale NodeJS and front-end projects, it’s necessary to use private NPM registry to share private packages across different projects and team members. This post shows the essential parts of how to build the infrastructure and set up the workflow to use them.

Read More

Apache Cassandra in Docker with JMX enabled

It’s a bit tricky to enable JMX for Cassandra when running in Docker. I create a Cassandra Docker image alexcheng/cassandra of version 3.11.2 with JMX authentication enabled, see the Dockerfile. The username and password to access JMX are both cassandra. The environment variable JMX_HOST has the default value of localhost, and it should work most of the time. If localhost doesn’t work , you can use the host’s IP address. After starting the container, you can access JMX using VisualVM or JConsole with address service:jmx:rmi://localhost/jndi/rmi://localhost:7199/jmxrmi. Change localhost to the same value as JMX_HOST if localhost is not used. Since SSL is not enabled, you need to use insecure connections.

On Mac, the local IP address can be obtained using ipconfig getifaddr en0, so we can use following command to start the container when using IP address is required.

docker run --rm -p 7199:7199 -e "JMX_HOST=`ipconfig getifaddr en0`" alexcheng/cassandra

Read More