Measuring the Actual Memory and CPU Consumption

In this lesson, we will figure out how to measure the actual memory and CPU consumption.

We'll cover the following

Exploring the Options

How did we come up with the current memory and CPU values? Why did we set the memory of the MongoDB to 100Mi? Why not 50Mi or 1Gi? It is embarrassing to admit that the values we have right now are random. We guessed that the containers based on the vfarcic/go-demo-2 image require less resources than Mongo database, so their values are comparatively smaller. That was the only criteria we used to define the resources.

Before you frown upon the decision to put random values for resources, you should know that we do not have any metrics to back us up. Anybody’s guess is as good as ours.

The only way to truly know how much memory and CPU an application uses is by retrieving metrics. We’ll use Heapster for that purpose.

Heapster collects and interprets various signals like compute resource usage, lifecycle events, etc. In our case, we’re interested only in CPU and memory consumption of the containers we’re running in our cluster.

When we created the cluster, we enabled the heapster addon and Minikube deployed it as a system application. Not only that, but it also deployed InfluxDB and Grafana. The former is the database where Heapster stores data and the latter can be used to visualize it through dashboards.

You might be inclined to think that Heapster, InfluxDB, and Grafana might be the solution for your monitoring needs. We advise against such a decision. We’re using Heapster only because it’s readily available as a Minikube addon.

The idea to develop Heapster as a tool for monitoring needs is mostly abandoned. Its primary focus is to serve as an internal tool required for some of the Kubernetes features.

We’d suggest a combination of Prometheus combined with the Kubernetes API as the source of metrics and Alertmanager for your alerting needs. However, those tools are not in the scope of this chapter, so you might need to educate yourself from their documentation, or wait until the sequel to this book is published (the tentative name is Advanced Kubernetes).

ℹ️ Use Heapster only as a quick-and-dirty way to retrieve metrics. Explore the combination of Prometheus and Alertmanager for your monitoring and alerting needs.

Now that we clarified what Heapster is good for, as well as what it isn’t, we can proceed and confirm that it is indeed running inside our cluster.

Get hands-on with 1200+ tech skills courses.