The usage of MySQL Router as a Middleware/Proxy/Router has increased along with the rise in MySQL InnoDB Cluster usage. While it is still relatively easy to use in production, monitoring it to stay informed about its current status is essential. This blog post will cover how to check and monitor MySQL routers, routes, and other statistics that can be valuable in identifying or even preventing potential issues.

In version 8.0.16, MySQL Router added a web server interface (HTTP), but the really cool thing related to the web server interface came in version 8.0.17 with the REST API. For those who don’t know, API stands for application programming interface, and REST stands for representational state transfer. Simply put, a REST API is an interface that lets computers trade information over the internet.

Using MySQL Router

Let’s explore the setup and usage. To get started, we’ll assume we have a Group Replication cluster set up on AWS and configure the MySQL Router on a separate server with IP 172.22.214.2. So, let’s start bootstrapping! 

Note that from version 8.0.22 and onwards, when bootstrapping the router, the REST API will be already set up with the bootstrap. Since we aim to understand the REST further, we added the –disable-rest flag to the bootstrap command to not set anything. Hence, we need to configure the router properly. 

The following settings are the most basic configuration to enable the HTTP server to serve our requests and the REST API basic endpoint:

With those only two groups on the MySQL Router conf file, it is already possible to send requests:

The swagger.json output is the only one able to reply/respond without any authentication, so to check the other endpoints, we need to create the authentication config. The router uses realm for authentication, so please use the following template to create the realm:

Once we create the realm, we can create the backend mentioned on the template above:

With the config done, we need to create the user on the file set on the configuration:

Giving the correct user permission:

With the user created and the authentication configured, we need to enable the route to other endpoints:

Sending request to the new endpoint:

Besides the two endpoints, we have endpoints for MySQL Router connection pool, routing, and metadata. Below, I will show you how to enable the routing and metadata ones, as well as some examples. So on MySQL Router REST API reference, we have all routes existent and the plugin needed to enable each one:

To enable routing:

Testing the routing REST endpoint:

Enabling metadata endpoint:

Using metadata endpoint:

Use case

If a host reaches the max_connection_errors from the route, the router will block the host on that route. The Rest API is a way to check which host was blocked and how many hosts were blocked. Allow me to show an example:

Checking the host was blocked:

Also, instead of implementing health checks using port knocking, you can now use the /health endpoint. For example, here is what a healthy route looks like: 

Or even:

Conclusion:

Although it isn’t possible to change configurations through the Router REST API, the values returned from the API consumption give us some monitoring values that can help us understand the health and usage of our MySQL Router.


MySQL Performance Tuning is an essential guide covering the critical aspects of MySQL performance optimization.

 

Download and unlock the full potential of your MySQL database today!

 

References:
https://dev.mysql.com/doc/relnotes/mysql-router/8.0/en/news-8-0-16.html
https://dev.mysql.com/doc/relnotes/mysql-router/8.0/en/news-8-0-17.html
https://dev.mysql.com/doc/relnotes/mysql-router/8.0/en/news-8-0-22.html
https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-rest-api-setup.html

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments