Configuring System::ProcWatch by XML is the preferred way. It is as simple
Ruleset: The Root Element
The root element of an XML configuration file/string is the
procwatch element. It has one implicit attribute,
the version attribute, set to "1.0".
The procwatch element symbolizes our ruleset,
and the childs of the root are our rules.
Rules: The Childs of the Root
The direct descendants of the root element procwatch,
are the watch elements, which can occur 1 time or
The watch element has one required attribute, the
name attribute, which gives the watch (or job, rule)
a descriptive name like "httpd-count".
Each watch element symbolizes a single rule,
containing a regular expression to search for, one or more conditions to
evaluate and one or more actions to be taken.
A rule consists of three child elements:
Rule Element: pattern
The pattern element describes the perl compatible
regular expression which should be evaluated against a column of the
output of ps.
There is one required attribute, the match attribute,
defining the column name of the output of ps in
lowercase like "command" or "vsz".
This makes System::ProcWatch highliy versatile and should make it
usable with any platforms procps program.
The pattern elements content solely consits of
the perl compatible regular expression to match against the column
defined in the match attribute. The PCRE MUST
contain the start and end delimiter and MAY contain any PCRE modifiers.
Example: <pattern match="command">/sbin\/httpd/</pattern>
Rule Element: condition
The condition element defines conditions that
MUST evaluate to TRUE at all so that later defined actions will
The condition element has one required and one
optional attribute, the required one being type,
which MUST be one of "presence" or "attr", and
the optional one being attr. However, if the
type attribute equals to "attr" the
attr attribute MUST be present.
The attr attribute represents a column of
procps' output like "user" or "%mem".
Dependent on the content of the type attribute,
syntax and behavior of the condition element differ.
A condition with type
"presence" MAY be empty, thus always evaluating to true.
Child Elements of condition may be:
Found value MUST exceed defined value.
Found value MUST NOT exceed defined value.
Found value MUST be equal to defined value.
Found value MUST NOT be equal to defined value.
The sum of found values MUST NOT exceed defined sum.
You may combine them to define for instance a range from min to max.
Rule Element: execute
The execute element defines actions that should be
taken if the condition applies.
It has one required attribute, the type attribute,
which MUST equal to one of "shell" or "php".
Obviously the content of the execute element
is executed either on the shell through shell_exec()
or directly in PHP through eval().
The execute element MAY occur any times.
There are some special variables that will automagically be available
in execute statements:
This contains a general message, what has happened.
It is quoted in single quotes for save usage and
is available in shell and php executes.
This contains all PIDs of the processes that have been
found. They are enclosed by single quotes and parenthesis.
Example: '(433, 444, 455, 466)'
This is a serialized php array in string format
containing all information gained from ps and looks like:
array(array('pid' => 344, 'command' => '/usr/sbin/httpd' ...))
It is only available in php executes and can easily be
used in function callbacks: