prometheus-install.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
  7. color
  8. verb_ip6
  9. catch_errors
  10. setting_up_container
  11. network_check
  12. update_os
  13. msg_info "Installing Dependencies"
  14. $STD apt-get install -y curl
  15. $STD apt-get install -y sudo
  16. $STD apt-get install -y mc
  17. msg_ok "Installed Dependencies"
  18. msg_info "Installing Prometheus"
  19. RELEASE=$(curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
  20. mkdir -p /etc/prometheus
  21. mkdir -p /var/lib/prometheus
  22. $STD wget https://github.com/prometheus/prometheus/releases/download/v${RELEASE}/prometheus-${RELEASE}.linux-amd64.tar.gz
  23. $STD tar -xvf prometheus-${RELEASE}.linux-amd64.tar.gz
  24. cd prometheus-${RELEASE}.linux-amd64
  25. mv prometheus promtool /usr/local/bin/
  26. mv consoles/ console_libraries/ /etc/prometheus/
  27. mv prometheus.yml /etc/prometheus/prometheus.yml
  28. msg_ok "Installed Prometheus"
  29. msg_info "Creating Service"
  30. service_path="/etc/systemd/system/prometheus.service"
  31. echo "[Unit]
  32. Description=Prometheus
  33. Wants=network-online.target
  34. After=network-online.target
  35. [Service]
  36. User=root
  37. Restart=always
  38. Type=simple
  39. ExecStart=/usr/local/bin/prometheus \
  40. --config.file=/etc/prometheus/prometheus.yml \
  41. --storage.tsdb.path=/var/lib/prometheus/ \
  42. --web.console.templates=/etc/prometheus/consoles \
  43. --web.console.libraries=/etc/prometheus/console_libraries \
  44. --web.listen-address=0.0.0.0:9090
  45. [Install]
  46. WantedBy=multi-user.target" >$service_path
  47. $STD sudo systemctl enable --now prometheus
  48. msg_ok "Created Service"
  49. motd_ssh
  50. customize
  51. msg_info "Cleaning up"
  52. $STD apt-get autoremove
  53. $STD apt-get autoclean
  54. rm -rf ../prometheus-${RELEASE}.linux-amd64 ../prometheus-${RELEASE}.linux-amd64.tar.gz
  55. msg_ok "Cleaned"