import asyncio
import io


async def get_stats(socket_path):
  """ Reads haproxy statistics from haproxy stats socket.

  Args:
    socket_path: A str - path to the haproxy socket on the file system.
  Returns:
    A StringIO buffer containing data from socket.
  """
  reader, writer = await asyncio.open_unix_connection(socket_path)
  try:
    stats_output = io.StringIO()
    writer.write(b'show stat\n')
    stats_output.write((await reader.read()).decode())
    stats_output.seek(0)
    return stats_output
  finally:
    writer.close()