Htop for CPU and memory inspection


#1

Hello, how can I see the CPU/cores and memory use of the cloud instance? Normally I would run htop at the command line. It’s important to ensure my code is actually taking advantage of the instance specs as intended.


#2

I use psutil library in my code to check cpu and memory usage. Below there is some my sample code.

import psutil
import time
import threading
from deepsense import neptune

ctx = neptune.Context()

loop = True

def worker(ctx):
    while loop:
        ctx.channel_send('cpu', psutil.cpu_percent())
        ctx.channel_send('mem', psutil.virtual_memory().percent)
        time.sleep(1)
        
t = threading.Thread(target=worker, args=(ctx,))
t.start()


# Your code here
Run my magic code

# Kill cpu plot thread
loop = False

This code will create separate thread which will send channel values and create cpu/mem plot.


#3

Fantastic code snippet. Thank you!