With all the convenience Kubernetes operators provide in managing resources, it can still be a challenge to conveniently store, query, manage, and download the database logs from the pods. Since the pod logs are rotated after a certain period or size depending on the configuration and workload, it’s necessary to collect them to analyze for debugging and troubleshooting purposes. And who knows and feels the pain better than a DBA?

To collect pod logs locally, we usually do two things; set up Grafana Loki as a data source in Percona Monitoring and Management (PMM) and LogCLI. While it may sound like just two components to set up and deploy, it’s not easy for someone with limited Kubernetes expertise. The integration of Loki as the data source part is well demonstrated by my colleagues in the blog Store and Manage Logs of Percona Operator Pods with PMM and Grafana Loki; this blog post will focus on LogCLI configuration to query MongoDB pod logs.

CLI Installation instructions can be found here

Once installation is completed, we’ll now proceed with the remaining steps.

Finding the respective Loki pod that will allow you to query MongoDB pod logs, assuming you follow the initial Grafana Loki deployment

The Objects that we are interested in are, “loki-stack-0” and service “loki-stack”.

We now need to forward the port default “3100” of “loki-stack-0” to our local machine where we have installed “Logcli”.

Next is to export the LOKI_ADDR environment variable which will be used by Logcli to query the logs.

We can now finally query or download the logs from any of the MongoDB deployment pods.

The above command can be adjusted based on our requirements so I’ve shown pretty basic flags to download the logs for a particular timeframe. More can be found with “logcli –help” or using this cheatsheet.

Similarly, let’s say I want to query a particular MongoDB pod to look for a COLLSCAN log line against the “demo” collection, run the below command,

Hence, based on our usage, we can adjust the commands and get the desired results. This includes querying for different labels like a particular “pod” or a different “container” inside a pod like “pmm-client” or “backup-agent” for PMM and Percona Backup for MongoDB debugging.

I hope you enjoyed this blog. Happy querying!!

Reference: Turbocharging Percona Monitoring and Management With Loki’s Log-shipping Functionality

 

Get started with Percona Operator for MongoDB

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments