# 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
    "rate_lim": "limit_on_new_sessions_per_second",
    "rate_max": "max_number_of_new_sessions_per_second",
    "check_code": "health_check_code",
    "check_duration": "health_check_duration_in_milliseconds",
    "hrsp_1xx": "http_responses_with_1xx_code",
    "hrsp_2xx": "http_responses_with_2xx_code",
    "hrsp_3xx": "http_responses_with_3xx_code",
    "hrsp_4xx": "http_responses_with_4xx_code",
    "hrsp_5xx": "http_responses_with_5xx_code",
    "hrsp_other": "http_responses_with_other_codes",
    "req_rate": "http_request_rate",
    "req_rate_max": "max_observed_http_requests",
    "req_tot": "http_requests_received",
    "cli_abrt": "client_aborted_data_transfers",
    "srv_abrt": "server_aborted_data_transfers"
}

def haproxy_pid():
  """Finds out the pid of haproxy process"""
  try:
     pid = subprocess.check_output(["pidof", "-s", "haproxy"])
  except subprocess.CalledProcessError:
     return None
  return pid.rstrip()

def find_conf_file(pid):
  """Returns the conf file of haproxy."""
  try:
     output = subprocess.check_output(["ps", "--no-headers", "-o", "cmd", pid])
  except subprocess.CalledProcessError as e:

# 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

    "rate_lim": "limit_on_new_sessions_per_second",
    "rate_max": "max_number_of_new_sessions_per_second",
    "check_code": "health_check_code",
    "check_duration": "health_check_duration_in_milliseconds",
    "hrsp_1xx": "http_responses_with_1xx_code",
    "hrsp_2xx": "http_responses_with_2xx_code",
    "hrsp_3xx": "http_responses_with_3xx_code",
    "hrsp_4xx": "http_responses_with_4xx_code",
    "hrsp_5xx": "http_responses_with_5xx_code",
    "hrsp_other": "http_responses_with_other_codes",
    "req_rate": "http_request_rate",
    "req_rate_max": "max_observed_http_requests",
    "req_tot": "http_requests_received",
    "cli_abrt": "client_aborted_data_transfers",
    "srv_abrt": "server_aborted_data_transfers"
}

def haproxy_pid():
  """Finds out the pid of haproxy process"""
  try:
     pid = subprocess.check_output(["pidof", "-s", "haproxy"])
  except subprocess.CalledProcessError:
     return None
  return pid.rstrip()

def find_conf_file(pid):
  """Returns the conf file of haproxy."""
  try:
     output = subprocess.check_output(["ps", "--no-headers", "-o", "cmd", pid])
  except subprocess.CalledProcessError as e:

     utils.err("HAProxy (pid %s) went away? %s" % (pid, e))