#cloud-config package_update: true package_upgrade: true packages: - wget - tar users: - name: prometheus system: true shell: /bin/false home: /var/lib/prometheus write_files: - path: /etc/systemd/system/prometheus.service content: | [Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple 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.enable-lifecycle [Install] WantedBy=multi-user.target - path: /etc/prometheus/prometheus.yml content: | global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node' static_configs: - targets: ['localhost:9100'] runcmd: # Download and install Prometheus - cd /tmp - wget https://github.com/prometheus/prometheus/releases/download/v2.40.0/prometheus-2.40.0.linux-amd64.tar.gz - tar -xzf prometheus-2.40.0.linux-amd64.tar.gz - cp prometheus-2.40.0.linux-amd64/prometheus /usr/local/bin/ - cp prometheus-2.40.0.linux-amd64/promtool /usr/local/bin/ - mkdir -p /etc/prometheus /var/lib/prometheus - chown prometheus:prometheus /etc/prometheus /var/lib/prometheus # Download and install Node Exporter - wget https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz - tar -xzf node_exporter-1.4.0.linux-amd64.tar.gz - cp node_exporter-1.4.0.linux-amd64/node_exporter /usr/local/bin/ # Start services - systemctl enable prometheus - systemctl start prometheus - systemctl enable node_exporter - systemctl start node_exporter # Configure firewall - ufw allow 9090/tcp - ufw allow 9100/tcp