diff --git a/install.sh b/install.sh index 99fef5a..ce97a67 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,14 @@ #! /bin/bash -# sudo apt update + +# @todo check for root +# @todo check distrib / version +# @todo ask IP address + + +## HOMEASSISTANT INSTALL + +sudo apt update sudo apt install git vim python3 python3-pip chromium-browser sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata sudo useradd -rm homeassistant @@ -31,47 +39,146 @@ RestartForceExitStatus=100 WantedBy=multi-user.target EOF + +cat < /etc/systemd/system/grafana-server.service.d/override.conf -[Service] -# Give the CAP_NET_BIND_SERVICE capability -CapabilityBoundingSet=CAP_NET_BIND_SERVICE -AmbientCapabilities=CAP_NET_BIND_SERVICE -# A private user cannot have process capabilities on the host's user -# namespace and thus CAP_NET_BIND_SERVICE has no effect. -PrivateUsers=false +# This is probably useless: we don't need to start on a port lower than 3000 +#cat < /etc/systemd/system/grafana-server.service.d/override.conf +#[Service] +## Give the CAP_NET_BIND_SERVICE capability +#CapabilityBoundingSet=CAP_NET_BIND_SERVICE +#AmbientCapabilities=CAP_NET_BIND_SERVICE +# +## A private user cannot have process capabilities on the host's user +## namespace and thus CAP_NET_BIND_SERVICE has no effect. +#PrivateUsers=false +#EOF + +## PROMETHEUS INSTALL + +curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi - +tar xvf prometheus*.tar.gz +cd prometheus*/ +sudo mv prometheus promtool /usr/local/bin/ + +cat << EOF | sudo tee /etc/systemd/system/prometheus.service +[Unit] +Description=Prometheus +Documentation=https://prometheus.io/docs/introduction/overview/ +Wants=network-online.target +After=network-online.target + +[Service] +Type=simple +User=prometheus +Group=prometheus +ExecReload=/bin/kill -HUP $MAINPID +ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries --web.listen-address=0.0.0.0:9090 --web.external-url= + +SyslogIdentifier=prometheus +Restart=always + +[Install] +WantedBy=multi-user.target EOF + sudo systemctl daemon-reload sudo systemctl enable home-assistant@homeassistant.service sudo systemctl start home-assistant@homeassistant.service sudo systemctl status home-assistant@homeassistant.service +sudo systemctl enable prometheus +sudo systemctl start prometheus +sudo systemctl status prometheus sudo systemctl enable grafana-server sudo systemctl start grafana-server sudo systemctl status grafana-server + echo " # create user in home ass # go to user profile in home ass # get long lived access token like eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlM2ZkY2VmZjYyODQ0OWQ5OGY2OTRlNmU2YjUxYzUyYSIsImlhdCI6MTY1MTg0ODU0NiwiZXhwIjoxOTY3MjA4NTQ2fQ.R6_My5eBUMcgompY3L3SbTUCTEIffQaNMUHyUw8sro0 " +cat << EOF | sudo tee /etc/prometheus/prometheus.yml +# File: /etc/prometheus/prometheus.yml +global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). + # Attach these labels to any time series or alerts when communicating with + # external systems (federation, remote storage, Alertmanager). + external_labels: + monitor: 'example' +# Alertmanager configuration +alerting: + alertmanagers: + - static_configs: + - targets: ['localhost:9093'] +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + - job_name: "hass" + scrape_interval: 60s + metrics_path: /api/prometheus + authorization: + credentials: "$TOKEN" + scheme: http + static_configs: + - targets: ['localhost:8123'] +EOF + read -p "Please provide your access token: " TOKEN cat << EOF | sudo tee /etc/grafana/grafana.ini metrics: - wal_directory: /var/tmp/wal + wal_directory: /tmp/wal configs: - name: integrations scrape_configs: - - job_name: integrations/hass - metrics_path: /api/prometheus - bearer_token: "$TOKEN" + - job_name: prometheus + metrics_path: /metrics scheme: http static_configs: - - targets: ['localhost:8123'] + - targets: ['localhost:9090'] remote_write: - url: http://cortex:9009/api/prom/push EOF