Monitoring PGD Proxy
====================

You cam monitor proxies at the cluster and group level or at the process
level.

Monitoring through the cluster
------------------------------

Using SQL
^^^^^^^^^

The current configuration of every group is visible in the `bdr.node_group_routing_config_summary <https://www.enterprisedb.com/docs/pgd/latest/reference/catalogs-internal#bdrnode_group_routing_config_summary>`_ 
view.

The `bdr.node_routing_config_summary <https://www.enterprisedb.com/docs/pgd/latest/reference/catalogs-internal#bdrnode_routing_config_summary>`_  view shows current per-node routing configuration.

 `bdr.proxy_config_summary <https://www.enterprisedb.com/docs/pgd/latest/reference/catalogs-internal#bdrproxy_config_summary>`_  shows per-proxy configuration.

Monitoring at the process level
-------------------------------

Proxy health check
^^^^^^^^^^^^^^^^^^

PGD Proxy provides the following HTTP(S) health check API endpoints. The
API endpoints respond to ``GET`` requests. You need to enable and
configure the endpoints before using them. See :ref:`Configuring health check <Configuring health check>`  .

.. csv-table::
  :header: Endpoint,Description
  :widths: 10,30
  :align: left
  :class: longtable

  `/health/is-ready`,Checks if the proxy can successfully route connections to the current write leader.
  `/health/is-live`,Checks if the proxy is running.
  `/health/is-write-ready`,Checks if the proxy can successfully route connections to the current write leader (PGD 5.5.0 and later).
  `/health/is-read-only-ready`,Checks if the proxy can successfully route read-only connections (PGD 5.5.0 and later).

Readiness
^^^^^^^^^

On receiving a valid ``GET`` request:

-  When in default (write) mode, the proxy checks if it can successfully
   route connections to the current write leader.

-  When in read-only mode, the proxy checks if it can successfully route
   read-only connections.

-  When in any mode, the proxy first checks if it can successfully route
   connections to the current write leader. If it can, the check is
   successful. If not, it checks if it can route a read-only connection.
   If it can, the check is successful. If not, the check fails.

If the check returns successfully, the API responds with a body
containing ``true`` and an HTTP status code ``200 (OK)`` . Otherwise, it
returns a body containing ``false`` with the HTTP status code
``500 (Internal Server Error)`` .

Liveness
^^^^^^^^

Liveness checks return either ``true`` with HTTP status code
``200 (OK)`` or an error. They never return ``false`` because the HTTP
server listening for the request is stopped if the PGD Proxy service
fails to start or exits.

Proxy log location
------------------

Proxies also write logs to system logging where they can be monitored
with other system services.

syslog
^^^^^^

-  Debian based - ``/var/log/syslog``

-  Red Hat based - ``/var/log/messages``

Use the ``journalctl`` command to filter and view logs for
troubleshooting PGD Proxy. The following are sample commands for quick
reference:

.. code:: sh

   journalctl -u pgd-proxy -n100 -f
   journalctl -u pgd-proxy --since today
   journalctl -u pgd-proxy --since "10 min ago"
   journalctl -u pgd-proxy --since "2022-10-20 16:21:50" --until "2022-10-20 16:21:55"
