Node Monitor v0.6.5

Show:

InspectProbe Class

Extends PollingProbe
Module: Probes

Inspect and manipulate variables on the monitored server.

This class monitors the variable specified by the key.

The key is evaluated to determine the variable to monitor, so it may be a complex key starting at global scope. If the key isn't specified, it monitors all variables in the global scope.

If the key points to an object of type Backbone.Model, this probe will update the value in real time, triggered on the change event. Otherwise it will update the value as it notices changes, while polling on the specified polling interval (default: 1 second).

Constructor

InspectProbe

(
  • [initParams]
  • model
)

Parameters:

  • [initParams] Object optional
    • Initialization parameters
    • [key=null] String optional

      A global variable name or expression

    • [depth=2] Integer optional

      If the key points to an object, this is the depth to traverse the object for changes. Default=2, or 1 if key='window'.

    • [pollInterval] Integer optional

      (from PollingProbe) Polling interval in milliseconds. Default: null

    • [cronPattern] String optional

      (from PollingProbe) Crontab syle polling pattern. Default once per second: "* * * * * *"

  • model Object
    • Monitor data model elements
    • value
      • The value of the element being inspected
    • isModel
      • Is the value a Backbone.Model?

Methods

_evaluate

(
  • expression
)
Mixed protected

Evaluate an expression, returning the raw results

Parameters:

  • expression String

    Expression to evaluate

Returns:

Mixed: value Returns the expression value

eval_control

(
  • expression
  • [depth=2]
)
Mixed

Evaluate an expression, returning the depth-limited results

Parameters:

  • expression String

    Expression to evaluate

  • [depth=2] Integer optional

    Depth of the object to return

Returns:

Mixed: value Returns the depth-limited value

initialize

(
  • attributes
  • options
)

Inherited from Probe:

Initialize the probe

This is called on the probe during construction. It contains the probe initialization attributes and an option to make probe construction asynchronous.

Probe implementations can defer the initial response to the monitor until the initial state is loaded. This allows the callback on Monitor.connect() to have the complete initial state of the probe when called.

If the initial probe state cannot be determined in initialize, it should set the options.asyncInit option to true, and call the options.callback(error) once the initial state is determined.

// Asynchronous initialization
options.asyncInit = true;
var callback = options.callback

If asyncInit is set to true, the callback must be called once the initial state of the probe is known (or in an error condition).

// Set the initial state, and call the callback
this.set(...);
callback(null);

See the initialize method of the FileProbe probe for an example. It defers returning the probe to the monitor until the initial file contents are loaded.

Parameters:

  • attributes Object

    Initial probe attributes sent in from the Monitor

  • options Object

    Initialization options

    • asyncInit Boolean

      Set this to TRUE if the initial probe state can't be known immediately.

    • callback Function(error)

      The callback to call if asyncInit is set to true. If an error is passed, the probe will not be used.

onControl

(
  • name
  • [params]
  • [callback]
)

Inherited from Probe:

Dispatch a control message to the appropriate control function.

This is called when the control() method of a monitor is called. The name determines the method name called on the probe.

The probe must implement a method with the name {name}_control(), and that method must accept two parameters - an input params and a callback. The callback must be called, passing an optional error and response object.

For example, if the probe supports a control with the name go, then all it needs to do is implement the go_control() method with the proper signature. See ping_control() for an example.

Parameters:

  • name String

    Name of the control message.

  • [params] Any optional

    Input parameters specific to the control message.

  • [callback] Function(error, response) optional

    Called to send the message (or error) response.

    • error (Any) An object describing an error (null if no errors)
    • response (Any) Response parameters specific to the control message.

ping_control

(
  • params
  • callback
)

Inherited from Probe:

Respond to a ping control sent from a monitor

Parameters:

  • params Object

    Input parameters (not used)

  • callback Function(error, response)

    Called to send the message (or error) response.

    • error (Any) An object describing an error
    • response (String) The string 'pong' is returned as the response

poll

()

Poll for changes in the evaluation

release

()

Inherited from Probe:

Release any resources consumed by this probe.

This can be implemented by derived classes that need to be informed when they are to be shut down.

Probes that listen to events should use this method to remove their event listeners.