Last active
July 6, 2022 22:27
-
-
Save davaymne/b5fd973c3f4c935e2fac826f281bf32f to your computer and use it in GitHub Desktop.
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 | |
function checkPorts { | |
echo -e '\n\e[42mCheck Ports\e[0m\n' | |
if ss -tulpen | awk '{print $5}' | grep -q ":3000$" ; then | |
echo -e "\e[31mInstallation is not possible, port 3000 already in use.\e[39m" | |
exit | |
else | |
echo "Port 3000 is OK" | |
fi | |
if ss -tulpen | awk '{print $5}' | grep -q ":9100$" ; then | |
echo -e "\e[31mInstallation is not possible, port 9090 already in use.\e[39m" | |
exit | |
else | |
echo "Port 9100 is OK" | |
fi | |
if ss -tulpen | awk '{print $5}' | grep -q ":9090$" ; then | |
echo -e "\e[31mInstallation is not possible, port 9090 already in use.\e[39m" | |
exit | |
else | |
echo "9090" | |
fi | |
} | |
function installNodeExporter { | |
echo -e '\n\e[42mInstalling Node Exporter\e[0m\n' | |
mkdir -p /opt/node_exporter | |
cd /opt/node_exporter | |
version=`wget -qO- -t1 -T2 "https://api.github.com/repos/prometheus/node_exporter/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'` | |
wget https://github.com/prometheus/node_exporter/releases/download/${version}/node_exporter-${version:1}.linux-amd64.tar.gz | |
tar xvfz node_exporter-*.*-amd64.tar.gz && cp node_exporter-*.*-amd64/node_exporter . && chown $USER:$USER node_exporter | |
echo "[Unit] | |
Description=Node Exporter | |
After=network.target | |
StartLimitIntervalSec=0 | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=1 | |
User=$USER | |
ExecStart=/opt/node_exporter/node_exporter | |
[Install] | |
WantedBy=multi-user.target" > /etc/systemd/system/node_exporter.service | |
sudo systemctl enable --now node_exporter | |
sleep 2 | |
curl http://localhost:9100/metrics | |
} | |
function installPrometheus { | |
echo -e '\n\e[42mInstalling Prometheus\e[0m\n' | |
mkdir -p /opt/prometheus | |
cd /opt/prometheus | |
echo -e " | |
scrape_configs: | |
- job_name: 'prometheus' | |
static_configs: | |
- targets: ['localhost:9090'] | |
- job_name: 'hyper-node-server' | |
scrape_interval: 5s | |
static_configs: | |
- targets: ['localhost:9100'] | |
- job_name: 'hyper-node' | |
scrape_interval: 5s | |
static_configs: | |
- targets: ['localhost:8899'] | |
- job_name: 'klaytn' | |
scrape_interval: 5s | |
static_configs: | |
- targets: ['localhost:31275']" > prometheus.yml | |
version=`wget -qO- -t1 -T2 "https://api.github.com/repos/prometheus/prometheus/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'` | |
wget https://github.com/prometheus/prometheus/releases/download/${version}/prometheus-${version:1}.linux-amd64.tar.gz | |
tar xvfz prometheus-*.*-amd64.tar.gz && cp prometheus-*.*-amd64/prometheus . && chown $USER:$USER prometheus | |
echo "[Unit] | |
Description=Prometheus | |
After=network.target | |
StartLimitIntervalSec=0 | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=1 | |
User=$USER | |
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml | |
[Install] | |
WantedBy=multi-user.target" > /etc/systemd/system/prometheus.service | |
sudo systemctl enable --now prometheus | |
sleep 2 | |
} | |
function installGrafana { | |
sudo apt-get install -y gnupg2 curl software-properties-common | |
curl https://packages.grafana.com/gpg.key | sudo apt-key add - | |
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" | |
sudo apt-get update | |
sudo apt-get -y install grafana | |
#mkdir -p /etc/grafana/provisioning/datasources/ | |
echo " | |
apiVersion: 1 | |
datasources: | |
- access: proxy | |
editable: true | |
name: prometheus | |
orgId: 1 | |
type: prometheus | |
url: http://localhost:9090/ | |
version: 1" > /etc/grafana/provisioning/datasources/prometheus.yml | |
#mkdir -p /etc/grafana/provisioning/dashboards/ | |
cd /etc/grafana/provisioning/dashboards/ | |
wget https://github.com/davaymne/blockpi-testnet-monitoring/blob/main/grafana/provisioning/dashboards/dashboard.json | |
sudo systemctl enable --now grafana-server | |
} | |
# Main | |
bash_profile=$HOME/.bash_profile | |
if [ -f "$bash_profile" ]; then | |
. $HOME/.bash_profile | |
fi | |
sleep 1 && wget -q -O davaymne_logo.sh https://gist.githubusercontent.com/davaymne/1361bc2ea24a9f5b8ab7585691e388e5/raw/14cce7b8c0f34302f856c0c7eda22651c37de64c/davaymne_logo.sh && chmod 777 davaymne_logo.sh && sudo /bin/bash davaymne_logo.sh && sleep 1 | |
apt update && apt upgrade -y | |
apt install htop git httpie jq tmux bc net-tools smartmontools -y | |
checkPorts | |
installNodeExporter | |
installPrometheus | |
installGrafana | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment