class MetricsHandler

Traits

Properties

protected PendingMetric> $metrics

The metrics being gathered.

protected Channel> $waiters

The waiters for metrics being gathered from sibling workers.

Methods

array
infoForChannels(Application $application, array $channels, string $info, bool $includeUserIds = false)

Get meta / status information for the given channels.

array
info(Application $application, string $channel, string $info, bool $includeUserIds = false)

Get meta / status information for the given channel.

bool
isPresenceChannel(Channel $channel)

Determine if the given channel is a presence channel.

bool
isCacheChannel(Channel $channel)

Determine if the given channel is a cache channel.

int
userCount(Channel $channel)

Get the number of unique users subscribed to the presence channel.

array
userIds(Channel $channel)

Get the unique user IDs subscribed to the presence channel.

__construct(ServerProviderManager $serverProviderManager, ChannelManager $channels, PubSubProvider $pubSubProvider, Server $server)

Create an instance of the metrics handler.

array
gather(Application $application, string $type, array $options = [])

Gather the metrics for the given type.

array
get(PendingMetric $metric)

Get the metrics for the given type.

array
getLocal(Application $application, MetricType $type, array $options)

Get the local metrics for the given type.

array
channel(Application $application, array $options)

Get the channel for the given application.

array
channels(Application $application, array $options)

Get the channels for the given application.

array
connections(Application $application)

Get the connections for the given application.

array
presence(Application $application, array $options)

Get a local presence-channel snapshot.

array
gatherMetricsFromSubscribers(PendingMetric $metric)

Gather metrics from all subscribers for the given type.

array
gatherMetricsFromWorkers(PendingMetric $metric, int $workerCount)

Gather metrics from this worker and every sibling worker.

void
receive(MetricsResponsePipeMessage $message)

Receive a metrics response from a sibling worker.

array
mergeSubscriberMetrics(array $metrics, MetricType $type)

Merge the given metrics into a single result set.

array
mergeChannel(array $metrics)

Merge multiple channel instances into a single set.

array
mergeChannels(array $metrics)

Merge multiple sets of channel instances into a single result set.

array
mergePresence(array $metrics)

Merge presence snapshots into one node-wide view.

void
publish(PendingMetric $metric)

Publish the metrics for the given type.

array
distributedOptions(MetricType $type, array $options)

Add distributed merge data when exact user counts were requested.

Channel
startGathering(PendingMetric $metric)

Register a pending metric and its waiter.

void
appendMetric(string $key, array $payload)

Append a response to a pending metric.

array
waitForMetric(PendingMetric $metric, Channel $waiter)

Wait for a pending metric or return every response received before the deadline.

void
stopGathering(PendingMetric $metric)

Remove a pending metric and its waiter.

Details

protected array infoForChannels(Application $application, array $channels, string $info, bool $includeUserIds = false)

Get meta / status information for the given channels.

Parameters

Application $application
array $channels
string $info
bool $includeUserIds

Return Value

array

protected array info(Application $application, string $channel, string $info, bool $includeUserIds = false)

Get meta / status information for the given channel.

Parameters

Application $application
string $channel
string $info
bool $includeUserIds

Return Value

array

protected bool isPresenceChannel(Channel $channel)

Determine if the given channel is a presence channel.

Parameters

Channel $channel

Return Value

bool

protected bool isCacheChannel(Channel $channel)

Determine if the given channel is a cache channel.

Parameters

Channel $channel

Return Value

bool

protected int userCount(Channel $channel)

Get the number of unique users subscribed to the presence channel.

Parameters

Channel $channel

Return Value

int

protected array userIds(Channel $channel)

Get the unique user IDs subscribed to the presence channel.

Parameters

Channel $channel

Return Value

array

at line 42
__construct(ServerProviderManager $serverProviderManager, ChannelManager $channels, PubSubProvider $pubSubProvider, Server $server)

Create an instance of the metrics handler.

Parameters

ServerProviderManager $serverProviderManager
ChannelManager $channels
PubSubProvider $pubSubProvider
Server $server

at line 53
array gather(Application $application, string $type, array $options = [])

Gather the metrics for the given type.

Parameters

Application $application
string $type
array $options

Return Value

array

at line 79
array get(PendingMetric $metric)

Get the metrics for the given type.

Parameters

PendingMetric $metric

Return Value

array

at line 87
protected array getLocal(Application $application, MetricType $type, array $options)

Get the local metrics for the given type.

Parameters

Application $application
MetricType $type
array $options

Return Value

array

at line 100
protected array channel(Application $application, array $options)

Get the channel for the given application.

Parameters

Application $application
array $options

Return Value

array

at line 113
protected array channels(Application $application, array $options)

Get the channels for the given application.

Parameters

Application $application
array $options

Return Value

array

at line 143
protected array connections(Application $application)

Get the connections for the given application.

Parameters

Application $application

Return Value

array

at line 151
protected array presence(Application $application, array $options)

Get a local presence-channel snapshot.

Parameters

Application $application
array $options

Return Value

array

at line 183
protected array gatherMetricsFromSubscribers(PendingMetric $metric)

Gather metrics from all subscribers for the given type.

Uses a Swoole coroutine channel with timeout instead of ReactPHP promises.

Parameters

PendingMetric $metric

Return Value

array

at line 231
protected array gatherMetricsFromWorkers(PendingMetric $metric, int $workerCount)

Gather metrics from this worker and every sibling worker.

Parameters

PendingMetric $metric
int $workerCount

Return Value

array

at line 279
void receive(MetricsResponsePipeMessage $message)

Receive a metrics response from a sibling worker.

Parameters

MetricsResponsePipeMessage $message

Return Value

void

at line 287
protected array mergeSubscriberMetrics(array $metrics, MetricType $type)

Merge the given metrics into a single result set.

Parameters

array $metrics
MetricType $type

Return Value

array

at line 302
protected array mergeChannel(array $metrics)

Merge multiple channel instances into a single set.

Parameters

array $metrics

Return Value

array

at line 328
protected array mergeChannels(array $metrics)

Merge multiple sets of channel instances into a single result set.

Parameters

array $metrics

Return Value

array

at line 347
protected array mergePresence(array $metrics)

Merge presence snapshots into one node-wide view.

Parameters

array $metrics

Return Value

array

at line 371
void publish(PendingMetric $metric)

Publish the metrics for the given type.

Called by the pub/sub message handler when this node receives a metrics request.

Parameters

PendingMetric $metric

Return Value

void

at line 382
protected array distributedOptions(MetricType $type, array $options)

Add distributed merge data when exact user counts were requested.

Parameters

MetricType $type
array $options

Return Value

array

at line 400
protected Channel startGathering(PendingMetric $metric)

Register a pending metric and its waiter.

Parameters

PendingMetric $metric

Return Value

Channel

at line 413
protected void appendMetric(string $key, array $payload)

Append a response to a pending metric.

Parameters

string $key
array $payload

Return Value

void

at line 432
protected array waitForMetric(PendingMetric $metric, Channel $waiter)

Wait for a pending metric or return every response received before the deadline.

Parameters

PendingMetric $metric
Channel $waiter

Return Value

array

at line 458
protected void stopGathering(PendingMetric $metric)

Remove a pending metric and its waiter.

Parameters

PendingMetric $metric

Return Value

void