| ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot |
Application Performance Monitoring (APM)Since version 1.3, the MongoDB driver contains an API for performance monitoring. This API allows you to find out how long specific operations take by setting up subscribers. Each subscriber is required to implement one or more interfaces under the MongoDB\Driver\Monitoring namespace. Currently, only the MongoDB\Driver\Monitoring\CommandSubscriber interface is available.
The MongoDB\Driver\Monitoring\CommandSubscriber
interface defines three methods: commandStarted,
commandSucceeded, and commandFailed.
Each of these three methods accept a single In this tutorial we will implement a subscriber that creates a list of all the query profiles and the average time they took. Subscriber Class ScaffoldingWe start with the framework for our subscriber:
<?php Registering the SubscriberOnce a subscriber object is instantiated, it needs to be registered with the driver's monitoring system. This is done by calling MongoDB\Driver\Monitoring\addSubscriber().
<?php Implementing the LogicWith the object registered, the only thing left is to implement the logic in the subscriber class. To correlate the two events that make up a successfully executed command (commandStarted and commandSucceeded), each event object exposes a requestId field. To record the average time per query shape, we will start by checking for a find command in the commandStarted event. We will then add an item to the pendingCommands property indexed by its requestId and with its value representing the query shape. If we receive a corresponding commandSucceeded event with the same requestId, we add the duration of the event (from durationMicros) to the total time and increment the operation count. If a corresponding commandFailed event is encountered, we just remove the entry from the pendingCommands property.
<?php |
各種マニュアル:
PHPマニュアル |
PEARマニュアル |
Smarty(英語)マニュアル |
PHP-GTKマニュアル |
「Application Performance Monitoring (APM)」をGoogle検索
|