crossbar.common.process

Attributes

Classes

ManholeService

Manhole service running inside a native processes (controller, router, container).

NativeProcess

A native Crossbar.io process (currently: controller, router or container).

Module Contents

class ManholeService(config, who)[source]

Bases: object

Manhole service running inside a native processes (controller, router, container).

This class is for _internal_ use within NativeProcess.

config[source]
created[source]
marshal()[source]

Marshal object information for use with WAMP calls/events.

Returns:

dict – The marshalled information.

port = None[source]
started = None[source]
status = 'starting'[source]
who[source]
class NativeProcess(config=None, reactor=None, personality=None)[source]

Bases: autobahn.twisted.wamp.ApplicationSession

A native Crossbar.io process (currently: controller, router or container).

WORKER_TYPE = 'native'[source]
_node_id[source]
_reactor = None[source]
_realm = None[source]
_uri_prefix[source]
_worker_id[source]
get_cpu_affinity(details=None)[source]

Get CPU affinity of this process.

Returns:

List of CPU IDs the process affinity is set to.

Return type:

list[int]

get_cpu_count(logical=True, details=None)[source]

Returns the CPU core count on the machine this process is running on.

Parameters:

logical (bool) – If enabled (default), include logical CPU cores (“Hyperthreading”), else only count physical CPU cores.

Returns:

The number of CPU cores.

Return type:

int

get_cpus(details=None)[source]
Returns:

List of CPU IDs.

Return type:

list[int]

get_manhole(details=None)[source]

Get current manhole service information.

Returns:

A dict with service information or None if the service is not running.

get_process_info(details=None)[source]

Get process information (open files, sockets, …).

Returns:

Dictionary with process information.

get_process_monitor(details=None)[source]
get_process_stats(details=None)[source]

Get process statistics (CPU, memory, I/O).

Returns:

Dictionary with process statistics.

log[source]
property node_id[source]
onConnect(do_join=True)[source]

Implements autobahn.wamp.interfaces.ISession.onConnect()

onJoin(details)[source]

Called when process has joined the node’s management realm.

onUserError(fail, msg)[source]

Implements autobahn.wamp.interfaces.ISession.onUserError()

set_cpu_affinity(cpus, relative=True, details=None)[source]

Set CPU affinity of this process.

Parameters:

cpus (list[int]) – List of CPU IDs to set process affinity to. Each CPU ID must be from the list [0 .. N_CPUs], where N_CPUs can be retrieved via crossbar.worker.<worker_id>.get_cpu_count.

Returns:

List of CPU IDs the process affinity is set to.

Return type:

list[int]

set_process_stats_monitoring(interval, details=None)[source]

Enable/disable periodic publication of process statistics.

Parameters:

interval (float) – The monitoring interval in seconds. Set to 0 to disable monitoring.

start_manhole(config, details=None)[source]

Start a Manhole service within this process.

Usage:

This procedure is registered under

  • crossbar.node.<node_id>.worker.<worker_id>.start_manhole - for native workers

  • crossbar.node.<node_id>.controller.start_manhole - for node controllers

The procedure takes a Manhole service configuration which defines a listening endpoint for the service and a list of users including passwords, e.g.

{
    "endpoint": {
        "type": "tcp",
        "port": 6022
    },
    "users": [
        {
            "user": "oberstet",
            "password": "secret"
        }
    ]
}

Errors:

The procedure may raise the following errors:

  • crossbar.error.invalid_configuration - the provided configuration is invalid

  • crossbar.error.already_started - the Manhole service is already running (or starting)

  • crossbar.error.feature_unavailable - the required support packages are not installed

Events:

The procedure will publish an event when the service is starting to

  • crossbar.node.<node_id>.worker.<worker_id>.on_manhole_starting - for native workers

  • crossbar.node.<node_id>.controller.on_manhole_starting - for node controllers

and publish an event when the service has started to

  • crossbar.node.<node_id>.worker.<worker_id>.on_manhole_started - for native workers

  • crossbar.node.<node_id>.controller.on_manhole_started - for node controllers

Parameters:

config (dict) – Manhole service configuration.

started(details=None)[source]

Return start time of this process.

Usage:

This procedure is registered under

  • crossbar.node.<node_id>.worker.<worker_id>.started for native workers and under

  • crossbar.node.<node_id>.controller.started for node controllers

Returns:

Start time (UTC) in UTC ISO 8601 format.

Return type:

str

stop_manhole(details=None)[source]

Stop the Manhole service running in this process.

This procedure is registered under

  • crossbar.node.<node_id>.worker.<worker_id>.stop_manhole for native workers and under

  • crossbar.node.<node_id>.controller.stop_manhole for node controllers

When no Manhole service is currently running within this process, or the Manhole service is already shutting down, a crossbar.error.not_started WAMP error is raised.

The procedure will publish an event when the service is stopping to

  • crossbar.node.<node_id>.worker.<worker_id>.on_manhole_stopping for native workers and

  • crossbar.node.<node_id>.controller.on_manhole_stopping for node controllers

and will publish an event when the service has stopped to

  • crossbar.node.<node_id>.worker.<worker_id>.on_manhole_stopped for native workers and

  • crossbar.node.<node_id>.controller.on_manhole_stopped for node controllers

trigger_gc(details=None)[source]

Manually trigger a garbage collection in this native process.

This procedure is registered under crossbar.node.<node_id>.worker.<worker_id>.trigger_gc for native workers and under crossbar.node.<node_id>.controller.trigger_gc for node controllers.

The procedure will publish an event when the garabage collection has finished to crossbar.node.<node_id>.worker.<worker_id>.on_gc_finished for native workers and crossbar.node.<node_id>.controller.on_gc_finished for node controllers:

{
    "requester": {
        "session_id": 982734923,
        "auth_id": "bob",
        "auth_role": "admin"
    },
    "duration": 190
}

Note

The caller of this procedure will NOT receive the event.

Returns:

Time (wall clock) consumed for garbage collection in ms.

Return type:

int

uptime(details=None)[source]

Return uptime of this process.

Usage:

This procedure is registered under

  • crossbar.node.<node_id>.worker.<worker_id>.uptime for native workers and under

  • crossbar.node.<node_id>.controller.uptime for node controllers

Returns:

Uptime in seconds.

Return type:

float

utcnow(details=None)[source]

Return current time as determined from within this process.

Usage:

This procedure is registered under

  • crossbar.node.<node_id>.worker.<worker_id>.utcnow for native workers and under

  • crossbar.node.<node_id>.controller.utcnow for node controllers

Returns:

Current time (UTC) in UTC ISO 8601 format.

Return type:

str

property worker_id[source]
_HAS_MANHOLE = False[source]