Add more commandline arguments, update Gentoo files
This commit is contained in:
parent
b0a5abc05d
commit
467e97f4e7
@ -38,10 +38,10 @@ ipc_socket=/run/pgmon/pgmon.sock
|
|||||||
##
|
##
|
||||||
|
|
||||||
# Log level for stderr logging (or 'off')
|
# Log level for stderr logging (or 'off')
|
||||||
stderr_log_level=info
|
stderr_log_level=off
|
||||||
|
|
||||||
# Log level for file logging (od 'off')
|
# Log level for file logging (od 'off')
|
||||||
file_log_level=notice
|
file_log_level=info
|
||||||
|
|
||||||
# Log file
|
# Log file
|
||||||
#log_file=pgmon.log
|
#log_file=pgmon.log
|
||||||
@ -67,4 +67,4 @@ file_log_level=notice
|
|||||||
# Metrics
|
# Metrics
|
||||||
#metrics={}
|
#metrics={}
|
||||||
|
|
||||||
include=pgmon-metrics.cfg
|
include=/etc/pgmon/pgmon-metrics.cfg
|
||||||
|
|||||||
@ -2,14 +2,19 @@
|
|||||||
|
|
||||||
extra_started_commands="reload"
|
extra_started_commands="reload"
|
||||||
|
|
||||||
agent_name=${RC_SERVICE#pgmon.}
|
agent_name=${SVCNAME#pgmon.}
|
||||||
agent_name=${agent_name:-pgmon}
|
agent_name=${agent_name:-pgmon}
|
||||||
|
|
||||||
command="/usr/local/bin/pgmon"
|
CONFIG_FILE="/etc/pgmon/${agent_name}.cfg"
|
||||||
command_args="--server --config /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"
|
||||||
|
|
||||||
|
command="/usr/bin/pgmon"
|
||||||
|
command_args="--server -c '$CONFIG_FILE' -l '$LOG_FILE' -p '$PID_FILE' -s '$SOCKET'"
|
||||||
command_user="zabbix:zabbix"
|
command_user="zabbix:zabbix"
|
||||||
|
|
||||||
pidfile="/run/pgmon/${agent_name}.pid"
|
pidfile="$PID_FILE"
|
||||||
|
|
||||||
start_pre() {
|
start_pre() {
|
||||||
checkpath -d -m 0755 -o "${command_user}" "/run/pgmon"
|
checkpath -d -m 0755 -o "${command_user}" "/run/pgmon"
|
||||||
|
|||||||
@ -14,7 +14,7 @@ LICENSE="BSD"
|
|||||||
SLOT="0"
|
SLOT="0"
|
||||||
KEYWORDS="amd64"
|
KEYWORDS="amd64"
|
||||||
|
|
||||||
EGIT_REPO_URI="https://code2.shh-dot-com.org/pgmon.git"
|
EGIT_REPO_URI="https://code2.shh-dot-com.org/james/pgmon.git"
|
||||||
#EGIT_COMMIT=""
|
#EGIT_COMMIT=""
|
||||||
|
|
||||||
IUSE="+agent agent2"
|
IUSE="+agent agent2"
|
||||||
@ -35,7 +35,11 @@ src_install() {
|
|||||||
default
|
default
|
||||||
|
|
||||||
# Install init script
|
# Install init script
|
||||||
newinitd files/pgmon.openrc pgmon
|
newinitd "${FILESDIR}/pgmon.openrc" pgmon
|
||||||
|
|
||||||
|
# Install script
|
||||||
|
exeinto /usr/bin
|
||||||
|
newexe "${S}/pgmon.py" pgmon
|
||||||
|
|
||||||
# Install default config
|
# Install default config
|
||||||
diropts -o root -g zabbix -m 0755
|
diropts -o root -g zabbix -m 0755
|
||||||
|
|||||||
30
pgmon.py
30
pgmon.py
@ -84,7 +84,7 @@ def init_logging(config):
|
|||||||
old_file_logger = file_log_handler
|
old_file_logger = file_log_handler
|
||||||
file_log_handler = None
|
file_log_handler = None
|
||||||
else:
|
else:
|
||||||
olf_file_logger = None
|
old_file_logger = None
|
||||||
|
|
||||||
# Create and add the handler if it doesn't exist
|
# Create and add the handler if it doesn't exist
|
||||||
if file_log_handler is None:
|
if file_log_handler is None:
|
||||||
@ -187,7 +187,7 @@ class Config:
|
|||||||
mindful about logging anything in this class.
|
mindful about logging anything in this class.
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
config_file: (str) Path to the config file
|
args: (argparse.Namespace) Command line arguments
|
||||||
read_metrics: (bool) Indicate if metrics should be parsed
|
read_metrics: (bool) Indicate if metrics should be parsed
|
||||||
read_clusters: (bool) Indicate if cluster information should be parsed
|
read_clusters: (bool) Indicate if cluster information should be parsed
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ class Config:
|
|||||||
OSError: Thrown if there's an issue opening a config file
|
OSError: Thrown if there's an issue opening a config file
|
||||||
ValueError: Thrown if there is an encoding error
|
ValueError: Thrown if there is an encoding error
|
||||||
"""
|
"""
|
||||||
def __init__(self, config_file, read_metrics = True, read_clusters = True):
|
def __init__(self, args, read_metrics = True, read_clusters = True):
|
||||||
# Set defaults
|
# Set defaults
|
||||||
self.pid_file = 'pgmon.pid' # PID file
|
self.pid_file = 'pgmon.pid' # PID file
|
||||||
|
|
||||||
@ -214,8 +214,20 @@ class Config:
|
|||||||
self.metrics = {} # Metrics
|
self.metrics = {} # Metrics
|
||||||
self.clusters = {} # Known clusters
|
self.clusters = {} # Known clusters
|
||||||
|
|
||||||
|
# Check if we have a config file
|
||||||
|
self.config_file = args.config
|
||||||
|
|
||||||
# Read config
|
# Read config
|
||||||
self.read_file(config_file, read_metrics, read_clusters)
|
if self.config_file is not None:
|
||||||
|
self.read_file(self.config_file, read_metrics, read_clusters)
|
||||||
|
|
||||||
|
# Override anything that was specified on the command line
|
||||||
|
if args.pidfile is not None:
|
||||||
|
self.pid_file = args.pidfile
|
||||||
|
if args.logfile is not None:
|
||||||
|
self.log_file = args.logfile
|
||||||
|
if args.socket is not None:
|
||||||
|
self.ipc_socket = args.socket
|
||||||
|
|
||||||
def read_file(self, config_file, read_metrics, read_clusters):
|
def read_file(self, config_file, read_metrics, read_clusters):
|
||||||
"""
|
"""
|
||||||
@ -1261,8 +1273,12 @@ def main():
|
|||||||
parser.add_argument('-c', '--config', default='pgmon.cfg')
|
parser.add_argument('-c', '--config', default='pgmon.cfg')
|
||||||
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('-l', '--logfile', default=None)
|
||||||
|
parser.add_argument('-p', '--pidfile', default=None)
|
||||||
|
|
||||||
# Operational mode
|
# Operational mode
|
||||||
parser.add_argument('-s', '--server', action='store_true')
|
parser.add_argument('-S', '--server', action='store_true')
|
||||||
parser.add_argument('-r', '--reload', action='store_true')
|
parser.add_argument('-r', '--reload', action='store_true')
|
||||||
|
|
||||||
# Agent options
|
# Agent options
|
||||||
@ -1274,7 +1290,7 @@ def main():
|
|||||||
if args.server:
|
if args.server:
|
||||||
# Try to start running in server mode
|
# Try to start running in server mode
|
||||||
try:
|
try:
|
||||||
server = Server(args.config)
|
server = Server(args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit("Failed to start server: {}".format(e))
|
sys.exit("Failed to start server: {}".format(e))
|
||||||
|
|
||||||
@ -1286,7 +1302,7 @@ def main():
|
|||||||
elif args.reload:
|
elif args.reload:
|
||||||
# Try to signal a running server to reload its config
|
# Try to signal a running server to reload its config
|
||||||
try:
|
try:
|
||||||
config = Config(args.config, read_metrics = False)
|
config = Config(args, read_metrics = False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit("Failed to read config file: {}".format(e))
|
sys.exit("Failed to read config file: {}".format(e))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user