import re


def get_cluster_sizes(connections):
	"""
    Returns a dictionary mapping clusters of servers (given
    by their naming scheme) and the number of connections in
    that cluster.
    """
	expr = re.compile(r".*\.shard\d+$")
	clusters = {}
	for conn in connections:
		if not expr.match(conn):
			continue
		cluster = conn.split(".shard", 1)[0]
		if cluster not in clusters:
			clusters[cluster] = 1
		else:
			clusters[cluster] += 1
	return clusters