def do_GET_metrics(self) -> None:
        """Handle a ``GET`` request to ``/metrics`` path.

        Write an HTTP response with plain text content in the format used by Prometheus, with HTTP status ``200``.

        The response contains the following items:

            * ``patroni_version``: Patroni version without periods, e.g. ``030002`` for Patroni ``3.0.2``;
            * ``patroni_postgres_running``: ``1`` if PostgreSQL is running, else ``0``;
            * ``patroni_postmaster_start_time``: epoch timestamp since Postmaster was started;
            * ``patroni_primary``: ``1`` if this node holds the leader lock, else ``0``;
            * ``patroni_xlog_location``: ``pg_wal_lsn_diff(pg_current_wal_flush_lsn(), '0/0')`` if leader, else ``0``;
            * ``patroni_standby_leader``: ``1`` if standby leader node, else ``0``;
            * ``patroni_replica``: ``1`` if a replica, else ``0``;
            * ``patroni_sync_standby``: ``1`` if a sync replica, else ``0``;
            * ``patroni_quorum_standby``: ``1`` if a quorum sync replica, else ``0``;
            * ``patroni_xlog_received_location``: ``pg_wal_lsn_diff(pg_last_wal_receive_lsn(), '0/0')``;
            * ``patroni_xlog_replayed_location``: ``pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '0/0)``;
            * ``patroni_xlog_replayed_timestamp``: ``pg_last_xact_replay_timestamp``;
            * ``patroni_xlog_paused``: ``pg_is_wal_replay_paused()``;
            * ``patroni_postgres_server_version``: Postgres version without periods, e.g. ``150002`` for Postgres
              ``15.2``;
            * ``patroni_cluster_unlocked``: ``1`` if no one holds the leader lock, else ``0``;
            * ``patroni_failsafe_mode_is_active``: ``1`` if ``failsafe_mode`` is currently active, else ``0``;
            * ``patroni_postgres_timeline``: PostgreSQL timeline based on current WAL file name;
            * ``patroni_dcs_last_seen``: epoch timestamp when DCS was last contacted successfully;
            * ``patroni_pending_restart``: ``1`` if this PostgreSQL node is pending a restart, else ``0``;
            * ``patroni_is_paused``: ``1`` if Patroni is in maintenance node, else ``0``.

        For PostgreSQL v9.6+ the response will also have the following:

            * ``patroni_postgres_streaming``: 1 if Postgres is streaming from another node, else ``0``;
            * ``patroni_postgres_in_archive_recovery``: ``1`` if Postgres isn't streaming and
              there is ``restore_command`` available, else ``0``.
        """
        postgres = self.get_postgresql_status(True)
        patroni = self.server.patroni
        epoch = datetime.datetime(1970, 1, 1, tzinfo=tzutc)

        metrics: List[str] = []

        labels = f'{{scope="{patroni.postgresql.scope}",name="{patroni.postgresql.name}"}}'
        metrics.append("# HELP patroni_version Patroni semver without periods.")
        metrics.append("# TYPE patroni_version gauge")
        padded_semver = ''.join([x.zfill(2) for x in patroni.version.split('.')])  # 2.0.2 => 020002
        metrics.append("patroni_version{0} {1}".format(labels, padded_semver))

        metrics.append("# HELP patroni_postgres_running Value is 1 if Postgres is running, 0 otherwise.")
        metrics.append("# TYPE patroni_postgres_running gauge")
        metrics.append("patroni_postgres_running{0} {1}".format(
            labels, int(postgres['state'] == PostgresqlState.RUNNING)))

        metrics.append("# HELP patroni_postmaster_start_time Epoch seconds since Postgres started.")
        metrics.append("# TYPE patroni_postmaster_start_time gauge")
        postmaster_start_time = postgres.get('postmaster_start_time')
        postmaster_start_time = (postmaster_start_time - epoch).total_seconds() if postmaster_start_time else 0
        metrics.append("patroni_postmaster_start_time{0} {1}".format(labels, postmaster_start_time))

        metrics.append("# HELP patroni_primary Value is 1 if this node is the leader, 0 otherwise.")
        metrics.append("# TYPE patroni_primary gauge")
        metrics.append("patroni_primary{0} {1}".format(labels, int(postgres['role'] == PostgresqlRole.PRIMARY)))

        metrics.append("# HELP patroni_xlog_location Current location of the Postgres"
                       " transaction log, 0 if this node is not the leader.")
        metrics.append("# TYPE patroni_xlog_location counter")
        metrics.append("patroni_xlog_location{0} {1}".format(labels, postgres.get('xlog', {}).get('location', 0)))

        metrics.append("# HELP patroni_standby_leader Value is 1 if this node is the standby_leader, 0 otherwise.")
        metrics.append("# TYPE patroni_standby_leader gauge")
        metrics.append("patroni_standby_leader{0} {1}".format(labels,
                                                              int(postgres['role'] == PostgresqlRole.STANDBY_LEADER)))

        metrics.append("# HELP patroni_replica Value is 1 if this node is a replica, 0 otherwise.")
        metrics.append("# TYPE patroni_replica gauge")
        metrics.append("patroni_replica{0} {1}".format(labels, int(postgres['role'] == PostgresqlRole.REPLICA)))

        metrics.append("# HELP patroni_sync_standby Value is 1 if this node is a sync standby, 0 otherwise.")
        metrics.append("# TYPE patroni_sync_standby gauge")
        metrics.append("patroni_sync_standby{0} {1}".format(labels, int(postgres.get('sync_standby', False))))

        metrics.append("# HELP patroni_quorum_standby Value is 1 if this node is a quorum standby, 0 otherwise.")
        metrics.append("# TYPE patroni_quorum_standby gauge")
        metrics.append("patroni_quorum_standby{0} {1}".format(labels, int(postgres.get('quorum_standby', False))))

        metrics.append("# HELP patroni_xlog_received_location Current location of the received"
                       " Postgres transaction log, 0 if this node is not a replica.")
        metrics.append("# TYPE patroni_xlog_received_location counter")
        metrics.append("patroni_xlog_received_location{0} {1}"
                       .format(labels, postgres.get('xlog', {}).get('received_location', 0)))

        metrics.append("# HELP patroni_xlog_replayed_location Current location of the replayed"
                       " Postgres transaction log, 0 if this node is not a replica.")
        metrics.append("# TYPE patroni_xlog_replayed_location counter")
        metrics.append("patroni_xlog_replayed_location{0} {1}"
                       .format(labels, postgres.get('xlog', {}).get('replayed_location', 0)))

        metrics.append("# HELP patroni_xlog_replayed_timestamp Current timestamp of the replayed"
                       " Postgres transaction log, 0 if null.")
        metrics.append("# TYPE patroni_xlog_replayed_timestamp gauge")
        replayed_timestamp = postgres.get('xlog', {}).get('replayed_timestamp')
        replayed_timestamp = (replayed_timestamp - epoch).total_seconds() if replayed_timestamp else 0
        metrics.append("patroni_xlog_replayed_timestamp{0} {1}".format(labels, replayed_timestamp))

        metrics.append("# HELP patroni_xlog_paused Value is 1 if the Postgres xlog is paused, 0 otherwise.")
        metrics.append("# TYPE patroni_xlog_paused gauge")
        metrics.append("patroni_xlog_paused{0} {1}"
                       .format(labels, int(postgres.get('xlog', {}).get('paused', False) is True)))

        if postgres.get('server_version', 0) >= 90600:
            metrics.append("# HELP patroni_postgres_streaming Value is 1 if Postgres is streaming, 0 otherwise.")
            metrics.append("# TYPE patroni_postgres_streaming gauge")
            metrics.append("patroni_postgres_streaming{0} {1}"
                           .format(labels, int(postgres.get('replication_state') == 'streaming')))

            metrics.append("# HELP patroni_postgres_in_archive_recovery Value is 1"
                           " if Postgres is replicating from archive, 0 otherwise.")
            metrics.append("# TYPE patroni_postgres_in_archive_recovery gauge")
            metrics.append("patroni_postgres_in_archive_recovery{0} {1}"
                           .format(labels, int(postgres.get('replication_state') == 'in archive recovery')))

        metrics.append("# HELP patroni_postgres_server_version Version of Postgres (if running), 0 otherwise.")
        metrics.append("# TYPE patroni_postgres_server_version gauge")
        metrics.append("patroni_postgres_server_version {0} {1}".format(labels, postgres.get('server_version', 0)))

        metrics.append("# HELP patroni_cluster_unlocked Value is 1 if the cluster is unlocked, 0 if locked.")
        metrics.append("# TYPE patroni_cluster_unlocked gauge")
        metrics.append("patroni_cluster_unlocked{0} {1}".format(labels, int(postgres.get('cluster_unlocked', 0))))

        metrics.append("# HELP patroni_failsafe_mode_is_active Value is 1 if failsafe mode is active, 0 if inactive.")
        metrics.append("# TYPE patroni_failsafe_mode_is_active gauge")
        metrics.append("patroni_failsafe_mode_is_active{0} {1}"
                       .format(labels, int(postgres.get('failsafe_mode_is_active', 0))))

        metrics.append("# HELP patroni_postgres_timeline Postgres timeline of this node (if running), 0 otherwise.")
        metrics.append("# TYPE patroni_postgres_timeline counter")
        metrics.append("patroni_postgres_timeline{0} {1}".format(labels, postgres.get('timeline') or 0))

        metrics.append("# HELP patroni_dcs_last_seen Epoch timestamp when DCS was last contacted successfully"
                       " by Patroni.")
        metrics.append("# TYPE patroni_dcs_last_seen gauge")
        metrics.append("patroni_dcs_last_seen{0} {1}".format(labels, postgres.get('dcs_last_seen', 0)))

        metrics.append("# HELP patroni_pending_restart Value is 1 if the node needs a restart, 0 otherwise.")
        metrics.append("# TYPE patroni_pending_restart gauge")
        metrics.append("patroni_pending_restart{0} {1}"
                       .format(labels, int(bool(patroni.postgresql.pending_restart_reason))))

        metrics.append("# HELP patroni_is_paused Value is 1 if auto failover is disabled, 0 otherwise.")
        metrics.append("# TYPE patroni_is_paused gauge")
        metrics.append("patroni_is_paused{0} {1}".format(labels, int(postgres.get('pause', 0))))

        self.write_response(200, '\n'.join(metrics) + '\n', content_type='text/plain')
Handle a ``GET`` request to ``/metrics`` path.

        Write an HTTP response with plain text content in the format used by Prometheus, with HTTP status ``200``.

        The response contains the following items:

            * ``patroni_version``: Patroni version without periods, e.g. ``030002`` for Patroni ``3.0.2``;
            * ``patroni_postgres_running``: ``1`` if PostgreSQL is running, else ``0``;
            * ``patroni_postmaster_start_time``: epoch timestamp since Postmaster was started;
            * ``patroni_primary``: ``1`` if this node holds the leader lock, else ``0``;
            * ``patroni_xlog_location``: ``pg_wal_lsn_diff(pg_current_wal_flush_lsn(), '0/0')`` if leader, else ``0``;
            * ``patroni_standby_leader``: ``1`` if standby leader node, else ``0``;
            * ``patroni_replica``: ``1`` if a replica, else ``0``;
            * ``patroni_sync_standby``: ``1`` if a sync replica, else ``0``;
            * ``patroni_quorum_standby``: ``1`` if a quorum sync replica, else ``0``;
            * ``patroni_xlog_received_location``: ``pg_wal_lsn_diff(pg_last_wal_receive_lsn(), '0/0')``;
            * ``patroni_xlog_replayed_location``: ``pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '0/0)``;
            * ``patroni_xlog_replayed_timestamp``: ``pg_last_xact_replay_timestamp``;
            * ``patroni_xlog_paused``: ``pg_is_wal_replay_paused()``;
            * ``patroni_postgres_server_version``: Postgres version without periods, e.g. ``150002`` for Postgres
              ``15.2``;
            * ``patroni_cluster_unlocked``: ``1`` if no one holds the leader lock, else ``0``;
            * ``patroni_failsafe_mode_is_active``: ``1`` if ``failsafe_mode`` is currently active, else ``0``;
            * ``patroni_postgres_timeline``: PostgreSQL timeline based on current WAL file name;
            * ``patroni_dcs_last_seen``: epoch timestamp when DCS was last contacted successfully;
            * ``patroni_pending_restart``: ``1`` if this PostgreSQL node is pending a restart, else ``0``;
            * ``patroni_is_paused``: ``1`` if Patroni is in maintenance node, else ``0``.

        For PostgreSQL v9.6+ the response will also have the following:

            * ``patroni_postgres_streaming``: 1 if Postgres is streaming from another node, else ``0``;
            * ``patroni_postgres_in_archive_recovery``: ``1`` if Postgres isn't streaming and
              there is ``restore_command`` available, else ``0``.
        
patroni/api.py