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