# 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
import re
import subprocess
from collectors.lib import utils
from collectors.lib import postgresqlutils
    print("postgresql.replication.walreceiver.running %i %s"
         % (ts, wal_receiver_running))

    # WAL sender process info (could be master only or master / slave combo)
    cursor.execute("SELECT client_addr, client_port, "
                   "pg_xlog_location_diff(sent_location, replay_location) AS lag_bytes "
                   "FROM pg_stat_replication;")
    ts = time.time()
    stats = cursor.fetchall()

    print("postgresql.replication.downstream.count %i %i"
           % (ts, len(stats)))

    for stat in stats:
      print("postgresql.replication.downstream.lag.bytes %i %i client_ip=%s client_port=%s"
           % (ts, stat[2], stat[0], stat[1]))

  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)

def main(args):
  """Collects and dumps stats from a PostgreSQL server."""

  try:
    db = postgresqlutils.connect()
  except (Exception) 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/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_replication.py
import sys
import os
import time
import socket
import errno
import re
import subprocess
from collectors.lib import utils
from collectors.lib import postgresqlutils

    print("postgresql.replication.walreceiver.running %i %s"
         % (ts, wal_receiver_running))

    # WAL sender process info (could be master only or master / slave combo)
    cursor.execute("SELECT client_addr, client_port, "
                   "pg_xlog_location_diff(sent_location, replay_location) AS lag_bytes "
                   "FROM pg_stat_replication;")
    ts = time.time()
    stats = cursor.fetchall()

    print("postgresql.replication.downstream.count %i %i"
           % (ts, len(stats)))

    for stat in stats:
      print("postgresql.replication.downstream.lag.bytes %i %i client_ip=%s client_port=%s"
           % (ts, stat[2], stat[0], stat[1]))

  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)

def main(args):
  """Collects and dumps stats from a PostgreSQL server."""

  try:
    db = postgresqlutils.connect()
  except (Exception) as e:

    utils.err("error: Could not initialize collector : %s" % (e))