diff --git a/openrc/pgmon.initd b/openrc/pgmon.initd index e3fc0c1..8d8c96d 100644 --- a/openrc/pgmon.initd +++ b/openrc/pgmon.initd @@ -11,6 +11,13 @@ PGMON_USER="${PGMON_USER:-postgres}" PGMON_GROUP="${PGMON_GROUP:-$PGMON_USER}" CONFIG_FILE="/etc/pgmon/${agent_name}.yml" +output_log=/var/log/pgmon/${SVCNAME}.log +error_log=/var/log/pgmon/${SVCNAME}.err + +start_pre() { + checkpath -f -m 0644 -o "${PGMON_USER}:${PGMON_GROUP}" "${output_log}" "${error_log}" +} + command="/usr/bin/pgmon" command_args="'$CONFIG_FILE'" command_background="true" diff --git a/sample-config/pgmon.yml b/sample-config/pgmon.yml index ba746b6..879005d 100644 --- a/sample-config/pgmon.yml +++ b/sample-config/pgmon.yml @@ -1,3 +1,6 @@ +# The port the agent listens on for requests +#port: 5400 + # Min PostgreSQL connection pool size (per database) #min_pool_size: 0 diff --git a/src/pgmon.py b/src/pgmon.py index 5d6dc6e..7f681ef 100755 --- a/src/pgmon.py +++ b/src/pgmon.py @@ -11,7 +11,7 @@ import logging from datetime import datetime, timedelta import psycopg2 -from psycopg2.extras import DictCursor +from psycopg2.extras import RealDictCursor from psycopg2.pool import ThreadedConnectionPool from contextlib import contextmanager @@ -70,6 +70,9 @@ class MetricVersionError(Exception): # Default config settings default_config = { + # The port the agent listens on for requests + 'port': 5400, + # Min PostgreSQL connection pool size (per database) 'min_pool_size': 0, @@ -296,7 +299,7 @@ def get_pool(dbname): host=config['dbhost'], port=config['dbport'], user=config['dbuser'], - connect_timeout=float(config['connect_timeout']), + connect_timeout=int(config['connect_timeout']), sslmode='require') # Clear the unhappy indicator if present unhappy_cooldown.pop(dbname, None) @@ -333,7 +336,7 @@ def run_query_no_retry(pool, return_type, query, args): """ with pool.connection(float(config['connect_timeout'])) as conn: try: - with conn.cursor(cursor_factory=DictCursor) as curs: + with conn.cursor(cursor_factory=RealDictCursor) as curs: curs.execute(query, args) res = curs.fetchall()