# 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/lib/postgresqlutils.py
# CONNECT_TIMEOUT = 2 # seconds
# SEARCH_DIRS = frozenset([
#   "/var/run/postgresql", # Debian default
#   "/var/pgsql_socket", # MacOS default
#   "/usr/local/var/postgres", # custom compilation
#   "/tmp", # custom compilation
# ])
# def find_sockdir():
# def postgres_connect(sockdir):
# def connect():


import sys
import os
import time
import socket
import errno
from collectors.lib import utils
from collectors.lib import postgresqlutils
      result[database] = stat

    for database in result:
      for i in range(2,len(cursor.description)):
        metric = cursor.description[i].name
        value = result[database][i]
        try:
          if metric in ("stats_reset"):
            continue
          print("postgresql.%s %i %s database=%s"
                 % (metric, ts, value, database))
        except:
          utils.err("got here")
          continue

    # connections
    cursor.execute("SELECT datname, count(datname) FROM pg_stat_activity"
                   " GROUP BY pg_stat_activity.datname")
    ts = time.time()
    connections = cursor.fetchall()

    for database, connection in connections:
      print("postgresql.connections %i %s database=%s"
             % (ts, connection, database))

  except (EnvironmentError, EOFError, RuntimeError, socket.error) as e:
    if isinstance(e, IOError) and e[0] == errno.EPIPE:
      # exit on a broken pipe. There is no point in continuing
      # because no one will read our stdout anyway.
      return 2

# 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/lib/postgresqlutils.py
# CONNECT_TIMEOUT = 2 # seconds
# SEARCH_DIRS = frozenset([
#   "/var/run/postgresql", # Debian default
#   "/var/pgsql_socket", # MacOS default
#   "/usr/local/var/postgres", # custom compilation
#   "/tmp", # custom compilation
# ])
# def find_sockdir():
# def postgres_connect(sockdir):
# def connect():


# Path: collectors/0/postgresql.py
import sys
import os
import time
import socket
import errno
from collectors.lib import utils
from collectors.lib import postgresqlutils

      result[database] = stat

    for database in result:
      for i in range(2,len(cursor.description)):
        metric = cursor.description[i].name
        value = result[database][i]
        try:
          if metric in ("stats_reset"):
            continue
          print("postgresql.%s %i %s database=%s"
                 % (metric, ts, value, database))
        except:
          utils.err("got here")
          continue

    # connections
    cursor.execute("SELECT datname, count(datname) FROM pg_stat_activity"
                   " GROUP BY pg_stat_activity.datname")
    ts = time.time()
    connections = cursor.fetchall()

    for database, connection in connections:
      print("postgresql.connections %i %s database=%s"
             % (ts, connection, database))

  except (EnvironmentError, EOFError, RuntimeError, socket.error) as e:
    if isinstance(e, IOError) and e[0] == errno.EPIPE:
      # exit on a broken pipe. There is no point in continuing
      # because no one will read our stdout anyway.
      return 2

    utils.err("error: failed to collect data: %s" % e)