3

I want to log, every 10 minutes, list of all the apps in Windows that are running, the CPU usage, and memory usage.

I have many node.exe tasks, so I want to see the arguments of the task (for example: node c:\myscript.js)

I tried: tasklist/? but didn't find anything related to CPU usage.

I tried: procexp/? but didn't find any way to export the list to file (or show in a console)

I tried: cprocess (NirSoft), it can dump to file, and show CPU, but it does not give the arguments of the exe that ran.

Any ideas?

2 Answers 2

1

Personally I would use Python and the lovely psutil library which can gather just about all of the information that you can dream of:

For a process on Windows you can get:

  • cpu_percent
  • cpu_times
  • io_counters
  • memory_info
  • memory_maps
  • num_ctx_switches
  • num_handles
  • num_threads
  • username
  • full exe path
  • cmdline
  • parent
  • status
  • cwd
  • io_counters
  • much more
  • even more on Linux & OSX

Some Python 3.5+ code to do more or less what you are asking for to the console, (the same can be done with earlier Pythons but not with the f-string):

import psutil
import time
import datetime

while True:
    print(datetime.datetime.now())
    for proc in psutil.process_iter():
        try:
            pr = proc.as_dict()
            print(f'{pr["name"]}\t{pr["memory_percent"]}\t{pr["cpu_percent"]}\t{pr["num_threads"]}\t{" ".join(pr["cmdline"][1:]) if pr["cmdline"] else ""}')
        except (OSError, psutil.AccessDenied):
            print(pr.name(), 'ACCESS DENIED')
    print('\n*** Ctrl-C to Exit ***\n\n')
    time.sleep(600) # Sleep for 10 Mins

On my machine the output looks like: enter image description here

You could simply pipe the output to a file or you could modify the code to output to a .csv file directly.

  • Free, Gratis & Open Source
  • Cross Platform
  • Flexible
1

You could do this simply with a batch file, here's something I quickly wrote up,

@echo off
ECHO ***Date and Time***
set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %datetimef%
ECHO ***List Processes***
WMIC path win32_process get Caption,Processid,Commandline
ECHO ***CPU-Usage***
wmic cpu get loadpercentage
ECHO ***Memory Usage***
systeminfo | findstr Memory

It's pretty simple, you can tweak it to fit your needs but this meets your requirements. I also see that you want this data exported to a file so you can, output the contents of the batch file like this, batch.bat > Logs-%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%.log

1
  • 1
    Link is broken FYI
    – airstrike
    Commented Apr 26, 2020 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.