Using the MySQL Proxy

Page last updated:

Warning: Pivotal Cloud Foundry (PCF) v2.3 is no longer supported because it has reached the End of General Support (EOGS) phase as defined by the Support Lifecycle Policy. To stay up to date with the latest software and security updates, upgrade to a supported version.

Warning: Pivotal Cloud Foundry (PCF) v2.3 is no longer supported because it has reached the End of General Support (EOGS) phase. To stay up to date with the latest software and security updates, upgrade to a supported version.

This topic describes how to use the MySQL proxy to monitor the health of your MySQL instance.

If you cannot write or connect to your app, you should check the health status of your MySQL VMs. You can observe the health status of MySQL VMs through a proxy using the Switchboard dashboard or API endpoint. You can also view the number of client connections routed through a proxy to each VM.

PCF uses a proxy to send client connections to the healthy MySQL database cluster nodes in a highly available cluster plan. Using a proxy gracefully handles failure of nodes, enabling fast, failover to other nodes within the cluster. When a node becomes unhealthy, the proxy closes all connections to the unhealthy node and re-routes all subsequent connections to a healthy node.

The proxy used in PCF is Switchboard. Switchboard was developed to replace HAProxy as the proxy tier for the high availability cluster for MySQL databases in PCF.

Switchboard offers the following features:

  • MySQL Server Access

    MySQL clients communicate with nodes through this network port. These connections are automatically passed through to the nodes.

  • Switchboard and API

    Operators can connect to Switchboard to view the state of the nodes.

Node Health

When determining where to route traffic, the proxy queries an HTTP healthcheck process running on the node. This healthcheck can return as either healthy or unhealthy, or the node can be unresponsive.

Healthy

If the healthcheck process returns HTTP status code 200, the proxy includes the node in its pool of healthy nodes.

When a new or resurrected nodes rejoin the cluster, the proxy continues to route all connections to the currently active node. In the case of failover, the proxy considers all healthy nodes as candidates for new connections.

Switchboard all healthy

Unhealthy

If the healthcheck returns HTTP status code 503, the proxy considers the node unhealthy.

This happens when a node becomes non-primary. For more information, see Cluster Scaling Behavior.

The proxy severs existing connections to newly unhealthy node. The proxy routes new connections to a healthy node, assuming such a node exists. Clients are expected to handle reconnecting on connection failure should the entire cluster become inaccessible.

Switchboard unhealthy

Unresponsive

If node health cannot be determined due to an unreachable or unresponsive healthcheck endpoint, the proxy considers the node unhealthy. This may happen if there is a network partition or if the VM running the node and healthcheck died.

Monitor Node Health

You can monitor the health status of your nodes by doing one of the following:

Monitor Node Health Using the Dashboard

Construct the URL for the Dashboard

Each MySQL Proxy instance has its own Switchboard dashboard. To access the dashboard, you must construct the dashboard URL.

To construct the URL for the Switchboard dashboard, do the following:

  1. Find and record the system domain on the Domains pane in the tile.

  2. Find and record the number of MySQL Proxy VM instances in your deployment in the Resource Config pane.

  3. Use the above information to build the Switchboard dashboard URL as follows: https://[PROXY-VM-INDEX]-proxy-p-mysql-ert.[SYSTEM-DOMAIN]

Log In to the Dashboard

To log into the Switchboard dashboard, do the following:

  1. In the PAS tile, the URL in your browser contains the Ops Manager fully qualified domain name (FQDN) and the PAS product GUID, as in the following example: https://OPS-MANAGER-FQDN/products/APPLICTION-SERVICE-PRODUCT-GUID/az_and_network_assignments/edit
    To log into the dashboard, you need the username and password for the MySQL Proxy VM that are stored in the BOSH Director CredHub.
    To obtain them, enter https://[OPS-MANAGER-FQDN]/api/v0/deployed/products/[APPLICTION-SERVICE-PRODUCT-GUID]/variables?name=mysql-proxy-dashboard-credentials into your browser and record the username and password.

  2. Enter the dashboard URL you constructed into your browser and log in using the credentials you obtained in Construct the URL for the Dashboard.

Use the Dashboard

To monitor node health using the Switchboard dashboard, do the following:

  1. To view a list of proxies in your browser, navigate to the URL that you created in Construct the URL for the Dashboard.

  2. When prompted, enter the username and password that you recorded in Log In to the Dashboard.

  3. Click the link for the proxy that you want to use to monitor node health.

  4. If you are prompted, enter the username and password that you recorded in Log In to the Dashboard.

    Switchboard all healthy

Monitor Node Health Using the API

You can also use the Switchboard API to obtain the information that is shown on the Switchboard dashboard. For example, you might want to use the API to write your own app to monitor the cluster.

To monitor node health using the Switchboard API, do the following:

  1. To monitor node health, run the following command:

    curl https://USERNAME:PASSWORD@N-HOSTNAME/v0/backends
    

    Where:

    • USERNAME is the username you recorded in Log In to the Dashboard.
    • PASSWORD is the password you recorded in Log In to the Dashboard.
    • N is either 0, 1, or 2 depending on the proxy you want to connect to.
    • HOSTNAME is the IP address of the Database found in the Status tab of your PAS tile.

    The above command outputs a JSON object similar to the following:

    $ curl https://abcdefghijklmno:012345678912345@0-proxy.123abc45-67d8-912e-34f5-g34612c10dba.org.dedicated-mysql.cf-app.com/v0/backends
    [
      {
        "host": "a-b1234c5d6.e-f891.bosh",
        "port": 6033,
        "healthy": true,
        "name": "backend-0",
        "currentSessionCount": 0,
        "active": true,
        "trafficEnabled": true
      },
      {
        "host": "a-b1234c5d6.e-f891.bosh",
        "port": 6033,
        "healthy": true,
        "name": "backend-1",
        "currentSessionCount": 0,
        "active": false,
        "trafficEnabled": true
      },
      {
        "host": "a-b1234c5d6.e-f891.bosh",
        "port": 6033,
        "healthy": true,
        "name": "backend-2",
        "currentSessionCount": 0,
        "active": false,
        "trafficEnabled": true
      }
    ]