Skip to content

Commit a143430

Browse files
committed
Back up metrics config
1 parent 48b5200 commit a143430

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

dappnode_package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"name": "db-data",
3030
"path": "/var/lib/postgresql/data",
3131
"service": "db"
32+
},
33+
{
34+
"name": "metrics-config",
35+
"path": "/config/user",
36+
"service": "metrics"
3237
}
3338
]
3439
}

metrics/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ FROM victoriametrics/vmagent:v1.101.0
99
ARG NETWORK
1010

1111
ENV ASSETS_DIR=/assets \
12-
CONFIG_FILE=/config/${NETWORK}/vmagent.yml
12+
CONFIG_FILE=/config/${NETWORK}/vmagent.yml \
13+
USER_SETTINGS_FILE=/config/user/settings.env
1314

1415
COPY --from=assets ${ASSETS_DIR}/ ${ASSETS_DIR}/
1516
COPY config/ /config/

metrics/entrypoint.sh

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
11
#!/bin/sh
22

3-
if [ "${SHUTTER_PUSH_METRICS_ENABLED}" = "false" ]; then
4-
echo "[INFO | metrics] Metrics push is disabled"
5-
exit 0
6-
fi
3+
update_user_settings() {
4+
key=$1
5+
value=$(eval echo \$$key)
6+
7+
if [ ! -f "$USER_SETTINGS_FILE" ]; then
8+
touch "$USER_SETTINGS_FILE"
9+
fi
10+
11+
if [ -z "$value" ]; then
12+
echo "[INFO | metrics] Skipped updating $key in user settings file (empty value)"
13+
return 1
14+
fi
15+
16+
if grep -q "^$key=" "$USER_SETTINGS_FILE"; then
17+
# Update the existing key
18+
sed -i "s/^$key=.*/$key=$value/" "$USER_SETTINGS_FILE"
19+
echo "[INFO | metrics] Updated $key to $value in $USER_SETTINGS_FILE"
20+
else
21+
# Add the new key
22+
echo "$key=$value" >>"$USER_SETTINGS_FILE"
23+
echo "[INFO | metrics] Added $key=$value to $USER_SETTINGS_FILE"
24+
fi
25+
}
26+
27+
source_envs() {
28+
set -a
729

8-
set -eu
30+
# shellcheck disable=SC1091
31+
if [ -f "${ASSETS_DIR}/variables.env" ]; then
32+
. "${ASSETS_DIR}/variables.env"
933

10-
set -a
34+
else
35+
echo "[ERROR | configure] Missing variables file (${ASSETS_DIR}/variables.env)"
36+
exit 1
37+
fi
1138

12-
# shellcheck disable=SC1091
13-
if [ -f "${ASSETS_DIR}/variables.env" ]; then
14-
. "${ASSETS_DIR}/variables.env"
15-
else
16-
echo "[ERROR | configure] Missing variables file (${ASSETS_DIR}/variables.env)"
17-
exit 1
39+
if [ -z "${_ASSETS_VERSION:-}" ]; then
40+
_ASSETS_VERSION="$(cat /assets/version)"
41+
fi
42+
43+
# shellcheck disable=SC1090
44+
. "$USER_SETTINGS_FILE"
45+
46+
set +a
47+
}
48+
49+
# Create an empty JSON file in path USER_SETTINGS_FILE if it does not exist
50+
if [ ! -f "${USER_SETTINGS_FILE}" ]; then
51+
echo "{}" >"${USER_SETTINGS_FILE}"
1852
fi
1953

20-
set +a
54+
update_user_settings "PUSHGATEWAY_URL" "${PUSHGATEWAY_URL}"
55+
update_user_settings "PUSHGATEWAY_USERNAME" "${PUSHGATEWAY_USERNAME}"
56+
update_user_settings "PUSHGATEWAY_PASSWORD" "${PUSHGATEWAY_PASSWORD}"
2157

22-
# TODO: Update script with upstream version
23-
if [ -z "${_ASSETS_VERSION:-}" ]; then
24-
_ASSETS_VERSION="$(cat /assets/version)"
25-
export _ASSETS_VERSION
58+
if [ "${SHUTTER_PUSH_METRICS_ENABLED}" = "false" ]; then
59+
echo "[INFO | metrics] Metrics push is disabled"
60+
exit 0
2661
fi
2762

63+
source_envs
64+
2865
exec /vmagent-prod \
2966
-promscrape.config="${CONFIG_FILE}" \
3067
-remoteWrite.url="${PUSHGATEWAY_URL}" \

0 commit comments

Comments
 (0)