[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Sharded PostgreSQL](../index.md) > [Step-by-step guides](index.md) > Cluster and host state monitoring

# Sharded PostgreSQL cluster and host state monitoring

Data on the cluster and host state is available in the [management console](https://console.yandex.cloud). You can view them on the **Monitoring** tab of the cluster management page or in [Yandex Monitoring](../../monitoring/concepts/index.md).

Diagnostic information about cluster states is presented as graphs.

Chart update rate:

* Standard hosts and hosts with an increased RAM to vCPU ratio (`memory-optimized`): 15 seconds.
* Hosts with a guaranteed vCPU share under 100% (`burstable`): 150 seconds.

{% note info %}

The most appropriate multiple units (MB, GB, and more) are automatically used in charts.

{% endnote %}

You can [configure alerts](#monitoring-integration) in Yandex Monitoring to receive notifications about cluster failures. In Yandex Monitoring, there are two alert thresholds: `Warning` and `Alarm`. If the specified threshold is exceeded, you will receive alerts via the configured [notification channels](../../monitoring/concepts/alerting.md#notification-channel).

## Cluster health state monitoring {#monitoring-cluster}

To view health details for a Managed Service for Sharded PostgreSQL cluster:

1. Navigate to **Yandex Managed Service for Sharded&nbsp;PostgreSQL**.

1. Click the cluster name and open the **Monitoring** tab.

1. To get started with Yandex Monitoring metrics, dashboards, or alerts, click **Open in Monium** in the top panel.

You will see the following charts:

* Under **Cluster**:

    * **SPQR is Alive, \[boolean\]**: Health status of [router hosts](../concepts/index.md#router).
    * **ETCD is Alive, \[boolean\]**: Health status of [coordinator hosts](../concepts/index.md#coordinator).
    * **Maximum CPU usage**: Peak processor core load.
    * **Average CPU usage**: Average processor core workload.
    * **Maximum memory usage**: Peak RAM usage (in bytes). At high loads, the value of the **Free space** metric decreases, while the others increase.

* **Sessions** → **Sessions count**: Number of active client connections to the router.

* **Connections** → **Backend connections count**: Number of active connections from the router to [shard](../concepts/index.md#shard) hosts.

* Under **Network**:

    * **Packets received/sent**: Network packet exchange rate, in packets per second.
    * **Network received/sent bytes**: Total amount of received and sent data, in bytes.

* Under **Time quantiles**:

    * **Router time quantiles, ms**: Execution time of client requests to each router at the quantiles set by the **Time Quantiles** [configuration](../concepts/settings-list.md).
    * **Shard time quantiles, ms**: Execution time of requests from the router to shard hosts at the quantiles set by the **Time Quantiles** configuration.

## Host state monitoring {#monitoring-hosts}

To view detailed information about the status of individual Managed Service for Sharded PostgreSQL hosts:

1. Navigate to **Yandex Managed Service for Sharded&nbsp;PostgreSQL**.
1. Click the cluster name and open the **Monitoring** → **Hosts** tab.
1. Click the line of the host in the list.

This page displays workload charts for an individual cluster host:

* **CPU usage**: Processor core workload. With increased workload, the **Idle** value drops.
* **Memory usage**: Use of RAM, in bytes. At high loads, the value of the **Free space** metric decreases, while the others increase.
* **Packets received/sent**: Network packet exchange rate, in packets per second.
* **Network received/sent bytes**: Total amount of received and sent data, in bytes.
* Under **Time quantiles**:
    * **Router time quantiles, ms**: Execution time of client requests to router at the quantiles set by the **Time Quantiles** [configuration](../concepts/settings-list.md).
    * **Shard time quantiles, ms**: Execution time of requests from the router to shard hosts at the quantiles set by the **Time Quantiles** configuration.


## Setting up alerts in Yandex Monitoring {#monitoring-integration}

To configure automatic monitoring of key cluster health metrics:

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), select the folder with the cluster for which you want to set up alerts.
    1. Navigate to ![image](../../_assets/console-icons/display-pulse.svg) **Monitoring**.
    1. Under **Service dashboards**, select:
        * **Managed Service for Sharded PostgreSQL — Cluster Overview** to configure cluster alerts.
        * **Managed Service for Sharded PostgreSQL — Host Overview** to set up host alerts.
    1. In the relevant chart, click ![options](../../_assets/console-icons/ellipsis.svg) and select **Create alert**.
    1. If the chart displays multiple metrics, select the data query for the relevant metric and click **Continue**. For more on the query language, see [this Yandex Monitoring guide](../../monitoring/concepts/querying.md).
    1. Set the `Alarm` and `Warning` alert thresholds.
    1. Click **Create alert**.

{% endlist %}

To have other cluster health indicators monitored automatically:

{% list tabs group=instructions %}

- Management console {#console}

    1. [Create an alert](../../monitoring/operations/alert/create-alert.md).
    1. Add a status metric.
    1. In the alert parameters, set the alert thresholds.

{% endlist %}

Recommended threshold values for selected metrics:

| Metric                                         |   Designation   | `Alarm` | `Warning` |
|-------------------------------------------------|:---------------:|:-----------------------------------------------------------------------:|:----------------------------------------------------------------------:|
| Number of healthy router hosts      | `spqr-is-alive` |                   `<number_of_router_hosts> - 2`                    |                   `<number_of_router_hosts> - 1`                   |
| Number of healthy coordinator hosts | `etcd-is-alive` |                 `<number_of_coordinator_hosts> - 2`                 |                `<number_of_coordinator_hosts> - 1`                 |


## Cluster health and status {#cluster-health-and-status}

The **State** of a cluster shows the health of its hosts, while the **Status** shows whether the cluster is started, stopped, or is at an intermediate stage.

To view cluster health and status:

1. Navigate to the folder dashboard and select **Yandex Managed Service for Sharded&nbsp;PostgreSQL**.
1. In the cluster row, hover over the indicator in the **Availability** column.

### Cluster health states {#cluster-health}

State | Description | Suggested actions
:--- | :--- | :---
**ALIVE** | Cluster is operating normally. | No action is required.
**DEGRADED** | Cluster is not running at its full capacity: the state of at least one of the hosts is other than `ALIVE`. | Run the diagnostics:<ul><li>Go to the **Hosts** tab and see which hosts are not working.</li><li>Go to the **Operations** tab and make sure all operations are completed.</li><li>Make sure the cluster is not under maintenance.</li></ul>If you cannot find the cause yourself, [contact support](https://center.yandex.cloud/support).
**DEAD** | The cluster is down: none of its hosts are running. | [Make a support request](https://center.yandex.cloud/support) stating the following:<ul><li>Cluster ID.</li><li>IDs of the last operations performed on it.</li><li>Time the cluster entered the `DEAD` state according to the [availability charts](#monitoring-cluster).</li></ul>
**UNKNOWN** | Cluster state is unknown. | [Make a support request](https://center.yandex.cloud/support) stating the following:<ul><li>Cluster ID.</li><li>IDs of the last operations performed on it.</li><li>Time the cluster entered the `UNKNOWN` state according to the [availability charts](#monitoring-cluster).</li></ul>

### Cluster statuses {#cluster-status}

Status | Description | Suggested actions
:--- | :--- | :---
**CREATING** | Preparing for the first start | Wait a while and get started. The time it takes to create a cluster depends on the host class.
**RUNNING** | The cluster is operating normally | No action is required.
**STOPPING** | The cluster is stopping | After a while, the cluster status will switch to `STOPPED` and the cluster will be disabled. No action is required.
**STOPPED** | The cluster is stopped | Start the cluster to get it running again.
**STARTING** | Starting the cluster that was stopped earlier | After a while, the cluster status will switch to `RUNNING`. Wait a while and get started.
**UPDATING** | Updating the cluster's configuration | Once the update is complete, the cluster will get the status it had prior to the update: `RUNNING` or `STOPPED`.
**ERROR** | Error when performing an operation with the cluster or during a maintenance window | If the cluster remains in this status for a long time, [contact support](https://center.yandex.cloud/support). You can see whether a cluster is available by its status.
**STATUS_UNKNOWN** | The cluster is unable to determine its status | If the cluster remains in this status for a long time, [contact support](https://center.yandex.cloud/support).