Debug agent
This commit is contained in:
parent
7a4e62a94e
commit
c1747d58dc
@ -10,7 +10,7 @@
|
||||
##
|
||||
|
||||
# IPC socket
|
||||
#ipc_socket=/tmp/pgmon.sock
|
||||
#ipc_socket=pgmon.sock
|
||||
|
||||
# IPC communication timeout (s)
|
||||
#ipc_timeout=10
|
||||
|
||||
@ -7,8 +7,8 @@ agent_name=${agent_name:-pgmon}
|
||||
|
||||
CONFIG_FILE="/etc/pgmon/${agent_name}.cfg"
|
||||
PID_FILE="/run/pgmon/${agent_name}.pid"
|
||||
LOG_FILE="/var/log/${agent_name}.log"
|
||||
SOCKET="/var/run/${agent_name}.socket"
|
||||
LOG_FILE="/var/log/pgmon/${agent_name}.log"
|
||||
SOCKET="/run/pgmon/${agent_name}.socket"
|
||||
|
||||
pidfile="$PID_FILE"
|
||||
|
||||
@ -17,6 +17,9 @@ command_args="--server -c '$CONFIG_FILE' -l '$LOG_FILE' -s '$SOCKET'"
|
||||
command_background="true"
|
||||
command_user="zabbix:zabbix"
|
||||
|
||||
output_log="/var/log/pgmon/${agent_name}-service.log"
|
||||
error_log="/var/log/pgmon/${agent_name}-service.err"
|
||||
|
||||
start_pre() {
|
||||
checkpath -d -m 0755 -o "${command_user}" "/run/pgmon"
|
||||
checkpath -d -m 0755 -o "${command_user}" "/var/log/pgmon"
|
||||
|
||||
24
pgmon.py
24
pgmon.py
@ -750,7 +750,11 @@ class IPC:
|
||||
self.mode = mode
|
||||
|
||||
# Set up the connection
|
||||
self.initialize()
|
||||
try:
|
||||
self.initialize()
|
||||
except Exception as e:
|
||||
logger.debug("IPC Initialization error: {}".format(e))
|
||||
raise
|
||||
|
||||
def initialize(self):
|
||||
"""
|
||||
@ -760,13 +764,18 @@ class IPC:
|
||||
OSError: if the socket file already exists and could not be removed
|
||||
RuntimeError: if the IPC object's mode is invalid
|
||||
"""
|
||||
logger.debug("Initializing IPC")
|
||||
if self.mode == 'server':
|
||||
# Try to clean up the socket if it exists
|
||||
try:
|
||||
logger.debug("Unlinking any former socket")
|
||||
os.unlink(self.config.ipc_socket)
|
||||
except OSError:
|
||||
logger.debug("Caught an exception unlinking socket")
|
||||
if os.path.exists(self.config.ipc_socket):
|
||||
logger.debug("Socket stilll exists")
|
||||
raise
|
||||
logger.debug("No socket to unlink")
|
||||
|
||||
# Create the socket
|
||||
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
@ -775,7 +784,9 @@ class IPC:
|
||||
self.socket.settimeout(1)
|
||||
|
||||
# Bind the socket and start listening
|
||||
logger.debug("Binding socket: {}".format(self.config.ipc_socket))
|
||||
self.socket.bind(self.config.ipc_socket)
|
||||
logger.debug("Listening on socket")
|
||||
self.socket.listen(1)
|
||||
|
||||
elif self.mode == 'agent':
|
||||
@ -788,6 +799,8 @@ class IPC:
|
||||
else:
|
||||
raise RuntimeError("Invalid IPC mode: {}".format(self.mode))
|
||||
|
||||
logger.debug("IPC initialization complete")
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
Establish a connection to a socket (agent mode)
|
||||
@ -916,6 +929,8 @@ class Agent:
|
||||
# Read the agent config
|
||||
config = Config(args, read_metrics = False, read_clusters = False)
|
||||
|
||||
init_logging(config)
|
||||
|
||||
# Connect to the IPC socket
|
||||
ipc = IPC(config, 'agent')
|
||||
try:
|
||||
@ -927,8 +942,8 @@ class Agent:
|
||||
# Wait for a response
|
||||
res = ipc.recv(conn)
|
||||
|
||||
except:
|
||||
print("IPC error")
|
||||
except Exception as e:
|
||||
print("IPC error: {}".format(e))
|
||||
sys.exit(1)
|
||||
|
||||
# Output the response
|
||||
@ -1059,6 +1074,7 @@ class Server:
|
||||
while True:
|
||||
# Wait for a request connection
|
||||
try:
|
||||
logger.debug("Waiting for a connection")
|
||||
conn = ipc.accept()
|
||||
except socket.timeout:
|
||||
conn = None
|
||||
@ -1275,7 +1291,7 @@ def main():
|
||||
description='A briidge between monitoring tools and PostgreSQL')
|
||||
|
||||
# General options
|
||||
parser.add_argument('-c', '--config', default='pgmon.cfg')
|
||||
parser.add_argument('-c', '--config', default=None)
|
||||
parser.add_argument('-v', '--verbose', action='store_true')
|
||||
|
||||
parser.add_argument('-s', '--socket', default=None)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user