Approved

Live Discover Query - CPU Usage (Weighted)

  REVIEWED by Sophos 

Hi guys,

Been playing with live discover, which seems to be all I'm doing at the moment, it's a little addictive! Anyway wrote a simple query to collect the most active processes on devices. Unlike the cpu_time table, this query will work on Windows as well as Mac and Linux > So should be good for the entire estate!

 

SELECT
   p.name AS Name,
   p.pid AS ProcessID,
   p.uid,
   u.username AS Username,
   printf("%.2f", ((p.user_time + p.system_time) / (process_cpu_time.total_cpu_usage)) * 100) || "%" AS CPU_Percentage_Weighted
FROM
   processes p,
   (
    SELECT
      (SUM(user_time) + SUM(system_time) * 1.0) AS total_cpu_usage
    FROM
      processes
   ) AS process_cpu_time
JOIN
 users u
 ON
   p.uid = u.uid
ORDER BY p.user_time+p.system_time DESC
LIMIT "$$Number of Processes to Show$$";

 

There's a variable call $$Number of Processes to Show$$ which limits the top number of processes returned. I'd recommend something less than 10

Cheers all,
AM