prometheus: Update default tsdb directory handling
authorAlex Simkin <sashasimkin@gmail.com>
Sat, 31 Jul 2021 08:43:58 +0000 (11:43 +0300)
committerPaul Spooren <mail@aparcar.org>
Thu, 9 Sep 2021 18:17:08 +0000 (08:17 -1000)
Use /srv/prometheus instead of /data, because user `prometheus` doens't
have permissions to create `/data/` in `/`.

Instead this commit puts prometheus data into `/srv/prometheus` by
default, which is a cleaner path, and it'll create tsdb path & then assign
required permissions on each prometheus service start.

This way, also, the cases when users re-configure tsdb to point to
external USB - it'll also be created and assigned required permissions for
prometheus.

Signed-off-by: Alex Simkin <sashasimkin@gmail.com>
utils/prometheus/Makefile
utils/prometheus/files/etc/init.d/prometheus
utils/prometheus/files/etc/uci-defaults/prometheus-defaults

index 6f4c4bd29cedff1286eaa7b86739dde83799014a..b06f667dced8ed7fbd8478662221e91bb9a825fb 100644 (file)
@@ -47,6 +47,9 @@ Prometheus, a Cloud Native Computing Foundation project, is a systems and
 service monitoring system. It collects metrics from configured targets at given
 intervals, evaluates rule expressions, displays the results, and can trigger
 alerts if some condition is observed to be true.
+
+Default tsdb path is /srv/prometheus, you might want to edit /etc/config/prometheus
+in order to place it on USB storage or external SD card.
 endef
 
 define Package/prometheus/install
index a652ddfc60c057da698681dfa6fc5751e4ce2570..99b4640b235e9670f1b3cf280e2f1c42ed71698c 100755 (executable)
@@ -12,8 +12,14 @@ start_service() {
        local web_listen_address
        config_load "prometheus"
        config_get config_file prometheus config_file "$CONFFILE"
-       config_get storage_tsdb_path prometheus storage_tsdb_path "/data"
+       config_get storage_tsdb_path prometheus storage_tsdb_path "/srv/prometheus"
        config_get web_listen_address prometheus web_listen_address "127.0.0.1:9090"
+       
+       # Create tsdb dir & permissions if needed
+       if [ ! -d "$storage_tsdb_path" ]; then
+               mkdir "$storage_tsdb_path"
+               chown prometheus:prometheus "$storage_tsdb_path"
+       fi;
 
        procd_open_instance
        procd_set_param command "$PROG"
index 2ce745259e74004cbe7f5ad27edcea948bd15fad..9c537d2e829c9d484b08235b8b9513036739bf0c 100755 (executable)
@@ -6,7 +6,7 @@ uci -q get prometheus.prometheus || {
        uci -q batch <<EOF
        set prometheus.prometheus=prometheus
        set prometheus.prometheus.config_file='/etc/prometheus.yml'
-       set prometheus.prometheus.storage_tsdb_path='/data'
+       set prometheus.prometheus.storage_tsdb_path='/srv/prometheus'
        set prometheus.prometheus.web_listen_address='127.0.0.1:9090'
        commit prometheus
 EOF