Class: Recmon::ProcSensor

Inherits:
Sensor
  • Object
show all
Defined in:
lib/recmon/proc-sensor.rb

Overview

ProcSensor checks periodically to ensure a certain process is running

Instance Method Summary collapse

Methods inherited from Sensor

#check

Constructor Details

#initialize(name, pattern, freq = 60) ⇒ ProcSensor

Create a new ProcSensor. The pattern is a string as specified in pgrep(1).



9
10
11
12
# File 'lib/recmon/proc-sensor.rb', line 9

def initialize(name, pattern, freq=60)
  super(name, freq)
  @pattern = pattern
end

Instance Method Details

#senseObject

Called by Monitor. This method executes pgrep(1) to check if one or more processes match



16
17
18
19
20
# File 'lib/recmon/proc-sensor.rb', line 16

def sense()
  `/usr/bin/pgrep -f "#{@pattern}"`
  status = $?.success? ? "running" : "stopped"
  return("proc=#{@name} status=#{status}")
end