0

I am looking for a program to write average CPU utilization and average memory utilization of the entire machine every couple of seconds or the past few seconds into a file. Is there any out of the box software which does this or can I make use of a command?

1 Answer 1

0
#!/bin/bash
while true
do
  mem=$(free | grep Mem | awk '{print $4/$2 * 100}');
  cpu=$(top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.2f\n", prefix, 100 - v }');
  sleep 10s;
  echo "${cpu},${mem}" >> log.csv;
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .