Skip to content

Instantly share code, notes, and snippets.

@bumbummen99
Last active August 26, 2022 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumbummen99/323ec27e0ffc6444fb2a36450fd0cc89 to your computer and use it in GitHub Desktop.
Save bumbummen99/323ec27e0ffc6444fb2a36450fd0cc89 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Download Node Exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz
tar xvfz node_exporter-*.*-amd64.tar.gz
cd node_exporter-*.*-amd64
# Install node_exporter to /usr/local/bin as grafana-agent
cp node_exporter /usr/local/bin/grafana-agent
# Reset working directory
cd ..
# Remove downloaded files
rm node_exporter-*.*-amd64.tar.gz
rm -R node_exporter-*.*-amd64
# Add grafana-agent user and service
sudo useradd --no-create-home --shell /bin/false grafana-agent
cat <<EOF > /etc/systemd/system/grafana-agent.service
[Unit]
Description=Grafana Agent
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target
[Service]
User=grafana-agent
ExecStart=/usr/local/bin/grafana-agent
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
# Allow access to grafana-agent from provided host
ufw allow from $1 to any proto tcp port 9100
# Start the grafana-agent service
service grafana-agent start
echo "Successfully installed, configured & started grafana-agent to be accessed by $1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment