Display the Number of YCQL Connections

Yugabyte Cloud Query Language (YCQL) is a semi-relational SQL API that is best fit for internet-scale OLTP and HTAP applications needing massive data ingestion and blazing-fast queries. 

We can connect to YCQL various ways. For example, via ycqlsh, the shell for interacting with the YugabyteDB YCQL API. We can also use DBeaver Enterprise and TablePlus.

As a DBA you might wonder how many current connections exist. 

While there aren’t any system catalog tables that track this detail, we can instead use the YCQL metrics endpoint to display the number of connections for a given DB node (i.e. T-Server).

Example:

The YCQL metrics enpoint is <node IP>:12000/metrics. The metric we want is named rpc_connections_alive. From the command line we can use the curl command to query the end point, then apply several Linux commands to extarct the info we need to calculate and display the number of YCQL connections on the node.

				
					# echo "YCQL Connections: $(( $(curl -s http://$(hostname -I | awk '{print $1}'):12000/metrics | grep rpc_connections_alive -A 1 | tail -n 1 | cut -d ":" -f2 | sed 's/ //g') / 2 ))"
YCQL Connections: 0
				
			

Right now there are not any current connection to YCQL. Let’s create some using ysqlsh.

				
					# ycqlsh $(hostname -I | awk '{print $1}') -u cassandra -p password > /dev/null &
[1] 42042

# ycqlsh $(hostname -I | awk '{print $1}') -u cassandra -p password > /dev/null &
[2] 42061

# ycqlsh $(hostname -I | awk '{print $1}') -u cassandra -p password > /dev/null &
[3] 42082

[root@Cloud_Server_0 ~]# echo "YCQL Connections: $(( $(curl -s http://$(hostname -I | awk '{print $1}'):12000/metrics | grep rpc_connections_alive -A 1 | tail -n 1 | cut -d ":" -f2 | sed 's/ //g') / 2 ))"
YCQL Connections: 3
				
			

Now we see the 3 connections!

What if we create a conenction from DBeaver? Can we count those too? Let’s find out…

				
					[root@Cloud_Server_0 ~]# echo "YCQL Connections: $(( $(curl -s http://$(hostname -I | awk '{print $1}'):12000/metrics | grep rpc_connections_alive -A 1 | tail -n 1 | cut -d ":" -f2 | sed 's/ //g') / 2 ))"
YCQL Connections: 4
				
			

Yup, the remote DBeaver connection is also counted by the rpc_connections_alive metric!

Have Fun!

Baby birds in a bush just outside of my home office window.