Improve openrc init script, add port setting

* Ensure the log directory exists with openrc

* Add a port setting to configure the port the agent listens on

* Switch to RealDictCursor

* Fix type for connection timeout
This commit is contained in:
James Campbell 2025-04-19 00:07:15 -04:00
parent 9b382bedaa
commit 2afeb827ed
Signed by: james
GPG Key ID: 2287C33A40DC906A
3 changed files with 16 additions and 3 deletions

View File

@ -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"

View File

@ -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

View File

@ -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()