BryanKMorrow

UIM: Using an Auto-Operator profile to gather process usage from a robot alarm

Blog Post created by BryanKMorrow Employee on Jun 8, 2015

The following is a LUA script that can be ran in an AO profile to gather process usage at the time of an alarm's arrival. For this to work the robot in question must have the processes probe running. Once the script has completed you will have an alarm note and an alarm annotation with the CPU and Memory usage of any process using more than 0% CPU. The reason both a note and an annotation are created is so the script supports both IM and USM alarming. Attached you will find screenshots of the alarm note and the generic AO configuration I used.

 

Currently there may be some formatting issues with the UMP Annotations, if anyone has suggestions on a better format for the java.exe processes I am all ears.

 

Please feel free to post questions or suggestions for improvement as well.

 

--Open connection to NIS database for new USM Alarm annotations
database.open("provider=nis;database=nis;driver=none")


-- get nimid (for notename), hostname (robotname)
alist = alarm.get()
if alist == nil then
   note_name = "TESTNOTE" -- running stand alone
   processes = "processes"
else
   note_name = "processes-"..alist.nimid
   processes = "/"..alist.domain.."/"..alist.hub.."/"..alist.robot.."/processes"
end


note_id = note.find (note_name)
if note_id == nil then
   note_id = note.create (note_name,"Initial Create at " ..timestamp.format(),1)
end


if alist ~= nil then
   note.attach (note_id,alist.nimid)
end


note.append (note_id," ")
note.append (note_id,"***Process information from "..processes.." added at "..timestamp.format())


--
-- Get the process-list from the processes probe, show all cpu-consuming processes
--
plist = nimbus.request(processes,"list_processes")


if plist == nil then
   printf ("The 'processes' probe does not run on the robot '%s'.",processes)
   note.append (note_id,"Probe "..processes.." does not run ")
else
   buff = ""
   for pid,proc in pairs(plist) do
      if proc.cpu_usage == nil then
         printf ("Executable pid:%05d cpu value is non-existent !!!!",proc.process_id)
      elseif proc.cpu_usage > 0 then
         if proc.short_executable == "java.exe" then
            printf ("Executable pid:%05d, cpu: %0.2f%% mem: %d MB - %s (%s)",proc.process_id,proc.cpu_usage,proc.working_set_size/1024,proc.short_executable,proc.command_line)
            process = string.format("%s cpu: %0.2f%% mem: %dMB (%s)",proc.short_executable,proc.cpu_usage,proc.working_set_size/1024,proc.command_line)
            buff = buff .. process .. " "
            print (process)
            note.append(note_id,process)
         elseif proc.short_executable ~= "Idle" then
            printf ("Executable pid:%05d, cpu: %0.2f%% mem: %d MB - %s (%s) ",proc.process_id,proc.cpu_usage,proc.working_set_size/1024,proc.short_executable,proc.executable)
            process = string.format("%s cpu: %0.2f%% mem: %dMB (%s) ",proc.short_executable,proc.cpu_usage,proc.working_set_size/1024,proc.executable)
            buff = buff .. process .. " "
            print (process)
            note.append(note_id,process)
         end
      end
   end
   query = string.format("INSERT INTO umpAlarmAnnotations (nimid,created,username,annotation) VALUES ('%s','%s','nas','%s')",alist.nimid,os.date("%c", timestamp.now()),buff)
   database.query(query)
end

Attachments

Outcomes