My requirement is that in my POD multiple processes are running and I want to collect the metrices for all the processes i.e (CPU AND MEMORY and other details OF all Process). Now , I want to write the output of any command I run inside my pod to stout .
Asked
Active
Viewed 2,860 times
2
-
Hi beingumang, since not every container has linux 'top' program inside, do you mean that you want to write the same metrics as 'kubectl top' outputs? – mozello Mar 16 '22 at 17:54
-
I want to get the output of any command which I run inside my POD to stout. How can I do that ? I can run top inside my pod or anyother command , goal is to get the output of that command in stout . – beingumang Mar 21 '22 at 02:02
1 Answers
1
A container engine handles and redirects any output generated to a containerized application's
stdout
andstderr
streams. For example, the Docker container engine redirects those two streams to a logging driver, which is configured in Kubernetes to write to a file in JSON format.
Usually, it is PID1 process's stdout and stderr.
So, try the following command inside a k8s Pod:
$ cat /proc/meminfo >> /proc/1/fd/1
Then you will see the standard output in the pod's logs:
$ kubectl logs yourPodName
...
MemTotal: 12807408 kB
MemFree: 10283624 kB
MemAvailable: 11461168 kB
Buffers: 50996 kB
Cached: 1345376 kB
...
To write stdout
and stderr
from the command, run it like this:
$ cat /proc/meminfo 1>> /proc/1/fd/1 2>> /proc/1/fd/2

mozello
- 1,083
- 3
- 8