Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created January 14, 2021 13:40
Show Gist options
  • Save ruanbekker/df4221d6d0bde9548dd685abd404dc0b to your computer and use it in GitHub Desktop.
Save ruanbekker/df4221d6d0bde9548dd685abd404dc0b to your computer and use it in GitHub Desktop.
Setup Grafana Cloud Agent for Linux

Download:

curl -O -L "https://github.com/grafana/agent/releases/latest/download/agent-linux-amd64.zip";
unzip "agent-linux-amd64.zip";
chmod a+x "agent-linux-amd64";

Move to place:

sudo mv agent-linux-amd64 /usr/local/bin/grafana-cloud-agent
sudo mkdir /etc/grafana-cloud

Create config:

cat <<EOF > /etc/grafana-cloud/agent-config.yaml
server:
  http_listen_port: 12345
prometheus:
  wal_directory: /tmp/grafana-agent-wal
  global:
    scrape_interval: 15s
  configs: null
integrations:
  node_exporter:
    enabled: true
  prometheus_remote_write:
    - url: https://prometheus-us-central1.grafana.net/api/prom/push
      basic_auth:
        username: \"${GRAFANA_USER}\"
        password: "$GRAFANA_API_KEY"
EOF

Create Systemd Unit File:

cat >> /etc/systemd/system/grafana_agent.service << EOF
[Unit]
Description=Grafana Agent
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/grafana-cloud-agent --config.file=/etc/grafana-cloud/agent-config.yaml
[Install]
WantedBy=multi-user.target
EOF

Enable and Restart:

sudo systemctl daemon-reload
sudo systemctl enable grafana_agent
sudo systemctl restart grafana_agent

Checks:

sudo journalctl -u grafana_agent -f
-- Logs begin at Thu 2020-12-03 14:21:24 SAST. --
Jan 14 15:36:25 Home-PC grafana-cloud-agent[372522]: level=info ts=2021-01-14T13:36:25.963452652Z caller=checkpoint.go:96 agent=prometheus instance=x msg="Creating checkpoint" from_segment=30 to_segment=32 mint=x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment