Skip to content

Instantly share code, notes, and snippets.

@willirath
Created November 4, 2021 08:53
Show Gist options
  • Save willirath/61339b8786b09365ee9533ca85972c77 to your computer and use it in GitHub Desktop.
Save willirath/61339b8786b09365ee9533ca85972c77 to your computer and use it in GitHub Desktop.
glances_demo
docker build -t glances_demo .
docker run --rm glance_demo
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" ]
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