Skip to content

Instantly share code, notes, and snippets.

@NotYusta
Last active May 18, 2025 12:55
Show Gist options
  • Save NotYusta/412c55b1d712bd717ccc310c7c48328b to your computer and use it in GitHub Desktop.
Save NotYusta/412c55b1d712bd717ccc310c7c48328b to your computer and use it in GitHub Desktop.
Install CAdvisor
#!/bin/sh
PORT=9101
BIN_DIR="/usr/local/bin"
SERVICE_NAME="cadvisor"
BINARY_NAME="cadvisor"
VERSION="0.52.1"
DOWNLOAD_URL="https://github.com/google/cadvisor/releases/download/v${VERSION}/cadvisor-v${VERSION}-linux-amd64"
# Function to download and place cadvisor binary
install_cadvisor() {
curl -sLo "${BIN_DIR}/${BINARY_NAME}" "$DOWNLOAD_URL"
chmod +x "${BIN_DIR}/${BINARY_NAME}"
}
# Function to create systemd service for cadvisor
create_systemd_service() {
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
[Unit]
Description=Google cAdvisor
After=network.target
[Service]
ExecStart=${BIN_DIR}/${BINARY_NAME} --port=${PORT}
Restart=always
[Install]
WantedBy=multi-user.target
EOF
}
# Function to enable and start the service
start_service() {
systemctl daemon-reload
systemctl enable ${SERVICE_NAME} --now
}
# Main function
main() {
install_cadvisor
create_systemd_service
start_service
}
# Execute
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment