Last active
May 23, 2020 18:21
-
-
Save ilap/c04314fa508828f4b6d31ef8f2c0255d to your computer and use it in GitHub Desktop.
Setup Shelley Monitoring (cardano-node)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#--------------------------------------------------------------------- | |
# File: setup_shelley_monitoring.sh | |
# Created: 2019/10/17 | |
# Creator: ilap | |
#===================================================================== | |
# UPDATES: | |
# - 21/05/2020: Updated to the `cardano-node` i.e. Haskell Shelley | |
# | |
# DESCRIPTION: | |
# | |
# This script downloads and configures the required files | |
# for monitoring a Shelley node by using grafana/prometheus. | |
# | |
###################################################################### | |
#### Functions | |
###################################################################### | |
clean_up () { | |
echo "Cleaning up...." >&2 | |
$DBG rm -rf "${TMP_DIR}" | |
RES=$1 | |
exit ${RES:=127} | |
} | |
message() { | |
echo -e "$*" >&2 | |
exit 127 | |
} | |
get_idx () { | |
case $OSTYPE in | |
"darwin"*) | |
IDX=0 | |
;; | |
"linux-gnu"*) | |
if [[ $HOSTTYPE == *"x86_64"* ]]; then | |
IDX=1 | |
elif [[ $HOSTTYPE == *"arm"* ]]; then | |
IDX=2 | |
else | |
message "The $HOSTTYPE is not supported" | |
fi | |
;; | |
*) | |
message "The \"$OSTYPE\" OS is not supported" | |
;; | |
esac | |
echo $IDX | |
} | |
dl() { | |
DL_URL="${1}" | |
OUTPUT="${TMP_DIR}/`basename \"${DL_URL}\"`" | |
shift | |
case ${DL} in | |
*"wget"*) | |
wget --no-check-certificate --output-document="${OUTPUT}" "${DL_URL}";; | |
*) | |
( cd "$TMP_DIR" && curl -JOL "$DL_URL" --silent );; | |
esac | |
} | |
###################################################################### | |
#### MAIN | |
###################################################################### | |
DBG=echo | |
unset DBG # For debug only | |
PROM_VER=2.18.1 | |
GRAF_VER=7.0.0 | |
NEXP_VER=0.18.1 | |
if [ -z "$1" ] ; then | |
message "usage: $(basename "$0") <project name> # e.g. $(basename "$0") monitoring" | |
fi | |
CURL=$(which curl) | |
WGET=$(which wget) | |
DL=${CURL:=$WGET} | |
if [ -z "$DL" ]; then | |
message 'You need to have "wget" or "curl" to be installed\nand accessable by PATH environment to continue...\nExiting.' | |
fi | |
PROJ_DIR="$(pwd)/$1" | |
PROJ_NAME="$(basename "$1")" | |
TMP_DIR=$(mktemp -d "/tmp/$PROJ_NAME.XXXXXXXX") | |
# Default parameters | |
IP=127.0.0.1 | |
PORT=9001 | |
export IP PORT TMP_DIR | |
while : | |
do | |
echo "Please use \"hasPrometeus\"'s IP:PORT from node's config file." | |
read -rp "What is the ip of the node (default:${IP})? " ip | |
read -rp "What port is used for prometheus metrics of the node running on ${IP:="${ip}"}'s (Default is ${PORT})?" port | |
echo "Is this correct? http://${ip:-"${IP}"}:${port:-"${PORT}"}/metrics" | |
read -rp "Do you want to continue? [Y/n/q] " answer | |
case ${answer:="Y"} in | |
[yY]*) | |
IP=${ip:-"${IP}"} | |
PORT=${port:-"${PORT}"} | |
break;; | |
[nN]* ) | |
continue;; | |
[qQ]* ) | |
exit;; | |
* ) | |
echo "Please enter [yY](es), [nN](o) or [qQ](quit).";; | |
esac | |
done | |
ARCHS=("darwin-amd64" "linux-amd64" "linux-armv6") | |
IDX=$(get_idx) | |
PROM_URL="https://github.com/prometheus/prometheus/releases/download/v$PROM_VER/prometheus-$PROM_VER.${ARCHS[IDX]}.tar.gz" | |
GRAF_URL="https://dl.grafana.com/oss/release/grafana-$GRAF_VER.${ARCHS[IDX]}.tar.gz" | |
NEXP="node_exporter" | |
NEXP_URL="https://github.com/prometheus/$NEXP/releases/download/v$NEXP_VER/$NEXP-$NEXP_VER.${ARCHS[IDX]}.tar.gz" | |
UMED_DB="Haskel_Node_SKY_Relay1_Dash.json" | |
UMED_DB_URL="https://raw.githubusercontent.com/Oqulent/SkyLight-Pool/master/$UMED_DB" | |
trap clean_up SIGHUP SIGINT SIGQUIT SIGTRAP SIGABRT SIGTERM | |
echo -e "Downloading prometheus..." >&2 | |
$DBG dl "$PROM_URL" | |
echo -e "Downloading grafana..." >&2 | |
$DBG dl "$GRAF_URL" | |
echo -e "Downloading exporter(s) and grafana dashboard(s)..." >&2 | |
$DBG dl "$NEXP_URL" | |
$DBG dl "$UMED_DB_URL" | |
PROM_DIR="$PROJ_DIR/prometheus" | |
GRAF_DIR="$PROJ_DIR/grafana" | |
EXP_DIR="$PROJ_DIR/exporters" | |
cd "$TMP_DIR" && mkdir -p "$PROJ_DIR"/{exporters,prometheus,grafana} | |
tar zxC "$PROM_DIR" -f ./*prome*gz --strip-components 1 | |
tar zxC "$GRAF_DIR" -f ./*graf*gz --strip-components 1 | |
tar zxC "$EXP_DIR" -f ./*node_exporter*gz "$NEXP-$NEXP_VER.${ARCHS[IDX]}/$NEXP" --strip-components 1 | |
echo -e "Configuring components" >&2 | |
chmod +x "$PROJ_DIR"/exporters/* | |
cp -pr "$UMED_DB" "$PROJ_DIR/" | |
cd "$PROJ_DIR" || exit 127 | |
NEXP_PORT=$(( PORT + 1 )) | |
HOSTNAME=$(hostname) | |
sed -i -e 's@\(^scrape_configs:.*\)@\1\ | |
- job_name: '\'${HOSTNAME}_node\''\ | |
static_configs:\ | |
- targets: ['\'${IP}:${PORT}\'']\ | |
- job_name: '\'${HOSTNAME}_node_exp\''\ | |
static_configs:\ | |
- targets: ['\'${IP}:${NEXP_PORT}\'']@g' "${PROM_DIR}"/prometheus.yml | |
cat > start_all.sh <<EOF | |
#!/bin/bash | |
#1. exporter | |
"$PROJ_DIR/exporters/node_exporter" --web.listen-address="$IP:$NEXP_PORT" & | |
sleep 3 | |
#2. Prometheus | |
"$PROM_DIR/prometheus" --config.file="$PROM_DIR/prometheus.yml" & | |
sleep 3 | |
#3. Grafana | |
#vi "$GRAF_DIR/conf/defaults.ini" | |
cd "$GRAF_DIR" | |
./bin/grafana-server web | |
EOF | |
chmod a+rx start_all.sh | |
echo -e " | |
===================================================== | |
Installation is completed | |
===================================================== | |
- Prometheus (default): http://localhost:9090/metrics | |
Node metrics: http://$IP:$PORT | |
Node exp metrics: http://$IP:$NEXP_PORT | |
- Grafana (default): http://localhost:3000 | |
You need to do the following to configure grafana: | |
0. Start the required services in a new terminal by \"$(pwd)/$PROJ_NAME/start_all.sh\" | |
- check the prometheus and its exporters by opening URLs above after start. | |
1. Login to grafana as admin/admin (http://localhost:3000) | |
2. Add \"prometheus\" (all lowercase) datasource (http://localhost:9090) | |
3. Create a new dashboard by importing \"$UMED_DB\" (left plus sign). | |
Enjoy... | |
" >&2 | |
clean_up 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment