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