def find_sockdir(): """Returns a path to PostgreSQL socket file to monitor.""" for dir in SEARCH_DIRS: for dirpath, dirnames, dirfiles in os.walk(dir, followlinks=True): for name in dirfiles: # ensure selection of PostgreSQL socket only if (utils.is_sockfile(os.path.join(dirpath, name)) and "PGSQL" in name): return(dirpath)
def find_sockfiles(): """Returns a list of paths to socket files to monitor.""" paths = [] # Look for socket files. for dir in SEARCH_DIRS: if not os.path.isdir(dir): continue for name in os.listdir(dir): subdir = os.path.join(dir, name) if not os.path.isdir(subdir): continue for subname in os.listdir(subdir): path = os.path.join(subdir, subname) if utils.is_sockfile(path): paths.append(path) break # We only expect 1 socket file per DB, so get out. # Try the default locations. for sockfile in DEFAULT_SOCKFILES: if not utils.is_sockfile(sockfile): continue paths.append(sockfile) return paths
def find_sockfiles(): """Returns a list of paths to socket files to monitor.""" paths = [] # Look for socket files. for thedir in SEARCH_DIRS: if not os.path.isdir(thedir) or not os.access(thedir, os.R_OK): continue for name in os.listdir(thedir): subdir = os.path.join(thedir, name) if not os.path.isdir(subdir) or not os.access(subdir, os.R_OK): continue for subname in os.listdir(subdir): path = os.path.join(subdir, subname) if utils.is_sockfile(path): paths.append(path) break # We only expect 1 socket file per DB, so get out. # Try the default locations. for sockfile in DEFAULT_SOCKFILES: if not utils.is_sockfile(sockfile): continue paths.append(sockfile) return paths
def find_sock_file(conf_file): """Returns the unix socket file of haproxy.""" try: fd = open(conf_file) except IOError as e: utils.err("Error: %s. Config file path is relative: %s" % (e, conf_file)) return None try: for line in fd: if line.lstrip(" \t").startswith("stats socket"): sock_file = line.split()[2] if utils.is_sockfile(sock_file): return sock_file finally: fd.close()
utils.err("HAProxy (pid %s) went away? %s" % (pid, e)) return None return output.split("-f")[1].split()[0] def find_sock_file(conf_file): """Returns the unix socket file of haproxy.""" try: fd = open(conf_file) except IOError, e: utils.err("Error: %s. Config file path is relative: %s" % (e, conf_file)) return None try: for line in fd: 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()
return None return output.split("-f")[1].split()[0] def find_sock_file(conf_file): """Returns the unix socket file of haproxy.""" try: fd = open(conf_file) except IOError, e: err("Error: %s. Config file path is relative: %s" % (e, conf_file)) return None try: for line in fd: 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) sock.connect(sock_file) sock.send("show stat\n") stats = sock.recv(10240) sock.close() ts = time.time() for line in stats.split("\n"): var = line.split(",")