Member-only story

Programming Exec into a Pod

MQ Prometheus Scraper for Queue Depth

Zhimin Wen
4 min readJun 7, 2020

I need to create a quick Prometheus scraper to mine the WebSphere MQ queue depth data. Instead of the full-blown exporter, I will simply exec into the MQ pod, running some MQSC command to get the queue depth without extra configuration against the MQ.

Creating a K8s client

Inspired by this paper, let’s create a package to get the K8s ClientSet (kubernetes.Interface) by determining the in-cluster or out-of-cluster automatically.

Create an exec package

Start with a struct,

type K8sExec struct {
ClientSet kubernetes.Interface
RestConfig *rest.Config
PodName string
ContainerName string
Namespace string
}

We can then define a function to create the pods/exec resource and return the output of the result.

func (k8s *K8sExec) Exec(command []string) ([]byte, []byte, error) {
req := k8s.ClientSet.CoreV1().RESTClient().Post()…

--

--

No responses yet