docker build -t glances_demo .
docker run --rm glance_demo
Created
November 4, 2021 08:53
-
-
Save willirath/61339b8786b09365ee9533ca85972c77 to your computer and use it in GitHub Desktop.
glances_demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.10-buster | |
RUN pip install glances | |
RUN mkdir -p /app | |
COPY glances_demo.py /app/glances_demo.py | |
ENTRYPOINT [ "python", "/app/glances_demo.py" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def stream_glances_processlist(nmax=10): | |
glances_proc = subprocess.Popen( | |
["glances", "--stdout", "processlist"], stdout=subprocess.PIPE, shell=False, | |
) | |
for n in range(nmax): | |
output = glances_proc.stdout.readline() | |
if output == b"" and glances_proc.poll() is not None: | |
break | |
if output: | |
yield output.decode("utf-8").strip() | |
glances_proc.terminate() | |
list(map(print, stream_glances_processlist(nmax=3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment