diff --git a/net-mgmt/victoria-metrics/files/prometheus.yml.sample b/net-mgmt/victoria-metrics/files/prometheus.yml.sample new file mode 100644 index 000000000000..bc0ffde40d9c --- /dev/null +++ b/net-mgmt/victoria-metrics/files/prometheus.yml.sample @@ -0,0 +1,17 @@ +# Global configuration. +global: + scrape_interval: 15s + evaluation_interval: 15s + +# A scrape configuration containing exactly one endpoint to scrape: +# the vmagent itself. +scrape_configs: + - job_name: vmagent + scrape_interval: 60s + scrape_timeout: 30s + metrics_path: "/metrics" + static_configs: + - targets: + - 127.0.0.1:8429 + labels: + project: vmagent diff --git a/net-mgmt/victoria-metrics/files/vmagent.in b/net-mgmt/victoria-metrics/files/vmagent.in index 06cf5ecbf26d..df1fb5a9d6dd 100644 --- a/net-mgmt/victoria-metrics/files/vmagent.in +++ b/net-mgmt/victoria-metrics/files/vmagent.in @@ -1,66 +1,82 @@ #!/bin/sh -# PROVIDE: victoria_vmagent +# PROVIDE: vmagent # REQUIRE: NETWORK # BEFORE: DAEMON . /etc/rc.subr -name="victoria_vmagent" +name="vmagent" desc="Fast, cost-effective, and scalable time series database" -rcvar="victoria_vmagent_enable" +rcvar="vmagent_enable" pidfile="/var/run/${name}.pid" daemon_pidfile="/var/run/${name}-daemon.pid" logdir="/var/log/${name}" -logfile="${logdir}/victoria_vmagent.log" +logfile="${logdir}/vmagent.log" command="%%PREFIX%%/bin/vmagent" -victoria_vmagent_args=${victoria_vmagent_args-"--remoteWrite.tmpDataPath=/tmp --promscrape.config=%%PREFIX%%/etc/prometheus/prometheus.yml --remoteWrite.url=http://127.0.0.1:8429/api/v1/write -httpListenAddr=:9429 --memory.allowedPercent=80"} -victoria_vmagent_user="%%VICTORIA_USER%%" +vmagent_args=${vmagent_args-"--remoteWrite.tmpDataPath=/tmp --promscrape.config=%%PREFIX%%/etc/prometheus/prometheus.yml --remoteWrite.url=http://127.0.0.1:8429/api/v1/write -httpListenAddr=:9429 --memory.allowedPercent=80"} +vmagent_user="%%VICTORIA_USER%%" load_rc_config ${name} +restart_precmd="checkconfig" +start_precmd="checkconfig" +checkconfig_cmd="checkconfig" start_cmd="start" stop_cmd="stop" status_cmd="status" -extra_commands="reload" +extra_commands="checkconfig reload" + +checkconfig() +{ + local _ret + + /usr/bin/su -m ${vmagent_user} -c "${command} ${vmagent_args} -promscrape.config.dryRun" > /dev/null 2>&1 + _ret=$? + if [ ${_ret} -ne 0 ]; then + echo "${name} checkconfig failed:" + echo "/usr/bin/su -m ${vmagent_user} -c \"${command} ${vmagent_args} -promscrape.config.dryRun\"" + exit ${_ret} + fi +} start() { [ ! -d ${logdir} ] && mkdir -p ${logdir} touch ${logfile} - chown ${victoria_vmagent_user} ${logdir} ${logfile} - /usr/sbin/daemon -u ${victoria_vmagent_user} -f -R5 -p ${pidfile} -P ${daemon_pidfile} -o ${logfile} ${command} ${victoria_vmagent_args} + chown ${vmagent_user} ${logdir} ${logfile} + /usr/sbin/daemon -u ${vmagent_user} -f -R5 -p ${pidfile} -P ${daemon_pidfile} -o ${logfile} ${command} ${vmagent_args} } stop() { if [ -f "${daemon_pidfile}" ]; then pids=$( pgrep -F ${daemon_pidfile} 2>&1 ) _err=$? [ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${daemon_pidfile} fi if [ -f "${pidfile}" ]; then pids=$( pgrep -F ${pidfile} 2>&1 ) _err=$? [ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${pidfile} fi } status() { if [ -f "${pidfile}" ]; then pids=$( pgrep -F ${pidfile} 2>&1 ) _err=$? if [ ${_err} -eq 0 ]; then echo "${name} is running as pid ${pids}" exit 0 else echo "wrong pid: ${pids}" exit 1 fi else echo "no pidfile $pidfile" exit 1 fi } run_rc_command "$1" diff --git a/net-mgmt/vmutils/Makefile b/net-mgmt/vmutils/Makefile index ee41121132de..cb0c6e580113 100644 --- a/net-mgmt/vmutils/Makefile +++ b/net-mgmt/vmutils/Makefile @@ -1,23 +1,28 @@ # Created by: Alexey Dokuchaev PORTNAME= vmutils +PORTREVISION= 1 + COMMENT= Ancillary utilities and agent for VictoriaMetrics USE_RC_SUBR= vmagent DESCR= ${.CURDIR}/pkg-descr PLIST= ${.CURDIR}/pkg-plist do-install: .for p in agent alert auth backup ctl restore ${INSTALL_PROGRAM} ${WRKSRC}/bin/vm${p}-pure \ ${STAGEDIR}${PREFIX}/bin/vm${p} .endfor + @${MKDIR} ${STAGEDIR}${PREFIX}/etc/prometheus + ${INSTALL_DATA} ${FILESDIR}/prometheus.yml.sample \ + ${STAGEDIR}${PREFIX}/etc/prometheus do-install-DOCS-on: @${MKDIR} ${STAGEDIR}${DOCSDIR} ${INSTALL_DATA} ${INSTALL_WRKSRC}/docs/vm* ${STAGEDIR}${DOCSDIR} MASTERDIR= ${.CURDIR}/../victoria-metrics .include "${MASTERDIR}/Makefile" diff --git a/net-mgmt/vmutils/pkg-plist b/net-mgmt/vmutils/pkg-plist index 658c55bab447..04166109880a 100644 --- a/net-mgmt/vmutils/pkg-plist +++ b/net-mgmt/vmutils/pkg-plist @@ -1,18 +1,19 @@ bin/vmagent bin/vmalert bin/vmauth bin/vmbackup bin/vmctl bin/vmrestore +@sample etc/prometheus/prometheus.yml.sample %%PORTDOCS%%%%DOCSDIR%%/vmagent.md %%PORTDOCS%%%%DOCSDIR%%/vmagent.png %%PORTDOCS%%%%DOCSDIR%%/vmalert.md %%PORTDOCS%%%%DOCSDIR%%/vmauth.md %%PORTDOCS%%%%DOCSDIR%%/vmbackup.md %%PORTDOCS%%%%DOCSDIR%%/vmbackupmanager.md %%PORTDOCS%%%%DOCSDIR%%/vmctl.md %%PORTDOCS%%%%DOCSDIR%%/vmgateway-access-control.jpg %%PORTDOCS%%%%DOCSDIR%%/vmgateway-overview.jpeg %%PORTDOCS%%%%DOCSDIR%%/vmgateway-rate-limiting.jpg %%PORTDOCS%%%%DOCSDIR%%/vmgateway.md %%PORTDOCS%%%%DOCSDIR%%/vmrestore.md