Created
November 28, 2023 08:11
-
-
Save rbudiharso/4292c3923a1ae70e0f5f4eedc0e79eea to your computer and use it in GitHub Desktop.
Setup node_exporter and promtail
This file contains hidden or 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 | |
echo "********PROMTAIL SETUP************" | |
promtail_file_config="/etc/promtail/promtail.yml" | |
mkdir -p /etc/promtail | |
promtail_version_manual="v1.6.1" | |
LOKI_URL="http://utilities.usetada.dev:3100/loki/api/v1/push" | |
cat > /etc/systemd/system/promtail.service <<END | |
[Unit] | |
Description=Promtail service | |
After=network.target | |
[Service] | |
Type=simple | |
User=root | |
ExecStart=/usr/local/bin/promtail -config.file /etc/promtail/promtail.yml | |
[Install] | |
WantedBy=multi-user.target | |
END | |
cat > /etc/promtail/promtail.yml <<END | |
server: | |
disable: true | |
positions: | |
filename: /tmp/positions.yaml | |
clients: | |
- url: ${LOKI_URL} | |
batchsize: 76800 | |
scrape_configs: | |
END | |
read -p "number of job : " numjob | |
for ((x=1; x<= $numjob; x++)) | |
do | |
echo " === job $x ===" | |
read -p " number of target : " numtarget | |
read -p " job_name : " job_name | |
echo " - job_name: "$job_name >> $promtail_file_config | |
echo " static_configs: " >> $promtail_file_config | |
for ((i=1; i<= $numtarget; i++)) | |
do | |
echo " --target $i--" | |
read -p " (label) job : " job | |
read -p " (label) app : " app | |
read -p " (label) container_name : " container_name | |
read -p " (label) instance : " instance | |
read -p " (label) environment : " environment | |
read -p " (label) __path__ : " path | |
echo " - targets: " >> $promtail_file_config | |
echo " - localhost " >> $promtail_file_config | |
echo " labels: " >> $promtail_file_config | |
echo " job: "$job >> $promtail_file_config | |
echo " app: "$app >> $promtail_file_config | |
echo " container_name: "$container_name >> $promtail_file_config | |
echo " instance: "$instance >> $promtail_file_config | |
echo " environment: "$environment >> $promtail_file_config | |
echo " __path__: "$path >> $promtail_file_config | |
done | |
done | |
chmod -x /etc/promtail/promtail.yml | |
systemctl daemon-reload | |
systemctl enable promtail.service | |
promtail_version=$(/opt/elasticbeanstalk/bin/get-config environment -k PROMTAIL_VERSION) | |
if [[ $promtail_version != "" ]]; then | |
cd /tmp | |
echo "============= stop promtail ==================" | |
systemctl stop promtail | |
echo "============= remove old promtail archive ====" | |
rm -f promtail-linux-amd64.zip | |
echo "============= download promtail" "============" | |
curl -L -O https://github.com/grafana/loki/releases/download/${promtail_version}/promtail-linux-amd64.zip | |
echo "============= unzip ==========================" | |
unzip -o promtail-linux-amd64.zip | |
echo "============= cp promtail ====================" | |
mv -f promtail-linux-amd64 /usr/local/bin/promtail | |
echo "============= restart promtail ===============" | |
systemctl restart promtail | |
echo "============= done ===========================" | |
else | |
cd /tmp | |
echo "============= stop promtail ==================" | |
systemctl stop promtail | |
echo "============= remove old promtail archive ====" | |
rm -f promtail-linux-amd64.zip | |
echo "============= download promtail" "============" | |
curl -L -O https://github.com/grafana/loki/releases/download/${promtail_version_manual}/promtail-linux-amd64.zip | |
echo "============= unzip ==========================" | |
unzip -o promtail-linux-amd64.zip | |
echo "============= cp promtail ====================" | |
mv -f promtail-linux-amd64 /usr/local/bin/promtail | |
echo "============= restart promtail ===============" | |
systemctl restart promtail | |
echo "============= done ===========================" | |
fi | |
echo "********FINISH PROMTAIL SETUP************" | |
echo "********NODEEXPORTER SETUP************" | |
cat > /etc/systemd/system/node_exporter.service <<END | |
[Unit] | |
Description=node_exporter service | |
After=network.target | |
[Service] | |
ExecStart=/usr/local/bin/node_exporter | |
Type=simple | |
PIDFile=/var/run/node_exporter.pid | |
Restart=on-failure | |
[Install] | |
WantedBy=default.target | |
END | |
chmod 644 /etc/systemd/system/node_exporter.service | |
cd /tmp | |
curl -Ls -o ./node_exporter.tar.gz https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz | |
tar xvzpf node_exporter.tar.gz --strip-components=1 | |
chmod 755 ./node_exporter | |
mv ./node_exporter /usr/local/bin/node_exporter | |
systemctl daemon-reload | |
systemctl enable node_exporter.service | |
systemctl start node_exporter.service | |
echo "********FINISH NODEEXPORTER SETUP************" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment