From 3ef43937080dcd10cea7d9c9cf4d4dbbc1a5e6cc Mon Sep 17 00:00:00 2001 From: yorickdowne <71337066+yorickdowne@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:49:19 -0400 Subject: [PATCH] Updated SSV dashboards (#1914) * Updated SSV dashboards * Detect if sudo is not available --- ethd | 51 ++++++++++++++++++++++++++++++++++++-------- grafana/provision.sh | 31 ++++++++++++++++----------- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/ethd b/ethd index db8092ab..f68103f8 100755 --- a/ethd +++ b/ethd @@ -43,15 +43,29 @@ determine_distro() { __distro=$(echo "$__distro" | tr "[:upper:]" "[:lower:]") if [[ "$__distro" = "ubuntu" ]]; then - if ! dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -q "ok installed"; then - ${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install lsb-release + if [ "$__cannot_sudo" -eq 0 ]; then + if ! dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -q "ok installed"; then + echo "Installing lsb-release" + ${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install lsb-release + fi + fi + if [ -n "$(command -v lsb_release 2>/dev/null)" ]; then + __os_major_version=$(lsb_release -r | cut -d: -f2 | sed s/'^\t'// | cut -d. -f1) + else + __os_major_version=24 # Without sudo and lsb_release let's just skip the check fi - __os_major_version=$(lsb_release -r | cut -d: -f2 | sed s/'^\t'// | cut -d. -f1) elif [[ "$__distro" =~ "debian" ]]; then - if ! dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -q "ok installed"; then - ${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install lsb-release + if [ "$__cannot_sudo" -eq 0 ]; then + if ! dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -q "ok installed"; then + echo "Installing lsb-release" + ${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install lsb-release + fi + fi + if [ -n "$(command -v lsb_release 2>/dev/null)" ]; then + __os_major_version=$(lsb_release -r | cut -f2) + else + __os_major_version=12 # Without sudo and lsb_release let's just skip the check fi - __os_major_version=$(lsb_release -r | cut -f2) fi } @@ -80,6 +94,10 @@ handle_docker_sudo() { fi __docker_sudo="" if ! docker images >/dev/null 2>&1; then + if [ "$__cannot_sudo" -eq 1 ]; then + echo "Cannot call Docker and cannot use sudo. Please make your user part of the docker group" + exit 1 + fi echo "Will use sudo to access Docker" __docker_sudo="sudo" fi @@ -87,12 +105,18 @@ handle_docker_sudo() { handle_root() { + __cannot_sudo=0 if [ "${EUID}" -eq 0 ]; then __as_owner="sudo -u ${OWNER}" __auto_sudo="" else __as_owner="" - __auto_sudo="sudo" + if groups | grep -q '\bsudo\b' || groups | grep -q '\badmin\b'; then + __auto_sudo="sudo" + else + __auto_sudo="" + __cannot_sudo=1 + fi fi } @@ -204,7 +228,13 @@ prep_conffiles() { fi # Make sure local user owns the dkg output dir and everything in it if find .eth/dkg_output \! -user "${OWNER}" -o \! -group "${OWNER_GROUP}" | grep -q .; then - ${__auto_sudo} chown -R "${OWNER}:${OWNER_GROUP}" .eth/dkg_output + if [ "$__cannot_sudo" -eq 0 ]; then + echo "Fixing ownership of .eth/dkg_output" + ${__auto_sudo} chown -R "${OWNER}:${OWNER_GROUP}" .eth/dkg_output + ${__auto_sudo} chmod -R 755 .eth/dkg_output + else + echo "Ownership of .eth/dkg_output should be fixed, but this user can't sudo" + fi fi # Make sure the dkg output dir and its contents are mod 0755 if find .eth/dkg_output \! -perm 755 | grep -q .; then @@ -251,7 +281,10 @@ install-bash-completions() { install() { - + if [ "$__cannot_sudo" -eq 1 ]; then + echo "The install command requires the user to be part of the sudo group, or on macOS the admin group" + exit 1 + fi if [[ "$__distro" = "ubuntu" ]]; then ${__auto_sudo} apt-get update ${__auto_sudo} apt-get install -y ca-certificates curl gnupg whiptail chrony pkg-config diff --git a/grafana/provision.sh b/grafana/provision.sh index 65be2f84..7dc085bc 100755 --- a/grafana/provision.sh +++ b/grafana/provision.sh @@ -27,15 +27,18 @@ case "$CLIENT" in # lighthouse_summary __url='https://raw.githubusercontent.com/sigp/lighthouse-metrics/master/dashboards/Summary.json' __file='/etc/grafana/provisioning/dashboards/lighthouse_summary.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lighthouse Summary"' | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lighthouse Summary"' \ + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" # lighthouse_validator_client __url='https://raw.githubusercontent.com/sigp/lighthouse-metrics/master/dashboards/ValidatorClient.json' __file='/etc/grafana/provisioning/dashboards/lighthouse_validator_client.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lighthouse Validator Client"' | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lighthouse Validator Client"' \ + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" # lighthouse_validator_monitor __url='https://raw.githubusercontent.com/sigp/lighthouse-metrics/master/dashboards/ValidatorMonitor.json' __file='/etc/grafana/provisioning/dashboards/lighthouse_validator_monitor.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lighthouse Validator Monitor"' | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lighthouse Validator Monitor"' \ + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" ;;& *teku* ) # teku_overview @@ -49,13 +52,15 @@ case "$CLIENT" in # nimbus_dashboard __url='https://raw.githubusercontent.com/status-im/nimbus-eth2/master/grafana/beacon_nodes_Grafana_dashboard.json' __file='/etc/grafana/provisioning/dashboards/nimbus_dashboard.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Nimbus Dashboard"' | jq 'walk(if . == "${DS_PROMETHEUS-PROXY}" then "Prometheus" else . end)' >"${__file}" + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Nimbus Dashboard"' \ + | jq 'walk(if . == "${DS_PROMETHEUS-PROXY}" then "Prometheus" else . end)' >"${__file}" ;;& *lodestar* ) # lodestar summary __url='https://raw.githubusercontent.com/ChainSafe/lodestar/stable/dashboards/lodestar_summary.json' __file='/etc/grafana/provisioning/dashboards/lodestar_summary.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lodestar Dashboard"' | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' \ + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Lodestar Dashboard"' \ + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' \ | jq '.templating.list[3].query |= "consensus" | .templating.list[4].query |= "validator"' \ | jq 'walk(if . == "prometheus_local" then "Prometheus" else . end)' >"${__file}" ;;& @@ -63,7 +68,8 @@ case "$CLIENT" in # geth_dashboard __url='https://gist.githubusercontent.com/karalabe/e7ca79abdec54755ceae09c08bd090cd/raw/3a400ab90f9402f2233280afd086cb9d6aac2111/dashboard.json' __file='/etc/grafana/provisioning/dashboards/geth_dashboard.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Geth Dashboard"' | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Geth Dashboard"' \ + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" ;;& *erigon* ) # erigon_dashboard @@ -77,7 +83,8 @@ case "$CLIENT" in __revision=$(wget -t 3 -T 10 -qO - https://grafana.com/api/dashboards/${__id} | jq .revision) __url="https://grafana.com/api/dashboards/${__id}/revisions/${__revision}/download" __file='/etc/grafana/provisioning/dashboards/besu_dashboard.json' - wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Besu Dashboard"' | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" + wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "Besu Dashboard"' \ + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" ;;& *reth* ) # reth_dashboard @@ -106,16 +113,14 @@ case "$CLIENT" in ;;& *ssv.yml* ) # SSV Operator Dashboard - __url='https://raw.githubusercontent.com/bloxapp/ssv/main/monitoring/grafana/dashboard_ssv_operator_performance.json' + __url='https://raw.githubusercontent.com/ssvlabs/ssv/main/monitoring/grafana/dashboard_ssv_operator_performance.json' __file='/etc/grafana/provisioning/dashboards/ssv_operator_dashboard.json' wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "SSV Operator Performance Dashboard"' \ - | jq '.templating.list[0].current |= {selected: false, text: "ssv-node", value: "ssv-node"} | .templating.list[0].options = [ { "selected": true, "text": "ssv-node", "value": "ssv-node" } ] | .templating.list[0].query = "ssv-node"' \ - | sed 's/eXfXfqH7z/Prometheus/g' >"${__file}" - __url='https://raw.githubusercontent.com/bloxapp/ssv/main/monitoring/grafana/dashboard_ssv_node.json' + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" + __url='https://raw.githubusercontent.com/ssvlabs/ssv/main/monitoring/grafana/dashboard_ssv_node.json' __file='/etc/grafana/provisioning/dashboards/ssv_node_dashboard.json' wget -t 3 -T 10 -qcO - "${__url}" | jq '.title = "SSV Node Dashboard"' \ - | jq '.templating.list[0].current |= {selected: false, text: "ssv-node", value: "ssv-node"} | .templating.list[0].options = [ { "selected": true, "text": "ssv-node", "value": "ssv-node" } ] | .templating.list[0].query = "ssv-node"' \ - | sed 's/eXfXfqH7z/Prometheus/g' >"${__file}" + | jq 'walk(if . == "${DS_PROMETHEUS}" then "Prometheus" else . end)' >"${__file}" ;;& !(*grafana-rootless*) ) # cadvisor and node exporter dashboard