[Yandex Cloud documentation](../../index.md) > [Yandex StoreDoc](../index.md) > [Step-by-step guides](index.md) > Logs and monitoring > Performance analysis tools

# Performance analysis tools

## Built-in diagnostic tools {#monitoring-tools}

Yandex StoreDoc provides tools for collecting performance metrics:

* `mongostat`: Collects CPU and memory usage statistics for Yandex StoreDoc processes.
* `mongotop`: Collects read/write statistics for each collection.

When calling these utilities, use a database user account with the [mdbMonitor](../concepts/users-and-roles.md#mdbMonitor) role.

For example, to output performance metrics with a five-second polling interval, run one of the following commands:

```bash
mongostat 5 \
  --ssl \
  --host=<Yandex_StoreDoc_host_FQDN> \
  --port=27018 \
  --username=<username> \
  --authenticationDatabase=admin
```

```bash
mongotop 5 \
  --ssl \
  --host=<Yandex_StoreDoc_host_FQDN> \
  --port=27018 \
  --username=<username> \
  --authenticationDatabase=admin
```

To learn how to get a host FQDN, see [this guide](connect/index.md#get-fqdn).


### Profiler {#explore-profiler}

Yandex StoreDoc Includes a built-in profiler. That collects query data and uses it to generate a query optimization strategy. The profiler’s operation is controlled by the [Yandex StoreDoc settings](../concepts/settings-list.md), which you can configure when [creating a cluster](cluster-create.md) or [updating the DBMS settings](update.md#change-mongod-config):

* [operationProfiling.mode](../concepts/settings-list.md#setting-operation-profiling).
* [operationProfiling.slowOpThreshold](../concepts/settings-list.md#setting-slow-op-threshold).

{% note warning %}

Setting `operationProfiling.mode` to `all` and `operationProfiling.slowOpThreshold` to a value near `0` will severely degrade cluster performance.

{% endnote %}

To view the data collected by the profiler, refer to the `system.profile` collection in each database. To read profiler collections, a [user](cluster-users.md#adduser) must have the [`mdbMonitor`](../concepts/users-and-roles.md#mdbMonitor) role. By default, this data is duplicated in the logs.


### Currently running queries {#list-running-queries}

To view queries executed by other users, run `db.currentOp` under the [`mdbMonitor`](../concepts/users-and-roles.md#mdbMonitor) role:

```javascript
db.currentOp()
```

To view the current user's queries, run `db.currentOp()` with `ownOps` set to `true`:

```javascript
db.currentOp({ "$ownOps": true })
```

## Logs {#explore-logs}

The logs contain the most detailed information about Yandex StoreDoc operation.

{% list tabs group=instructions %}

- Management console {#console}

    1. Open the [folder dashboard](https://console.yandex.cloud).
    1. Navigate to **Yandex StoreDoc**.
    1. Click the name of your cluster and select the ![image](../../_assets/console-icons/receipt.svg) **Logs** tab.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To view **Yandex StoreDoc** logs:

    1. See the description of the CLI command for viewing logs:

        ```bash
        yc managed-mongodb cluster list-logs --help
        ```

    1. To retrieve all cluster logs, run this command:

        ```bash
        yc managed-mongodb cluster list-logs --id <cluster_ID>
        ```

        You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.ListLogs](../api-ref/Cluster/listLogs.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request GET \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>:logs' \
            --url-query serviceType=<service_type> \
            --url-query columnFilter=<column_list> \
            --url-query fromTime=<time_range_start> \
            --url-query toTime=<time_range_end>
        ```

        Where:

        * `serviceType`: Target service type for log retrieval:
        
          * `MONGOD`: Yandex StoreDoc operations log.
          * `AUDIT`: Audit log.

        * `columnFilter`: List of output columns:

          * `hostname`: Host name.
          * `component`: Type of component to log, Example: `HTTP-Session`.
          * `message`: Message output by the component.
          * `query_id`: Request ID.
          * `severity`: Logging level, e.g., `Debug`.
          * `thread`: ID of the thread involved in query handling.

          You can specify only one column in the `columnFilter` parameter. If you want to filter logs by more than one column, provide a list of the columns in several parameters.
        
            * `fromTime`: Left boundary of a time range in [RFC-3339](https://www.ietf.org/rfc/rfc3339.html) format, Example: `2006-01-02T15:04:05Z`.

            * `toTime`: End of the time range in the same format as `fromTime`.

        You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/Cluster/listLogs.md#yandex.cloud.mdb.mongodb.v1.ListClusterLogsResponse) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    1. Call the [ClusterService.ListLogs](../api-ref/grpc/Cluster/listLogs.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
          -format json \
          -import-path ~/cloudapi/ \
          -import-path ~/cloudapi/third_party/googleapis/ \
          -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/cluster_service.proto \
          -rpc-header "Authorization: Bearer $IAM_TOKEN" \
          -d '{
                "cluster_id": "<cluster_ID>",
                "service_type": "<service_type>",
                "column_filter": [
                  "<column_1>", "<column_2>", ..., "<column_N>"
                ],
                "from_time": "<time_range_start>",
                "to_time": "<time_range_end>"
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mongodb.v1.ClusterService.ListLogs
        ```

        Where:

        * `service_type`: Target service type for log retrieval:

          * `MONGOD`: Yandex StoreDoc operations log.
          * `AUDIT`: Audit log.

        * `column_filter`: List of output columns:

          * `hostname`: Host name.
          * `component`: Type of component to log, Example: `HTTP-Session`.
          * `message`: Message output by the component.
          * `query_id`: Request ID.
          * `severity`: Logging level, e.g., `Debug`.
          * `thread`: ID of the thread involved in query handling.

          You can specify more than one column in the `column_filter` parameter if you want to filter logs by multiple columns.

            * `from_time`: Left boundary of a time range in [RFC-3339](https://www.ietf.org/rfc/rfc3339.html) format, Example: `2006-01-02T15:04:05Z`.

            * `to_time`: End of the time range in the same format as `from_time`.

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/grpc/Cluster/listLogs.md#yandex.cloud.mdb.mongodb.v1.ListClusterLogsResponse) to make sure your request was successful.

{% endlist %}