Skip to content

Commit 0e9fccd

Browse files
rpwrouesnel
rp
authored andcommitted
add rc-script for postgres_exporter
1 parent e3dbbe6 commit 0e9fccd

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

postgres_exporter.rc

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
3+
# PROVIDE: postgres_exporter
4+
# REQUIRE: LOGIN
5+
# KEYWORD: shutdown
6+
#
7+
# rc-script for postgres_exporter
8+
#
9+
#
10+
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
11+
# to enable this service:
12+
#
13+
# postgres_exporter_enable (bool): Set to NO by default.
14+
# Set it to YES to enable postgres_exporter.
15+
# postgres_exporter_user (string): Set user that postgres_exporter will run under
16+
# Default is "nobody".
17+
# postgres_exporter_group (string): Set group that postgres_exporter will run under
18+
# Default is "nobody".
19+
# postgres_exporter_args (string): Set extra arguments to pass to postgres_exporter
20+
# Default is "".
21+
# postgres_exporter_listen_address (string):Set ip:port to listen on for web interface and telemetry.
22+
# Defaults to ":9187"
23+
# postgres_exporter_pg_user (string): Set the Postgres database user
24+
# Defaults to "postgres_exporter"
25+
# postgres_exporter_pg_pass (string): Set the Postgres datase password
26+
# Default is empty
27+
# postgres_exporter_pg_host (string): Set the Postgres database server
28+
# Defaults to "localhost"
29+
# postgres_exporter_pg_port (string): Set the Postgres database port
30+
# Defaults to "5432"
31+
32+
# Add extra arguments via "postgres_exporter_args" which could be choosen from:
33+
# (see $ postgres_exporter --help)
34+
#
35+
# -dumpmaps
36+
# Do not run, simply dump the maps.
37+
# -extend.query-path string
38+
# Path to custom queries to run.
39+
# -log.level value
40+
# Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
41+
# -version
42+
# print version and exit
43+
# -web.telemetry-path string
44+
# Path under which to expose metrics. (default "/metrics")
45+
# -log.format value
46+
# If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
47+
# -extend.query-path string
48+
# Path to custom queries to run.
49+
50+
51+
. /etc/rc.subr
52+
53+
name=postgres_exporter
54+
rcvar=postgres_exporter_enable
55+
56+
load_rc_config $name
57+
58+
: ${postgres_exporter_enable:="NO"}
59+
: ${postgres_exporter_user:="nobody"}
60+
: ${postgres_exporter_group:="nobody"}
61+
: ${postgres_exporter_args:=""}
62+
: ${postgres_exporter_listen_address:=":9187"}
63+
: ${postgres_exporter_pg_user:="postgres_exporter"}
64+
: ${postgres_exporter_pg_pass:=""}
65+
: ${postgres_exporter_pg_host:="localhost"}
66+
: ${postgres_exporter_pg_port:="5432"}
67+
68+
postgres_exporter_data_source_name="postgresql://${postgres_exporter_pg_user}:${postgres_exporter_pg_pass}@${postgres_exporter_pg_host}:${postgres_exporter_pg_port}/postgres?sslmode=disable"
69+
70+
71+
pidfile=/var/run/postgres_exporter.pid
72+
command="/usr/sbin/daemon"
73+
procname="/usr/local/bin/postgres_exporter"
74+
command_args="-p ${pidfile} /usr/bin/env DATA_SOURCE_NAME="${postgres_exporter_data_source_name}" ${procname} \
75+
-web.listen-address=${postgres_exporter_listen_address} \
76+
${postgres_exporter_args}"
77+
78+
start_precmd=postgres_exporter_startprecmd
79+
80+
postgres_exporter_startprecmd()
81+
{
82+
if [ ! -e ${pidfile} ]; then
83+
install -o ${postgres_exporter_user} -g ${postgres_exporter_group} /dev/null ${pidfile};
84+
fi
85+
}
86+
87+
load_rc_config $name
88+
run_rc_command "$1"
89+

0 commit comments

Comments
 (0)