# Path: collectors/lib/utils.py
# PY3 = sys.version_info[0] > 2
# USER = "nobody"
# def drop_privileges(user=USER):
# def is_sockfile(path):
# def err(msg):
#     def is_numeric(value):
#     def is_numeric(value):


import os
import socket
import sys
import time
import stat
import subprocess
import csv
from collectors.lib import utils
      if line.lstrip(" \t").startswith("stats socket"):
        sock_file = line.split()[2]
        if utils.is_sockfile(sock_file):
          return sock_file
  finally:
    fd.close()


def collect_stats(sock_file):
    """Collects stats from haproxy unix domain socket"""
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)  
    try:
      sock.settimeout(COLLECTION_INTERVAL)
      sock.connect(sock_file)
      sock.send("show stat\n")
      statlines = sock.recv(10240).split('\n')
    finally:
      sock.close()

    ts = time.time()
    # eat up any empty lines that may be present
    statlines = [line for line in statlines if line != ""]

    # headers are given first, with or without the prompt present
    headers = None
    if statlines[0].startswith("> # "):
        headers = statlines[0][4:].split(',')
    elif statlines[0].startswith("# "):
        headers = statlines[0][2:].split(',')
    else:

# Path: collectors/lib/utils.py
# PY3 = sys.version_info[0] > 2
# USER = "nobody"
# def drop_privileges(user=USER):
# def is_sockfile(path):
# def err(msg):
#     def is_numeric(value):
#     def is_numeric(value):


# Path: collectors/0/haproxy.py
import os
import socket
import sys
import time
import stat
import subprocess
import csv
from collectors.lib import utils

      if line.lstrip(" \t").startswith("stats socket"):
        sock_file = line.split()[2]
        if utils.is_sockfile(sock_file):
          return sock_file
  finally:
    fd.close()


def collect_stats(sock_file):
    """Collects stats from haproxy unix domain socket"""
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)  
    try:
      sock.settimeout(COLLECTION_INTERVAL)
      sock.connect(sock_file)
      sock.send("show stat\n")
      statlines = sock.recv(10240).split('\n')
    finally:
      sock.close()

    ts = time.time()
    # eat up any empty lines that may be present
    statlines = [line for line in statlines if line != ""]

    # headers are given first, with or without the prompt present
    headers = None
    if statlines[0].startswith("> # "):
        headers = statlines[0][4:].split(',')
    elif statlines[0].startswith("# "):
        headers = statlines[0][2:].split(',')
    else:

        utils.err("No headers found in HAProxy output: %s" % (statlines[0],))