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:
parent
9b382bedaa
commit
2afeb827ed
@ -11,6 +11,13 @@ PGMON_USER="${PGMON_USER:-postgres}"
|
|||||||
PGMON_GROUP="${PGMON_GROUP:-$PGMON_USER}"
|
PGMON_GROUP="${PGMON_GROUP:-$PGMON_USER}"
|
||||||
CONFIG_FILE="/etc/pgmon/${agent_name}.yml"
|
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="/usr/bin/pgmon"
|
||||||
command_args="'$CONFIG_FILE'"
|
command_args="'$CONFIG_FILE'"
|
||||||
command_background="true"
|
command_background="true"
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
# The port the agent listens on for requests
|
||||||
|
#port: 5400
|
||||||
|
|
||||||
# Min PostgreSQL connection pool size (per database)
|
# Min PostgreSQL connection pool size (per database)
|
||||||
#min_pool_size: 0
|
#min_pool_size: 0
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import logging
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2.extras import DictCursor
|
from psycopg2.extras import RealDictCursor
|
||||||
from psycopg2.pool import ThreadedConnectionPool
|
from psycopg2.pool import ThreadedConnectionPool
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
@ -70,6 +70,9 @@ class MetricVersionError(Exception):
|
|||||||
|
|
||||||
# Default config settings
|
# Default config settings
|
||||||
default_config = {
|
default_config = {
|
||||||
|
# The port the agent listens on for requests
|
||||||
|
'port': 5400,
|
||||||
|
|
||||||
# Min PostgreSQL connection pool size (per database)
|
# Min PostgreSQL connection pool size (per database)
|
||||||
'min_pool_size': 0,
|
'min_pool_size': 0,
|
||||||
|
|
||||||
@ -296,7 +299,7 @@ def get_pool(dbname):
|
|||||||
host=config['dbhost'],
|
host=config['dbhost'],
|
||||||
port=config['dbport'],
|
port=config['dbport'],
|
||||||
user=config['dbuser'],
|
user=config['dbuser'],
|
||||||
connect_timeout=float(config['connect_timeout']),
|
connect_timeout=int(config['connect_timeout']),
|
||||||
sslmode='require')
|
sslmode='require')
|
||||||
# Clear the unhappy indicator if present
|
# Clear the unhappy indicator if present
|
||||||
unhappy_cooldown.pop(dbname, None)
|
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:
|
with pool.connection(float(config['connect_timeout'])) as conn:
|
||||||
try:
|
try:
|
||||||
with conn.cursor(cursor_factory=DictCursor) as curs:
|
with conn.cursor(cursor_factory=RealDictCursor) as curs:
|
||||||
curs.execute(query, args)
|
curs.execute(query, args)
|
||||||
res = curs.fetchall()
|
res = curs.fetchall()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user