-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_node_exporter_with_blockchain_metrics_node.sh
54 lines (47 loc) · 1.97 KB
/
setup_node_exporter_with_blockchain_metrics_node.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Use this for archival, full, prune node.
# Requires one chain specific command as argument.
# Downloads node_exporter from prometheus.
# Downloads node_status_prom_script.py that serves a .prom file for the node_exporter.
# Sets up a cronjob to refresh the .prom file every minute.
# Starts the node_exporter in a tmux session
set -e
if [ $# -lt 1 ]; then
echo "Requires one argument. Argument is the chain specific command."
exit 1
elif [ $# -gt 1 ]; then
echo "Please specify only one argument."
exit 1
fi
node_exporter_directory=node_exporter-1.5.0.linux-amd64
prom_script_file=node_status_prom_script.py
echo "Changing to home directory..."
cd
echo "Downloading $node_exporter_directory"
if [ -d "$node_exporter_directory" ]; then
rm -rf $node_exporter_directory
fi
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz -P ~
echo "Extracting file..."
tar -xzf node_exporter-1.5.0.linux-amd64.tar.gz
rm -f node_exporter-1.5.0.linux-amd64.tar.gz
echo "$node_exporter_directory downloaded."
echo "Downloading node_status_prom_script.py"
if [ -f "$prom_script_file" ]; then
rm -f $prom_script_file
fi
wget https://raw.githubusercontent.com/coinhall/os-scripts/main/node_status_prom_script.py -P ~
echo "$prom_script_file downloaded."
echo "Setting up cronjob..."
(crontab -l || true; echo "*/1 * * * * python3 ~/node_status_prom_script.py $1 > ./node_exporter_cron.log 2>&1") | awk '!seen[$0]++' | crontab -
echo "cronjob set up done."
echo "Starting node_exporter in tmux session called node-exporter..."
session_name=node-exporter
session_exist=$(tmux ls | grep $session_name) || session_exist=""
if [ ! "$session_exist" = "" ]; then
tmux kill-session -t $session_name
fi
tmux new-session -d -s $session_name
tmux send-keys -t $session_name 'cd node_exporter-1.5.0.linux-amd64' C-m
tmux send-keys -t $session_name './node_exporter --collector.textfile.directory="$HOME"' C-m
echo "node_exporter started"