#!/bin/sh
LC_ALL=C

ps -eo pid=,user=,comm=,%cpu=,%mem=,rss=,vsz= --sort=-rss | head -n 10 | awk '
function esc(s) {
  gsub(/\\/, "\\\\", s)
  gsub(/ /, "\\ ", s)
  gsub(/,/, "\\,", s)
  gsub(/=/, "\\=", s)
  return s
}
{
  pid=$1
  user=$2
  comm=$3
  cpu=$4
  mem=$5
  rss=$6
  vsz=$7

  printf "process_top,user=%s,comm=%s pid=%si,cpu=%s,mem=%s,rss=%si,vsz=%si\n", esc(user), esc(comm), pid, cpu, mem, rss, vsz
}'
