Lines 8-24
Link Here
|
8 |
# to enable this service: |
8 |
# to enable this service: |
9 |
# |
9 |
# |
10 |
# prometheus_enable (bool) |
10 |
# prometheus_enable (bool) |
|
|
11 |
# Set it to YES to enable prometheus |
11 |
# Set to NO by default |
12 |
# Set to NO by default |
12 |
# Set it to YES to enable prometheus |
|
|
13 |
# prometheus_user (string) |
13 |
# prometheus_user (string) |
14 |
# Set user to run prometheus |
14 |
# Set user that prometheus will run under |
15 |
# Default is "%%PROMETHEUS_USER%%" |
15 |
# Default is "%%PROMETHEUS_USER%%" |
16 |
# prometheus_group (string) |
16 |
# prometheus_group (string) |
17 |
# Set group to run prometheus |
17 |
# Set group that own prometheus files |
18 |
# Default is "%%PROMETHEUS_GROUP%%" |
18 |
# Default is "%%PROMETHEUS_GROUP%%" |
19 |
# prometheus_data_dir (string) |
19 |
# prometheus_config (string) |
20 |
# Set dir to run prometheus in |
20 |
# Set full path to config file |
21 |
# Default is "%%PROMETHEUS_DB_DIR%%" |
21 |
# Default is "%%PREFIX%%/etc/prometheus.yml" |
|
|
22 |
# prometheus_pidfile (string) |
23 |
# Set full path to pid file |
24 |
# Default is "/var/run/prometheus.pid" |
25 |
# prometheus_syslog_output_enable (bool) |
26 |
# Set it to NO to disable syslog output |
27 |
# Set to YES by default |
28 |
# prometheus_syslog_output_tag (str) |
29 |
# Set syslog tag if syslog enabled |
30 |
# Default is "prometheus" |
31 |
# prometheus_syslog_output_priority (string) |
32 |
# Set syslog priority if syslog enabled |
33 |
# Default is "info" |
34 |
# prometheus_syslog_output_facility (string) |
35 |
# Set syslog facility if syslog enabled |
36 |
# Default is "daemon" |
22 |
# prometheus_consoles (string) |
37 |
# prometheus_consoles (string) |
23 |
# Set dir that contains Prometheus consoles |
38 |
# Set dir that contains Prometheus consoles |
24 |
# Default is "%%PROMETHEUS_CONSOLES_DIR%%" |
39 |
# Default is "%%PROMETHEUS_CONSOLES_DIR%%" |
Lines 25-30
Link Here
|
25 |
# prometheus_console_libraries (string) |
40 |
# prometheus_console_libraries (string) |
26 |
# Set dir containing Prometheus console libraries |
41 |
# Set dir containing Prometheus console libraries |
27 |
# Default is "%%PROMETHEUS_CONSOLE_LIBRARIES_DIR%%" |
42 |
# Default is "%%PROMETHEUS_CONSOLE_LIBRARIES_DIR%%" |
|
|
43 |
# prometheus_data_dir (string) |
44 |
# Set dir to run prometheus in |
45 |
# Default is "%%PROMETHEUS_DB_DIR%%" |
46 |
# prometheus_loglevel (string) |
47 |
# Set one of [debug, info, warn, error] |
48 |
# Default is "info" |
49 |
# prometheus_logformat (string) |
50 |
# Set one of [logfmt, json] |
51 |
# Default is "logfmt" |
52 |
# prometheus_env (string) |
53 |
# Set environment variables used with prometheus |
54 |
# Default is "" |
28 |
# prometheus_args (string) |
55 |
# prometheus_args (string) |
29 |
# Set additional command line arguments |
56 |
# Set additional command line arguments |
30 |
# Default is "" |
57 |
# Default is "" |
Lines 40-106
Link Here
|
40 |
: ${prometheus_user:="%%PROMETHEUS_USER%%"} |
67 |
: ${prometheus_user:="%%PROMETHEUS_USER%%"} |
41 |
: ${prometheus_group:="%%PROMETHEUS_GROUP%%"} |
68 |
: ${prometheus_group:="%%PROMETHEUS_GROUP%%"} |
42 |
: ${prometheus_config:="%%PREFIX%%/etc/prometheus.yml"} |
69 |
: ${prometheus_config:="%%PREFIX%%/etc/prometheus.yml"} |
43 |
: ${prometheus_data_dir:="%%PROMETHEUS_DB_DIR%%"} |
70 |
: ${prometheus_pidfile:="/var/run/prometheus.pid"} |
|
|
71 |
: ${prometheus_syslog_output_enable:="YES"} |
44 |
: ${prometheus_consoles_dir:="%%PROMETHEUS_CONSOLES_DIR%%"} |
72 |
: ${prometheus_consoles_dir:="%%PROMETHEUS_CONSOLES_DIR%%"} |
45 |
: ${prometheus_console_libraries_dir:="%%PROMETHEUS_CONSOLE_LIBRARIES_DIR%%"} |
73 |
: ${prometheus_console_libraries_dir:="%%PROMETHEUS_CONSOLE_LIBRARIES_DIR%%"} |
46 |
: ${prometheus_args:=""} |
74 |
: ${prometheus_data_dir:="%%PROMETHEUS_DB_DIR%%"} |
|
|
75 |
: ${prometheus_loglevel:="info"} |
76 |
: ${prometheus_logformat:="logfmt"} |
47 |
|
77 |
|
48 |
pidfile="/var/run/${name}.pid" |
78 |
if checkyesno prometheus_syslog_output_enable; then |
|
|
79 |
if [ -n "${prometheus_syslog_output_tag}" ]; then |
80 |
prometheus_syslog_output_flags="-T ${prometheus_syslog_output_tag}" |
81 |
else |
82 |
prometheus_syslog_output_flags="-T ${name}" |
83 |
fi |
84 |
if [ -n "${prometheus_syslog_output_priority}" ]; then |
85 |
prometheus_syslog_output_flags="${prometheus_syslog_output_flags} -s ${prometheus_syslog_output_priority}" |
86 |
fi |
87 |
if [ -n "${prometheus_syslog_output_facility}" ]; then |
88 |
prometheus_syslog_output_flags="${prometheus_syslog_output_flags} -l ${prometheus_syslog_output_facility}" |
89 |
fi |
90 |
fi |
91 |
|
92 |
pidfile="${prometheus_pidfile}" |
49 |
required_files="${prometheus_config}" |
93 |
required_files="${prometheus_config}" |
|
|
94 |
|
95 |
procname="%%PREFIX%%/bin/prometheus" |
50 |
command="/usr/sbin/daemon" |
96 |
command="/usr/sbin/daemon" |
51 |
procname="%%PREFIX%%/bin/${name}" |
97 |
command_args="-f ${prometheus_syslog_output_flags} -p ${pidfile} -t ${name} \ |
52 |
sig_reload="HUP" |
98 |
/usr/bin/env ${prometheus_env} ${procname} \ |
|
|
99 |
--config.file=${prometheus_config} \ |
100 |
--web.console.templates=${prometheus_consoles_dir} \ |
101 |
--web.console.libraries=${prometheus_console_libraries_dir} \ |
102 |
--storage.tsdb.path=${prometheus_data_dir} \ |
103 |
--log.level=${prometheus_loglevel} \ |
104 |
--log.format=${prometheus_logformat} \ |
105 |
${prometheus_args}" |
106 |
|
107 |
start_precmd="prometheus_start_precmd" |
53 |
extra_commands="reload" |
108 |
extra_commands="reload" |
54 |
command_args="-p ${pidfile} -m 3 -T ${name} \ |
|
|
55 |
/usr/bin/env ${procname} \ |
56 |
--config.file=${prometheus_config} \ |
57 |
--storage.tsdb.path=${prometheus_data_dir} \ |
58 |
--web.console.templates=${prometheus_consoles_dir} \ |
59 |
--web.console.libraries=${prometheus_console_libraries_dir} \ |
60 |
${prometheus_args}" |
61 |
|
109 |
|
62 |
start_precmd=prometheus_startprecmd |
110 |
# This checks for the existence of a prometheus 1.x data at the |
63 |
|
|
|
64 |
# This checks for the existence of a prometheus 1.x data dir at the |
65 |
# $prometheus_data_dir location. If one is found, Prometheus will not start. |
111 |
# $prometheus_data_dir location. If one is found, Prometheus will not start. |
66 |
prometheus_check_data_dir_version() |
112 |
prometheus_check_data_version() |
67 |
{ |
113 |
{ |
68 |
local data_dir_version_file="${prometheus_data_dir}/VERSION" |
114 |
local _version |
|
|
115 |
local _version_file="${prometheus_data_dir}/VERSION" |
69 |
|
116 |
|
70 |
if [ -f "${data_dir_version_file}" ]; then |
117 |
if [ -f "${_version_file}" ]; then |
71 |
local data_dir_version="0" |
118 |
read _version < "${_version_file}" |
72 |
|
119 |
|
73 |
read data_dir_version < "${data_dir_version_file}" |
120 |
if [ "${_version}" = "1" ]; then |
74 |
|
121 |
return 1 |
75 |
if [ "${data_dir_version}" = "1" ]; then |
122 |
fi |
76 |
return 1 |
123 |
fi |
77 |
fi |
|
|
78 |
fi |
79 |
} |
124 |
} |
80 |
|
125 |
|
81 |
prometheus_startprecmd() |
126 |
prometheus_start_precmd() |
82 |
{ |
127 |
{ |
83 |
if [ ! -e ${pidfile} ]; then |
128 |
if [ ! -e "${pidfile}" ]; then |
84 |
install \ |
129 |
install -m 0600 -o "${prometheus_user}" -g "${prometheus_group}" /dev/null "${pidfile}" |
85 |
-o ${prometheus_user} \ |
130 |
fi |
86 |
-g ${prometheus_group} \ |
131 |
if [ ! -d "${prometheus_data_dir}" ]; then |
87 |
/dev/null ${pidfile}; |
132 |
install -d -m 750 -o "${prometheus_user}" -g "${prometheus_group}" "${prometheus_data_dir}" |
88 |
fi |
133 |
else |
89 |
if [ ! -d ${prometheus_data_dir} ]; then |
134 |
# Ensure it's not a prometheus 1.x data |
90 |
install \ |
135 |
if [ ! prometheus_check_data_version ]; then |
91 |
-d \ |
136 |
err 1 "Found \"net-mgmt/prometheus1\" data, refusing to start." |
92 |
-o ${prometheus_user} \ |
137 |
fi |
93 |
-g ${prometheus_group} \ |
138 |
fi |
94 |
-m 750 \ |
|
|
95 |
${prometheus_data_dir} |
96 |
else |
97 |
# The directory already existed. Ensure it's not a prometheus 1.x |
98 |
# data dir. |
99 |
if ! prometheus_check_data_dir_version; then |
100 |
err 1 "Found net-mgmt/prometheus1 data dir, refusing to start." |
101 |
fi |
102 |
fi |
103 |
} |
139 |
} |
104 |
|
140 |
|
105 |
load_rc_config $name |
|
|
106 |
run_rc_command "$1" |
141 |
run_rc_command "$1" |